Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* All endpoints under the
* Spot Account/Trade Endpoint
* section of the API documentation will be implemented in this class.
*
* Response will be returned in String format.
*/
public class Trade {
private final String baseUrl;
private final RequestHandler requestHandler;
private final boolean showLimitUsage;
public Trade(String baseUrl, String apiKey, String secretKey, boolean showLimitUsage) {
this.baseUrl = baseUrl;
this.requestHandler = new RequestHandler(apiKey, new HmacSignatureGenerator(secretKey));
this.showLimitUsage = showLimitUsage;
}
public Trade(String baseUrl, String apiKey, SignatureGenerator signatureGenerator, boolean showLimitUsage) {
this.baseUrl = baseUrl;
this.requestHandler = new RequestHandler(apiKey, signatureGenerator);
this.showLimitUsage = showLimitUsage;
}
private final String TEST_NEW_ORDER = "/api/v3/order/test";
/**
* Test new order creation and signature/recvWindow long.
* Creates and validates a new order but does not send it into the matching engine.
*
* POST /api/v3/order/test
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* POST /api/v3/order
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* DELETE /api/v3/order
*
* @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
* orderId -- optional/long
* origClientOrderId -- optional/string
* newClientOrderId -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#cancel-order-trade
*/
public String cancelOrder(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
return requestHandler.sendSignedRequest(baseUrl, ORDER, parameters, HttpMethod.DELETE, showLimitUsage);
}
private final String ALL_OPEN_ORDERS = "/api/v3/openOrders";
/**
* Cancels all active orders on a symbol.
* This includes OCO orders.
*
* DELETE /api/v3/openOrders
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* GET /api/v3/order
*
* @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
* orderId -- optional/long
* origClientOrderId -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#query-order-user_data
*/
public String getOrder(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
return requestHandler.sendSignedRequest(baseUrl, ORDER, parameters, HttpMethod.GET, showLimitUsage);
}
private final String CANCEL_REPLACE = "/api/v3/order/cancelReplace";
/**
* Cancels an existing order and places a new order on the same symbol.
* Filters are evaluated before the cancel order is placed.
* If the new order placement is successfully sent to the engine, the order count will increase by 1.
*
* POST /api/v3/order/cancelReplace
*
* @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
* side -- mandatory/enum
* type -- mandatory/enum
* cancelReplaceMode -- mandatory/enum -- The allowed values are: STOP_ON_FAILURE - If the cancel request fails, the new order placement will not be attempted. ALLOW_FAILURES - new order placement will be attempted even if cancel request fails.
* timeInForce -- optional/enum
* quantity -- optional/decimal
* quoteOrderQty -- optional/decimal
* price -- optional/decimal
* cancelNewClientOrderId -- optional/string
* cancelOrigClientOrderId -- optional/string -- Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
* cancelOrderId -- optional/long -- Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
* newClientOrderId -- optional/string -- Used to identify the new order.
* stopPrice -- optional/decimal
* icebergQty -- optional/decimal
* trailingDelta -- optional/long
* newOrderRespType -- optional/enum
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#cancel-an-existing-order-and-send-a-new-order-trade
*/
public String cancelReplace(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
ParameterChecker.checkParameter(parameters, "side", String.class);
ParameterChecker.checkParameter(parameters, "type", String.class);
ParameterChecker.checkParameter(parameters, "cancelReplaceMode", String.class);
return requestHandler.sendSignedRequest(baseUrl, CANCEL_REPLACE, parameters, HttpMethod.POST, showLimitUsage);
}
/**
* Get all open orders on a symbol. Careful when accessing this with no symbol.
*
* GET /api/v3/openOrders
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* symbol -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#current-open-orders-user_data
*/
public String getOpenOrders(LinkedHashMap parameters) {
return requestHandler.sendSignedRequest(baseUrl, ALL_OPEN_ORDERS, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ALL_ORDERS = "/api/v3/allOrders";
/**
* Get all account orders; active, canceled, or filled.
*
* GET /api/v3/allOrders
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* POST /api/v3/order/oco
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* DELETE /api/v3/orderList
*
* @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
* orderListId -- optional/string
* listClientOrderId -- optional/string
* newClientOrderId -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#cancel-oco-trade
*/
public String cancelOCO(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
return requestHandler.sendSignedRequest(baseUrl, OCO_LIST, parameters, HttpMethod.DELETE, showLimitUsage);
}
/**
* Retrieves a specific OCO based on provided optional parameters
*
* GET /api/v3/orderList
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* orderListId -- optional/string
* origClientOrderId -- optional/string
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#query-oco-user_data
*/
public String getOCOOrder(LinkedHashMap parameters) {
return requestHandler.sendSignedRequest(baseUrl, OCO_LIST, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ALL_OCO_LIST = "/api/v3/allOrderList";
/**
* Retrieves all OCO based on provided optional parameters
*
* GET /api/v3/allOrderList
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* fromId -- optional/long
* startTime -- optional/long
* endTime -- optional/long
* limit -- optional/int
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#query-oco-user_data
*/
public String getOCOOrders(LinkedHashMap parameters) {
return requestHandler.sendSignedRequest(baseUrl, ALL_OCO_LIST, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ALL_OPEN_OCO_LIST = "/api/v3/openOrderList";
/**
* GET /api/v3/openOrderList
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#query-open-oco-user_data
*/
public String getOpenOCOOrders(LinkedHashMap parameters) {
return requestHandler.sendSignedRequest(baseUrl, ALL_OPEN_OCO_LIST, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ACCOUNT_INFO = "/api/v3/account";
/**
* Get current account information.
*
* GET /api/v3/account
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#account-information-user_data
*/
public String account(LinkedHashMap parameters) {
return requestHandler.sendSignedRequest(baseUrl, ACCOUNT_INFO, parameters, HttpMethod.GET, showLimitUsage);
}
private final String ACCOUNT_TRADES = "/api/v3/myTrades";
/**
* Get trades for a specific account and symbol.
*
* GET /api/v3/myTrades
*
* @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
* orderId -- optional/long
* startTime -- optional/long
* endTime -- optional/long
* fromId -- optional/long
* limit -- optional/int
* recvWindow -- optional/long
* @return String
* @see
* https://binance-docs.github.io/apidocs/spot/en/#account-trade-list-user_data
*/
public String myTrades(LinkedHashMap parameters) {
ParameterChecker.checkParameter(parameters, "symbol", String.class);
return requestHandler.sendSignedRequest(baseUrl, ACCOUNT_TRADES, parameters, HttpMethod.GET, showLimitUsage);
}
private final String RATE_LIMIT = "/api/v3/rateLimit/order";
/**
* Displays the user's current order count usage for all intervals.
*
* GET /api/v3/rateLimit/order
*
* @param
* parameters LinkedHashedMap of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
*