Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Fix ping interval for websocket clients #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 72 additions & 75 deletions src/main/java/com/binance/api/client/BinanceApiClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
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.
*/
public class BinanceApiWebSocketClientImpl implements BinanceApiWebSocketClient, Closeable {

private final OkHttpClient client;

public BinanceApiWebSocketClientImpl(OkHttpClient client) {
this.client = client;
public BinanceApiWebSocketClientImpl() {
this.client = getSharedClient().newBuilder().pingInterval(3, TimeUnit.MINUTES).build();
}

@Override
Expand Down