All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.binance.connector.client.impl.spot.Trade Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.binance.connector.client.impl.spot;

import java.util.Map;

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;
import com.binance.connector.client.utils.signaturegenerator.HmacSignatureGenerator;
import com.binance.connector.client.utils.signaturegenerator.SignatureGenerator;

/**
 * 

Trade Endpoints

* 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, ProxyAuth proxy) { this.baseUrl = baseUrl; this.requestHandler = new RequestHandler(apiKey, new HmacSignatureGenerator(secretKey), proxy); this.showLimitUsage = showLimitUsage; } public Trade(String baseUrl, String apiKey, SignatureGenerator signatureGenerator, boolean showLimitUsage, ProxyAuth proxy) { this.baseUrl = baseUrl; this.requestHandler = new RequestHandler(apiKey, signatureGenerator, proxy); 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 Map of String,Object pair * where String is the name of the parameter and Object is the value of the parameter *

* In addition to all parameters accepted by POST /api/v3/order, the following optional parameters are also accepted:
* computeCommissionRates -- optional/boolean -- Default: false
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#test-new-order-trade */ public String testNewOrder(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); ParameterChecker.checkParameter(parameters, "side", String.class); ParameterChecker.checkParameter(parameters, "type", String.class); return requestHandler.sendSignedRequest(baseUrl, TEST_NEW_ORDER, parameters, HttpMethod.POST, showLimitUsage); } private final String ORDER = "/api/v3/order"; /** * Send in a new order. *

* POST /api/v3/order *
* @param * parameters Map 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
* timeInForce -- optional/enum
* quantity -- optional/decimal
* quoteOrderQty -- optional/decimal
* price -- optional/decimal
* newClientOrderId -- optional/string -- A unique id among open orders. Automatically generated if not sent.
* strategyId -- optional/int
* strategyType -- optional/int -- The value cannot be less than 1000000.
* stopPrice -- optional/decimal -- Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
* trailingDelta -- optional/long -- Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
* icebergQty -- optional/decimal -- Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
* newOrderRespType -- optional/enum -- Set the response JSON. ACK, RESULT, or FULL; MARKET and LIMIT order types default to FULL, all other orders default to ACK.
* selfTradePrevention -- optional/enum -- The allowed enums is dependent on what is configured on the symbol. The possible supported values are EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE.
s * recvWindow -- optional/long
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#new-order-trade */ public String newOrder(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); ParameterChecker.checkParameter(parameters, "side", String.class); ParameterChecker.checkParameter(parameters, "type", String.class); return requestHandler.sendSignedRequest(baseUrl, ORDER, parameters, HttpMethod.POST, showLimitUsage); } /** * Cancel an active order. *

* DELETE /api/v3/order *
* @param * parameters Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-order-trade */ public String cancelOrder(Map 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 Map of String,Object pair * where String is the name of the parameter and Object is the value of the parameter *

* symbol -- mandatory/string
* recvWindow -- optional/long
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-order-trade */ public String cancelOpenOrders(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); return requestHandler.sendSignedRequest(baseUrl, ALL_OPEN_ORDERS, parameters, HttpMethod.DELETE, showLimitUsage); } /** * Check an order's status. *

* GET /api/v3/order *
* @param * parameters Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-order-user_data */ public String getOrder(Map 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 Map 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.
* stopStrategyId -- optional/int
* stopStrategyType -- optional/int -- The value cannot be less than 1000000.
* stopPrice -- optional/decimal
* icebergQty -- optional/decimal
* trailingDelta -- optional/long
* newOrderRespType -- optional/enum -- Allowed values: ACK, RESULT, FULL. MARKET and LIMIT orders types default to FULL; all other orders default to ACK
* selfTradePreventionMode -- optional/enum -- The allowed enums is dependent on what is configured on the symbol. The possible supported values are EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE.
* cancelRestrictions -- optional/enum -- Supported values: ONLY_NEW - Cancel will succeed if the order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED.
* recvWindow -- optional/long
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-an-existing-order-and-send-a-new-order-trade */ public String cancelReplace(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#current-open-orders-user_data */ public String getOpenOrders(Map 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 Map 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
* limit -- optional/int
* recvWindow -- optional/long
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#all-orders-user_data */ public String getOrders(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); return requestHandler.sendSignedRequest(baseUrl, ALL_ORDERS, parameters, HttpMethod.GET, showLimitUsage); } private final String OCO_LIST = "/api/v3/orderList"; /** * Cancel an entire Order List. *

* DELETE /api/v3/orderList *
* @param * parameters Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#cancel-order-list-trade */ public String cancelOCO(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-order-lists-user_data */ public String getOCOOrder(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-all-order-lists-user_data */ public String getOCOOrders(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-open-order-lists-user_data */ public String getOpenOCOOrders(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#account-information-user_data */ public String account(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#account-trade-list-user_data */ public String myTrades(Map 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 Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-current-order-count-usage-trade */ public String rateLimitOrder(Map parameters) { return requestHandler.sendSignedRequest(baseUrl, RATE_LIMIT, parameters, HttpMethod.GET, showLimitUsage); } private final String PREVENTED_MATCHES = "/api/v3/myPreventedMatches"; /** * Displays the list of orders that were expired because of STP. * * These are the combinations supported: * * * symbol + preventedMatchId * * symbol + orderId * * symbol + orderId + fromPreventedMatchId (limit will default to 500) * * symbol + orderId + fromPreventedMatchId + limit * *

* GET /api/v3/myPreventedMatches *
* @param * parameters Map of String,Object pair * where String is the name of the parameter and Object is the value of the parameter *

* symbol -- mandatory/string
* preventedMatchId -- optional/long
* orderId -- optional/long -- Order id
* fromPreventedMatchId -- optional/long
* limit -- optional/int -- Default 500; max 1000.
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-prevented-matches-user_data */ public String preventedMatches(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); return requestHandler.sendSignedRequest(baseUrl, PREVENTED_MATCHES, parameters, HttpMethod.GET, showLimitUsage); } private final String SOR_ALLOCATIONS = "/api/v3/myAllocations"; /** * Retrieves allocations resulting from SOR order placement. * * * Supported parameter combinations: * Parameters Response * symbol allocations from oldest to newest * symbol + startTime oldest allocations since startTime * symbol + endTime newest allocations until endTime * symbol + startTime + endTime allocations within the time range * symbol + fromAllocationId allocations by allocation ID * symbol + orderId allocations related to an order starting with oldest * symbol + orderId + fromAllocationId allocations related to an order by allocation ID * * Note: The time between startTime and endTime can't be longer than 24 hours. *

* GET /api/v3/myAllocations *
* @param * parameters Map of String,Object pair * where String is the name of the parameter and Object is the value of the parameter *

* symbol -- mandatory/string -- Trading symbol, e.g. BNBUSDT
* startTime -- optional/long -- UTC timestamp in ms
* endTime -- optional/long -- UTC timestamp in ms
* fromAllocationId -- optional/int
* limit -- optional/int -- Default 500; max 1000.
* orderId -- optional/long -- Order id
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-allocations-user_data */ public String sorAllocations(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); return requestHandler.sendSignedRequest(baseUrl, SOR_ALLOCATIONS, parameters, HttpMethod.GET, showLimitUsage); } private final String COMMISSION = "/api/v3/account/commission"; /** * Get current account commission rates. *

* GET /api/v3/account/commission *
* @param * parameters Map 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://developers.binance.com/docs/binance-spot-api-docs/rest-api#query-commission-rates-user_data */ public String commission(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); return requestHandler.sendSignedRequest(baseUrl, COMMISSION, parameters, HttpMethod.GET, showLimitUsage); } private final String SOR_ORDER = "/api/v3/sor/order"; /** * Places an order using smart order routing (SOR). * *

* POST /api/v3/sor/order *
* @param * parameters Map of String,Object pair * where String is the name of the parameter and Object is the value of the parameter *

* symbol -- mandatory/string -- Trading symbol, e.g. BNBUSDT
* side -- mandatory/enum
* type -- mandatory/enum -- only supports LIMIT and MARKET orders
* timeInForce -- optional/enum -- Order time in force
* quantity -- mandatory/decimal
* price -- optional/decimal
* newClientOrderId -- optional/string -- Used to uniquely identify this cancel. Automatically generated by default
* strategyId -- optional/int
* strategyType -- optional/int -- The value cannot be less than 1000000.
* icebergQty -- optional/decimal -- Used with LIMIT to create an iceberg order.
* newOrderRespType -- optional/enum -- Set the response JSON. MARKET and LIMIT order types default to FULL, all other orders default to ACK.
* selfTradePreventionMode -- optional/enum -- The allowed enums is dependent on what is configured on the symbol. The possible supported values are EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE.
* recvWindow -- optional/long -- The value cannot be greater than 60000
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/testnet/rest-api#new-order-using-sor-trade */ public String sorOrder(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); ParameterChecker.checkParameter(parameters, "side", String.class); ParameterChecker.checkParameter(parameters, "type", String.class); ParameterChecker.checkRequiredParameter(parameters, "quantity"); return requestHandler.sendSignedRequest(baseUrl, SOR_ORDER, parameters, HttpMethod.POST, showLimitUsage); } private final String TEST_SOR_ORDER = "/api/v3/sor/order/test"; /** * Test new order creation and signature/recvWindow using smart order routing (SOR). * Creates and validates a new order but does not send it into the matching engine. *

* POST /api/v3/sor/order/test *
* @param * parameters Map of String,Object pair * where String is the name of the parameter and Object is the value of the parameter *

* In addition to all parameters accepted by POST /api/v3/sor/order, the following optional parameters are also accepted:
* computeCommissionRates -- optional/boolean -- Default: false
* @return String * @see * https://developers.binance.com/docs/binance-spot-api-docs/testnet/rest-api#test-new-order-using-sor-trade */ public String testSorOrder(Map parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); ParameterChecker.checkParameter(parameters, "side", String.class); ParameterChecker.checkParameter(parameters, "type", String.class); ParameterChecker.checkRequiredParameter(parameters, "quantity"); return requestHandler.sendSignedRequest(baseUrl, TEST_SOR_ORDER, parameters, HttpMethod.POST, showLimitUsage); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy