Last active
August 2, 2019 18:30
-
-
Save coinscious-io/77395e40dfa44dfee86393a3c3f4c06c to your computer and use it in GitHub Desktop.
Subscribing to live stream trade history data
This file contains 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
import okhttp3.Dispatcher; | |
import okhttp3.OkHttpClient; | |
import okhttp3.Request; | |
import okhttp3.Response; | |
import okhttp3.WebSocket; | |
import okhttp3.WebSocketListener; | |
import java.util.concurrent.TimeUnit; | |
public class Example { | |
public static void main(String[] args) { | |
Dispatcher dispatcher = new Dispatcher(); | |
OkHttpClient httpClient = new OkHttpClient.Builder() | |
.pingInterval(60, TimeUnit.SECONDS) | |
.dispatcher(dispatcher) | |
.build(); | |
Request request = new Request.Builder() | |
.url("wss://livestream.coinscious.org/live") | |
.addHeader("Authorization", "Bearer <token>") | |
.build(); | |
WebSocket webSocket = httpClient.newWebSocket(request, new WebSocketListener() { | |
@Override | |
public void onMessage(WebSocket webSocket, String text) { | |
// TODO your code here | |
} | |
@Override | |
public void onFailure(WebSocket webSocket, Throwable t, Response response) { | |
// TODO your code here | |
} | |
@Override | |
public void onClosing(WebSocket webSocket, int code, String reason) { | |
// TODO your code here | |
} | |
}); | |
webSocket.send("{\"subscribe\":\"trade\",\"msg\":{\"exchange\":\"binance\",\"pair\":\"btc_usdt\"}}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment