com.binance.connector.client.impl.spot.UserData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of binance-connector-java Show documentation
Show all versions of binance-connector-java Show documentation
lightweight connector to API
package com.binance.connector.client.impl.spot;
import java.util.LinkedHashMap;
import com.binance.connector.client.enums.HttpMethod;
import com.binance.connector.client.utils.ParameterChecker;
import com.binance.connector.client.utils.ProxyAuth;
import com.binance.connector.client.utils.RequestHandler;
/**
* User Data Streams Endpoints
* All endpoints under the
* User Data Streams
* section of the API documentation will be implemented in this class.
*
* Response will be returned in String format.
*/
public class UserData {
private final String baseUrl;
private final RequestHandler requestHandler;
private final boolean showLimitUsage;
public UserData(String baseUrl, String apiKey, boolean showLimitUsage, ProxyAuth proxy) {
this.baseUrl = baseUrl;
this.requestHandler = new RequestHandler(apiKey, proxy);
this.showLimitUsage = showLimitUsage;
}
private final String SPOT_LISTEN_KEY = "/api/v3/userDataStream";
/**
* Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent.
* If the account has an active listenKey, that listenKey will be returned and its validity will be extended for 60 minutes.
*
* POST /api/v3/userDataStream
*
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
*/
public String createListenKey() {
return requestHandler.sendWithApiKeyRequest(baseUrl, SPOT_LISTEN_KEY, null, HttpMethod.POST, showLimitUsage);
}
/**
* Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes.
* It's recommended to send a ping about every 30 minutes.
*
* PUT /api/v3/userDataStream
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* listenKey -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
*/
public String extendListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "listenKey", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, SPOT_LISTEN_KEY, parameters, HttpMethod.PUT, showLimitUsage);
}
/**
* Close out a user data stream.
*
* DELETE /api/v3/userDataStream
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* listenKey -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
*/
public String closeListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "listenKey", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, SPOT_LISTEN_KEY, parameters, HttpMethod.DELETE, showLimitUsage);
}
private final String MARGIN_LISTEN_KEY = "/sapi/v1/userDataStream";
/**
* POST /sapi/v1/userDataStream
*
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin
*/
public String createMarginListenKey() {
return requestHandler.sendWithApiKeyRequest(baseUrl, MARGIN_LISTEN_KEY, null, HttpMethod.POST, showLimitUsage);
}
/**
* PUT /sapi/v1/userDataStream
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* listenKey -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin
*/
public String extendMarginListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "listenKey", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, MARGIN_LISTEN_KEY, parameters, HttpMethod.PUT, showLimitUsage);
}
/**
* DELETE /sapi/v1/userDataStream
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* listenKey -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin
*/
public String closeMarginListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "listenKey", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, MARGIN_LISTEN_KEY, parameters, HttpMethod.DELETE, showLimitUsage);
}
private final String ISOLATED_LISTEN_KEY = "/sapi/v1/userDataStream/isolated";
/**
* POST /sapi/v1/userDataStream/isolated
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* symbol -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin
*/
public String createIsolatedMarginListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, ISOLATED_LISTEN_KEY, parameters, HttpMethod.POST, showLimitUsage);
}
/**
* PUT /sapi/v1/userDataStream/isolated
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* symbol -- mandatory/string
* listenKey -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin
*/
public String extendIsolatedMarginListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
ParameterChecker.checkParameter(parameters, "listenKey", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, ISOLATED_LISTEN_KEY, parameters, HttpMethod.PUT, showLimitUsage);
}
/**
* DELETE /sapi/v1/userDataStream/isolated
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* symbol -- mandatory/string
* listenKey -- mandatory/string
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin
*/
public String closeIsolatedMarginListenKey(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
ParameterChecker.checkParameter(parameters, "listenKey", String.class);
return requestHandler.sendWithApiKeyRequest(baseUrl, ISOLATED_LISTEN_KEY, parameters, HttpMethod.DELETE, showLimitUsage);
}
}