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

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

package com.binance.connector.client.impl.spot;

import com.binance.connector.client.enums.HttpMethod;
import com.binance.connector.client.utils.HmacSignatureGenerator;
import com.binance.connector.client.utils.ParameterChecker;
import com.binance.connector.client.utils.RequestHandler;
import com.binance.connector.client.utils.SignatureGenerator;
import java.util.LinkedHashMap;

/**
 * 

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) { 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 *

* symbol -- mandatory/string
* side -- mandatory/enum
* type -- mandatory/enum
* timeInForce -- optional/enum
* quantity -- optional/decimal
* quoteOrderQty -- optional/decimal
* price -- optional/decimal
* newClientOrderId -- optional/string
* 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/#test-new-order-trade */ public String testNewOrder(LinkedHashMap 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 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
* timeInForce -- optional/enum
* quantity -- optional/decimal
* quoteOrderQty -- optional/decimal
* price -- optional/decimal
* newClientOrderId -- optional/string
* 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/#new-order-trade */ public String newOrder(LinkedHashMap 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 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 *

* symbol -- mandatory/string
* recvWindow -- optional/long
* @return String * @see * https://binance-docs.github.io/apidocs/spot/en/#cancel-order-trade */ public String cancelOpenOrders(LinkedHashMap 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 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 *

* symbol -- mandatory/string
* orderId -- 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/#all-orders-user_data */ public String getOrders(LinkedHashMap parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); return requestHandler.sendSignedRequest(baseUrl, ALL_ORDERS, parameters, HttpMethod.GET, showLimitUsage); } private final String OCO_ORDER = "/api/v3/order/oco"; /** * Send in a new OCO. *

* 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 *

* symbol -- mandatory/string
* listClientOrderId -- optional/string
* side -- mandatory/enum
* quantity -- mandatory/decimal
* limitClientOrderId -- optional/string
* price -- mandatory/decimal
* limitIcebergQty -- optional/decimal
* trailingDelta -- optional/long
* stopClientOrderId -- optional/string
* stopPrice -- mandatory/decimal
* stopLimitPrice -- optional/decimal
* stopIcebergQty -- optional/decimal
* stopLimitTimeInForce -- optional/enum
* newOrderRespType -- optional/enum
* recvWindow -- optional/long
* @return String * @see * https://binance-docs.github.io/apidocs/spot/en/#new-order-trade */ public String ocoOrder(LinkedHashMap parameters) { ParameterChecker.checkParameter(parameters, "symbol", String.class); ParameterChecker.checkParameter(parameters, "side", String.class); ParameterChecker.checkRequiredParameter(parameters, "quantity"); ParameterChecker.checkRequiredParameter(parameters, "price"); ParameterChecker.checkRequiredParameter(parameters, "stopPrice"); return requestHandler.sendSignedRequest(baseUrl, OCO_ORDER, parameters, HttpMethod.POST, showLimitUsage); } private final String OCO_LIST = "/api/v3/orderList"; /** * Cancel an entire Order List. *

* 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 *

* recvWindow -- optional/long
* @return String * @see * https://binance-docs.github.io/apidocs/spot/en/#query-current-order-count-usage-trade */ public String rateLimitOrder(LinkedHashMap parameters) { return requestHandler.sendSignedRequest(baseUrl, RATE_LIMIT, parameters, HttpMethod.GET, showLimitUsage); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy