Skip to content

Commit

Permalink
trace debug
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorFrWu committed Oct 27, 2023
1 parent 009127d commit 711e07a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>

</distributionManagement>

<build>
Expand Down Expand Up @@ -238,6 +239,7 @@
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
5 changes: 2 additions & 3 deletions src/main/java/com/bybit/api/client/config/BybitApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ public class BybitApiConfig {
*/
public static boolean useTestnet;

// V5
public static final String V5_PUBLIC_SPOT = "/v5/public/spot";
public static final String V5_PUBLIC_LINEAR = "/v5/public/linear";
public static final String V5_PUBLIC_INVERSE = "/v5/public/inverse";
public static final String V5_PUBLIC_OPTION = "/v5/public/option";
public static final String V3_PUBLIC_OPTION = "/option/usdc/public/v3";

public static final String v2_PUBLIC_SPOT = "/spot/quote/ws/v2";

public static final String V5_PRIVATE = "/v5/private";

// V3
public static final String V3_CONTRACT_PRIVATE = "/contract/private/v3";
public static final String V3_UNIFIED_PRIVATE = "/unified/private/v3";
public static final String V3_CONTRACT_USDT_PUBLIC = "/contract/usdt/public/v3";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bybit.api.client.websocket;

import com.bybit.api.client.logging.LoggingInterceptor;
import lombok.Getter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand All @@ -11,8 +10,7 @@
@Getter
public final class WebSocketHttpClientSingleton {
private final Logger LOGGER = LoggerFactory.getLogger(WebSocketHttpClientSingleton.class);
private boolean debugMode;
private final OkHttpClient OK_HTTP_CLIENT = createOkHttpClient(debugMode);
private final boolean debugMode;

private WebSocketHttpClientSingleton(boolean debugMode) {
this.debugMode = debugMode;
Expand All @@ -25,13 +23,15 @@ public static WebSocketHttpClientSingleton createInstance(boolean debugMode) {
public OkHttpClient createOkHttpClient(boolean debugMode) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (debugMode) {
builder.addInterceptor(new LoggingInterceptor(LOGGER));
LOGGER.info("Debug Mode Actived, Trace Request Header and Response Header");
builder.addInterceptor(new WebsocketLoggingInterceptor(LOGGER));
}
return builder.build();
}

public void createWebSocket(String url, WebSocketListener listener) {
Request request = new Request.Builder().url(url).build();
OK_HTTP_CLIENT.newWebSocket(request, listener);
OkHttpClient okHttpClient = createOkHttpClient(debugMode);
okHttpClient.newWebSocket(request, listener);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bybit.api.client.logging;
package com.bybit.api.client.websocket;

import okhttp3.Headers;
import okhttp3.Interceptor;
Expand All @@ -9,9 +9,9 @@

import java.io.IOException;

public class LoggingInterceptor implements Interceptor {
public class WebsocketLoggingInterceptor implements Interceptor {
private final Logger LOGGER;
public LoggingInterceptor(Logger logger) {
public WebsocketLoggingInterceptor(Logger logger) {
this.LOGGER = logger;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bybit.api.examples.Websocket;

import com.bybit.api.client.config.BybitApiConfig;
import com.bybit.api.client.service.BybitApiClientFactory;

import java.util.List;

public class WebsocketDebuggerExample {
public static void main(String[] args) {
BybitApiClientFactory factory = BybitApiClientFactory.newInstance();
var client = factory.newWebsocketClient((message) -> System.out.println("Handle message :" + message), true);

// Orderbook
client.getPublicChannelStream(List.of("orderbook.50.MATICUSDT"), BybitApiConfig.V5_PUBLIC_LINEAR);
}
}

0 comments on commit 711e07a

Please sign in to comment.