Last active
July 9, 2017 13:58
-
-
Save andre77/8fd320c83abbcf21de79c82f6f71cbfc to your computer and use it in GitHub Desktop.
Java test app for Bittrex Websockets using https://github.com/SignalR/java-client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bittrex; | |
import java.util.concurrent.ExecutionException; | |
import microsoft.aspnet.signalr.client.ErrorCallback; | |
import microsoft.aspnet.signalr.client.LogLevel; | |
import microsoft.aspnet.signalr.client.Logger; | |
import microsoft.aspnet.signalr.client.SignalRFuture; | |
import microsoft.aspnet.signalr.client.hubs.HubConnection; | |
import microsoft.aspnet.signalr.client.hubs.HubProxy; | |
import microsoft.aspnet.signalr.client.transport.ServerSentEventsTransport; | |
public class BittrexWebsocket { | |
private static final String DEFAULT_SERVER_URL = "https://www.bittrex.com/signalR/"; | |
public static void main(String[] args) throws InterruptedException, ExecutionException { | |
Logger logger = (message, level) -> { | |
if (level == LogLevel.Critical) { | |
System.out.println(level + " " + message); | |
} | |
}; | |
HubConnection connection = new HubConnection(DEFAULT_SERVER_URL, null, false, logger); | |
connection.error(new ErrorCallback() { | |
@Override | |
public void onError(Throwable error) { | |
System.err.println("There was an error communicating with the server."); | |
error.printStackTrace(); | |
} | |
}); | |
connection.connected(() -> System.out.println("Connecton started")); | |
connection.closed(() -> System.out.println("Connecton closed")); | |
connection.received(json -> { | |
//System.out.println(new Date() + " RECEIVED: " + json); | |
}); | |
final HubProxy proxy = connection.createHubProxy("corehub"); | |
proxy.subscribe(new Object() { | |
@SuppressWarnings("unused") | |
public void updateSummaryState(Object o) { | |
// ignore it for now | |
} | |
@SuppressWarnings("unused") | |
public void updateExchangeState(Object o) { | |
System.out.println("updateExchangeState! " + o.getClass() + ": " + o); | |
} | |
}); | |
SignalRFuture<Void> start = connection.start(new ServerSentEventsTransport(logger)); | |
start.get(); | |
SignalRFuture<Void> updates = proxy.invoke("SubscribeToExchangeDeltas", "USDT-BTC"); // -> "updateExchangeState" events | |
updates.done(v -> System.out.println("Subscribed for USDT-BTC")); | |
updates.onError(err -> { | |
System.err.println("Could not subscribe for exchange deltas USDT-BTC"); | |
err.printStackTrace(); | |
}); | |
SignalRFuture<Object> state = proxy.invoke(Object.class, "QueryExchangeState", "USDT-BTC"); | |
state.done(v -> System.out.println("QueryExchangeState for USDT-BTC: " + v)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment