Class BinanceTradeService
- All Implemented Interfaces:
BaseService
,TradeService
public class BinanceTradeService extends BinanceTradeServiceRaw implements TradeService
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BinanceTradeService.BinanceOrderFlags
-
Field Summary
Fields inherited from class org.knowm.xchange.binance.service.BinanceBaseService
apiKey, binance, binanceFutures, LOG, signatureCreator
Fields inherited from class org.knowm.xchange.service.BaseResilientExchangeService
resilienceRegistries
Fields inherited from class org.knowm.xchange.service.BaseExchangeService
exchange
-
Constructor Summary
Constructors Constructor Description BinanceTradeService(BinanceExchange exchange, ResilienceRegistries resilienceRegistries)
-
Method Summary
Modifier and Type Method Description Collection<String>
cancelAllOrders(CancelAllOrders orderParams)
boolean
cancelOrder(String orderId)
cancels order with matching orderId (conveniance method, typical just delegate to cancelOrder(CancelOrderByIdParams))boolean
cancelOrder(CancelOrderParams params)
cancels order with matching orderParamsOpenOrdersParams
createOpenOrdersParams()
CreateOpenOrdersParams
object specific to this exchange.TradeHistoryParams
createTradeHistoryParams()
CreateTradeHistoryParams
object specific to this exchange.OpenOrders
getOpenOrders()
Gets the open ordersOpenOrders
getOpenOrders(CurrencyPair pair)
OpenOrders
getOpenOrders(OpenOrdersParams params)
Gets the open ordersOpenPositions
getOpenPositions()
Get all openPositions of the exchangeCollection<Order>
getOrder(String... orderIds)
get's the latest order form the order book that with matching orderIdCollection<Order>
getOrder(OrderQueryParams... params)
get's the latest order form the order book that with matching orderQueryParamsClass[]
getRequiredCancelOrderParamClasses()
Returns required cancel order parameter as classesClass
getRequiredOrderQueryParamClass()
Returns required get order parameter as classesUserTrades
getTradeHistory(TradeHistoryParams params)
Fetch the history of user trades.String
placeLimitOrder(LimitOrder limitOrder)
Place a limit orderString
placeMarketOrder(MarketOrder mo)
Place a market orderString
placeStopOrder(StopOrder order)
Place a stop ordervoid
placeTestOrder(OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice)
void
placeTestOrder(OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice, BigDecimal quoteOrderQty, Long trailingDelta)
Methods inherited from class org.knowm.xchange.binance.service.BinanceTradeServiceRaw
allOrders, cancelAllOpenOrdersAllProducts, cancelOrderAllProducts, closeDataStream, getDustLog, keepAliveDataStream, myTradesAllProducts, myTradesPermits, newFutureOrder, newOrder, openOrdersAllProducts, openOrdersAllProducts, openOrdersPermits, openPositions, orderStatusAllProducts, startUserDataStream, testNewOrder
Methods inherited from class org.knowm.xchange.binance.service.BinanceBaseService
getExchangeInfo, getFutureExchangeInfo, getRecvWindow, getSystemStatus, getTimestampFactory
Methods inherited from class org.knowm.xchange.service.BaseResilientExchangeService
decorateApiCall, rateLimiter, rateLimiter, retry, retry
Methods inherited from class org.knowm.xchange.service.BaseExchangeService
verifyOrder, verifyOrder, verifyOrder
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.knowm.xchange.service.trade.TradeService
changeOrder, verifyOrder, verifyOrder
-
Constructor Details
-
BinanceTradeService
-
-
Method Details
-
getOpenOrders
Description copied from interface:TradeService
Gets the open orders- Specified by:
getOpenOrders
in interfaceTradeService
- Returns:
- the open orders, null if some sort of error occurred. Implementers should log the error.
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data
-
getOpenOrders
- Throws:
IOException
-
getOpenOrders
Description copied from interface:TradeService
Gets the open orders- Specified by:
getOpenOrders
in interfaceTradeService
- Parameters:
params
- The parameters describing the filter. Note thatOpenOrdersParams
is an empty interface. Exchanges should implement its own params object. Params should be create withTradeService.createOpenOrdersParams()
.- Returns:
- the open orders, null if some sort of error occurred. Implementers should log the error.
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data
-
placeMarketOrder
Description copied from interface:TradeService
Place a market orderIf your orders amount does to meet the restrictions dictated by
InstrumentMetaData
then the exchange will reject your order. UseOrderValuesHelper
to validate and / or adjust it while you'r building an order.- Specified by:
placeMarketOrder
in interfaceTradeService
- Returns:
- the order ID
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data- See Also:
OrderValuesHelper
-
placeLimitOrder
Description copied from interface:TradeService
Place a limit orderIf your orders amount or limit price does to meet the restrictions dictated by
InstrumentMetaData
then the exchange will reject your order. UseOrderValuesHelper
to validate and / or adjust those values while you'r building an order.- Specified by:
placeLimitOrder
in interfaceTradeService
- Returns:
- the order ID
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data- See Also:
OrderValuesHelper
-
placeStopOrder
Description copied from interface:TradeService
Place a stop orderIf your orders amount or spot price does to meet the restrictions dictated by
InstrumentMetaData
then the exchange will reject your order. UseOrderValuesHelper
to validate and / or adjust those values while you'r building an order.- Specified by:
placeStopOrder
in interfaceTradeService
- Returns:
- the order ID
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data- See Also:
OrderValuesHelper
-
placeTestOrder
public void placeTestOrder(OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice) throws IOException- Throws:
IOException
-
placeTestOrder
public void placeTestOrder(OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice, BigDecimal quoteOrderQty, Long trailingDelta) throws IOException- Throws:
IOException
-
cancelOrder
Description copied from interface:TradeService
cancels order with matching orderParams- Specified by:
cancelOrder
in interfaceTradeService
- Returns:
- true if order was successfully cancelled, false otherwise.
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data
-
cancelOrder
Description copied from interface:TradeService
cancels order with matching orderId (conveniance method, typical just delegate to cancelOrder(CancelOrderByIdParams))- Specified by:
cancelOrder
in interfaceTradeService
- Returns:
- true if order was successfully cancelled, false otherwise.
-
getRequiredCancelOrderParamClasses
Description copied from interface:TradeService
Returns required cancel order parameter as classesDifferent trading services requires different parameters for order cancellation. To provide generic operation of the trade service interface. This method returns
Class
of the parameter objects as an array. This class information can be utilized by the caller ofTradeService.cancelOrder(CancelOrderParams)
to create instances of the required parameters such asCancelOrderByIdParams
,CancelOrderByInstrument
etc...- Specified by:
getRequiredCancelOrderParamClasses
in interfaceTradeService
- Returns:
- Class types for the required parameter classes. Default implementation returns an array
with a single
CancelOrderByIdParams
element
-
getTradeHistory
Description copied from interface:TradeService
Fetch the history of user trades.If you are calling this method for single exchange, known at the development time, you may pass an object of specific *TradeHistoryParam class that is nested it that exchange's trade service.
If, however, you are fetching user trade history from many exchanges using the same code, you will find useful to create the parameter object with
TradeService.createTradeHistoryParams()
and check which parameters are required or supported using instanceof operator. See subinterfaces ofTradeHistoryParams
. Note that whether an interface is required or supported will vary from exchange to exchange and it's described only through the javadoc.There is also implementation of all the common interfaces,
TradeHistoryParamsAll
, that, with all properties set non-null, should work with any exchange.Some exchanges allow extra parameters, not covered by any common interface. To access them, you will have to use the object returned by
TradeService.createTradeHistoryParams()
and cast it to the exchange-specific type.- Specified by:
getTradeHistory
in interfaceTradeService
- Parameters:
params
- The parameters describing the filter. Note thatTradeHistoryParams
is an empty interface. Exact set of interfaces that are required or supported by this method is described by the type of object returned fromTradeService.createTradeHistoryParams()
and the javadoc of the method.- Returns:
- UserTrades as returned by the exchange API
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data- See Also:
TradeService.createTradeHistoryParams()
,TradeHistoryParamsAll
-
getOrder
Description copied from interface:TradeService
get's the latest order form the order book that with matching orderQueryParams- Specified by:
getOrder
in interfaceTradeService
- Returns:
- the order as it is on the exchange.
- Throws:
IOException
- - Indication that a networking error occurred while fetching JSON data
-
getOpenPositions
Description copied from interface:TradeService
Get all openPositions of the exchange- Specified by:
getOpenPositions
in interfaceTradeService
- Throws:
IOException
-
cancelAllOrders
- Specified by:
cancelAllOrders
in interfaceTradeService
- Throws:
IOException
-
createTradeHistoryParams
Description copied from interface:TradeService
CreateTradeHistoryParams
object specific to this exchange. Object created by this method may be used to discover supported and requiredTradeService.getTradeHistory(TradeHistoryParams)
parameters and should be passed only to the method in the same class as the createTradeHistoryParams that created the object.- Specified by:
createTradeHistoryParams
in interfaceTradeService
-
createOpenOrdersParams
Description copied from interface:TradeService
CreateOpenOrdersParams
object specific to this exchange. Object created by this method may be used to discover supported and requiredTradeService.getOpenOrders(OpenOrdersParams)
parameters and should be passed only to the method in the same class as the createOpenOrdersParams that created the object.- Specified by:
createOpenOrdersParams
in interfaceTradeService
-
getOrder
Description copied from interface:TradeService
get's the latest order form the order book that with matching orderId- Specified by:
getOrder
in interfaceTradeService
- Returns:
- the order as it is on the exchange.
-
getRequiredOrderQueryParamClass
Description copied from interface:TradeService
Returns required get order parameter as classesDifferent trading services requires different parameters for order querying. To provide generic operation of the trade service interface, This method returns
Class
of the parameter objects as an array. This class information can be utilized by the caller ofTradeService.getOrder(OrderQueryParams...)
to create instances of the required parameter such asOrderQueryParamCurrencyPair
,OrderQueryParamInstrument
etc...- Specified by:
getRequiredOrderQueryParamClass
in interfaceTradeService
- Returns:
- Class type for the required parameter class. Default implementation returns an instance
of
OrderQueryParams
element
-