Skip to content

Commit 4a7b359

Browse files
committed
[WeBsocket] - Opening a new one after close old wsocket;
1 parent c0a63eb commit 4a7b359

2 files changed

Lines changed: 4 additions & 24 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.grinply</groupId>
88
<artifactId>bybit-java-api</artifactId>
9-
<version>1.0.7</version>
9+
<version>1.0.8</version>
1010
<name>bybit-java-api</name>
1111
<packaging>jar</packaging>
1212
<url>https://github.com/grinply/bybit-java-api</url>

src/main/java/com/grinply/api/client/websocket/impl/WebsocketStreamClientImpl.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nulla
233233
LOGGER.error("Trying to open a new connection in same wsocket: ", t);
234234
WebsocketStreamClientImpl.this.onClose(webSocket, 0, "Socket Exception caused by server");
235235
}
236-
reconnect();
236+
connect();
237237
}
238238

239239
@Override
@@ -293,7 +293,8 @@ public void onError(WebSocket webSocket, Throwable t) {
293293
@Override
294294
public void onClose(WebSocket ws, int code, String reason) {
295295
LOGGER.info("WebSocket closed. Code: {}, Reason: {}", code, reason);
296-
ws.close(code, reason);
296+
// cancel, since we're having problems using close (it's wait for graceful shutdown)
297+
ws.cancel();
297298
this.webSocket = null;
298299
}
299300

@@ -327,27 +328,6 @@ public WebSocket connect() {
327328
return this.webSocket;
328329
}
329330

330-
private synchronized void reconnect() {
331-
try {
332-
// Reconnect to the same stream
333-
if (requiresAuthentication(path)) {
334-
if (path.equals(BybitApiConfig.V5_TRADE) && params != null) {
335-
getTradeChannelStream(params, path);
336-
} else if (argNames != null) {
337-
getPrivateChannelStream(argNames, path);
338-
}
339-
} else {
340-
if (argNames != null) {
341-
getPublicChannelStream(argNames, path);
342-
} else {
343-
LOGGER.warn("No args provided for public stream. Cannot reconnect.");
344-
}
345-
}
346-
} catch (Exception e) {
347-
LOGGER.error("Reconnect failed", e);
348-
}
349-
}
350-
351331
@Override
352332
public WebSocket getPublicChannelStream(List<String> argNames, String path) {
353333
setupChannelStream(argNames, path);

0 commit comments

Comments
 (0)