Код: Выделить всё
public class MainClass {
public static void main(String[] args) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
try (HttpClient client = HttpClient.newHttpClient()) {
client.newWebSocketBuilder()
.buildAsync(URI.create("wss://socket.coinex.com/v2/futures"), new WebSocketClient(latch))
.join();
latch.wait();
}
}
private record WebSocketClient(CountDownLatch latch) implements WebSocket.Listener {
@Override
public void onOpen(WebSocket webSocket) {
System.out.println("Connected to server");
String message = """
{
"method": "state.subscribe",
"params": {"market_list": ["BTCUSDT"]},
"id": 1
}
""";
webSocket.sendText(message, true);
WebSocket.Listener.super.onOpen(webSocket);
}
@Override
public CompletionStage onText(WebSocket webSocket, CharSequence data, boolean last) {
System.out.println("Receive: " + data.toString());
latch.countDown();
return WebSocket.Listener.super.onText(webSocket, data, last);
}
@Override
public CompletionStage onClose(WebSocket webSocket, int statusCode, String reason) {
System.out.println("Socket Closed: " + statusCode);
latch.countDown();
return WebSocket.Listener.super.onClose(webSocket, statusCode, reason);
}
@Override
public void onError(WebSocket webSocket, Throwable error) {
System.out.println("Error: " + error.getMessage());
latch.countDown();
WebSocket.Listener.super.onError(webSocket, error);
}
}
}
Код: Выделить всё
websocat --uncompress-gzip --binary wss://socket.coinex.com/v2/futures
# After connect enter this message to receive response :
{"method": "state.subscribe","params": {"market_list": ["BTCUSDT"]},"id": 1}
но моя проблема в том, что этот метод не получает никаких данных с сервера!
p>
Документ CoinEx
Подробнее здесь: https://stackoverflow.com/questions/792 ... t-received