From 700d54a544219967e7da698d42f7935410218be1 Mon Sep 17 00:00:00 2001 From: Eugen Podaru Date: Sat, 21 Nov 2020 14:55:02 +0100 Subject: [PATCH] Fix ping interval for websocket clients --- .../api/client/BinanceApiClientFactory.java | 147 +++++++++--------- .../impl/BinanceApiWebSocketClientImpl.java | 7 +- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/binance/api/client/BinanceApiClientFactory.java b/src/main/java/com/binance/api/client/BinanceApiClientFactory.java index 842ad20d5..3470951d5 100755 --- a/src/main/java/com/binance/api/client/BinanceApiClientFactory.java +++ b/src/main/java/com/binance/api/client/BinanceApiClientFactory.java @@ -2,94 +2,91 @@ import com.binance.api.client.impl.*; -import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient; - /** * A factory for creating BinanceApi client objects. */ public class BinanceApiClientFactory { - /** - * API Key - */ - private String apiKey; + /** + * API Key + */ + private String apiKey; - /** - * Secret. - */ - private String secret; + /** + * Secret. + */ + private String secret; - /** - * Instantiates a new binance api client factory. - * - * @param apiKey the API key - * @param secret the Secret - */ - private BinanceApiClientFactory(String apiKey, String secret) { - this.apiKey = apiKey; - this.secret = secret; - } + /** + * Instantiates a new binance api client factory. + * + * @param apiKey the API key + * @param secret the Secret + */ + private BinanceApiClientFactory(String apiKey, String secret) { + this.apiKey = apiKey; + this.secret = secret; + } - /** - * New instance. - * - * @param apiKey the API key - * @param secret the Secret - * - * @return the binance api client factory - */ - public static BinanceApiClientFactory newInstance(String apiKey, String secret) { - return new BinanceApiClientFactory(apiKey, secret); - } + /** + * New instance. + * + * @param apiKey the API key + * @param secret the Secret + * @return the binance api client factory + */ + public static BinanceApiClientFactory newInstance(String apiKey, String secret) { + return new BinanceApiClientFactory(apiKey, secret); + } - /** - * New instance without authentication. - * - * @return the binance api client factory - */ - public static BinanceApiClientFactory newInstance() { - return new BinanceApiClientFactory(null, null); - } + /** + * New instance without authentication. + * + * @return the binance api client factory + */ + public static BinanceApiClientFactory newInstance() { + return new BinanceApiClientFactory(null, null); + } - /** - * Creates a new synchronous/blocking REST client. - */ - public BinanceApiRestClient newRestClient() { - return new BinanceApiRestClientImpl(apiKey, secret); - } + /** + * Creates a new synchronous/blocking REST client. + */ + public BinanceApiRestClient newRestClient() { + return new BinanceApiRestClientImpl(apiKey, secret); + } - /** - * Creates a new asynchronous/non-blocking REST client. - */ - public BinanceApiAsyncRestClient newAsyncRestClient() { - return new BinanceApiAsyncRestClientImpl(apiKey, secret); - } + /** + * Creates a new asynchronous/non-blocking REST client. + */ + public BinanceApiAsyncRestClient newAsyncRestClient() { + return new BinanceApiAsyncRestClientImpl(apiKey, secret); + } - /** - * Creates a new asynchronous/non-blocking Margin REST client. - */ - public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() { - return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret); - } + /** + * Creates a new asynchronous/non-blocking Margin REST client. + */ + public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() { + return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret); + } - /** - * Creates a new synchronous/blocking Margin REST client. - */ - public BinanceApiMarginRestClient newMarginRestClient() { - return new BinanceApiMarginRestClientImpl(apiKey, secret); - } + /** + * Creates a new synchronous/blocking Margin REST client. + */ + public BinanceApiMarginRestClient newMarginRestClient() { + return new BinanceApiMarginRestClientImpl(apiKey, secret); + } - /** - * Creates a new web socket client used for handling data streams. - */ - public BinanceApiWebSocketClient newWebSocketClient() { - return new BinanceApiWebSocketClientImpl(getSharedClient()); - } + /** + * Creates a new web socket client used for handling data streams. + */ + public BinanceApiWebSocketClient newWebSocketClient() { + return new BinanceApiWebSocketClientImpl(); + } - /** - * Creates a new synchronous/blocking Swap REST client. - */ - public BinanceApiSwapRestClient newSwapRestClient() { - return new BinanceApiSwapRestClientImpl(apiKey, secret); - } + /** + * Creates a new synchronous/blocking Swap REST client. + */ + public BinanceApiSwapRestClient newSwapRestClient() { + return new BinanceApiSwapRestClientImpl(apiKey, secret); + } } diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java b/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java index be0dcf518..6b5f485df 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java @@ -13,8 +13,11 @@ import java.io.Closeable; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient; + /** * Binance API WebSocket client implementation using OkHttp. */ @@ -22,8 +25,8 @@ public class BinanceApiWebSocketClientImpl implements BinanceApiWebSocketClient, private final OkHttpClient client; - public BinanceApiWebSocketClientImpl(OkHttpClient client) { - this.client = client; + public BinanceApiWebSocketClientImpl() { + this.client = getSharedClient().newBuilder().pingInterval(3, TimeUnit.MINUTES).build(); } @Override