API Binance Futures

Binance

 

Binance is an international multi-language cryptocurrency exchange. It offers some APIs to access Binance data. This component allows you to get Binance Futures WebSocket Market Streams.

 

https://binance-docs.github.io/apidocs/futures/en

https://binance-docs.github.io/apidocs/delivery/en

Futures Contracts

Binance API has 2 types of methods: public and private. Public methods can be accessed without authentication, example: get ticker prices. Some are private and related to user data; those methods require the use of Binance API keys.

 

 

Client can connect to USDT or COIN Binance Futures, set which contract you want to trade using FuturesContracts property:

 

 

Client can connect to Production or Demo Binance accounts. If TestNet property is enabled, it will connect to Demo account, otherwise will connect to production Binance Servers.

 

 

WebSocket Stream API

Client can subscribe / unsubscribe from events after a successful connection.

The following Subscription / Unsubscription methods are supported.

 

Method Parameters Description
AggregateTrades Symbol The Aggregate Trade Streams push trade information that is aggregated for a single taker order every 100 milliseconds.
MarkPrice Symbol, UpdateSpeed Mark price and funding rate for a single symbol pushed every 3 seconds or every second.
AllMarkPrice UpdateSpeed Mark price and funding rate for all symbols pushed every 3 seconds or every second.
KLine Symbol, Interval The Kline/Candlestick Stream push updates to the current klines/candlestick every 250 milliseconds (if existing).
MiniTicker Symbol 24hr rolling window mini-ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before.
AllMiniTicker   24hr rolling window mini-ticker statistics for all symbols. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before. Note that only tickers that have changed will be present in the array.
Ticker Symbol 24hr rolling window ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before.
AllMarketTickers   24hr rolling window ticker statistics for all symbols. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before. Note that only tickers that have changed will be present in the array.
BookTicker Symbol Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.
AllBookTickers   Pushes any update to the best bid or ask's price or quantity in real-time for all symbols.
LiquidationOrders Symbol The Liquidation Order Streams push force liquidation order information for specific symbol
AllLiquidationOrders   The All Liquidation Order Streams push force liquidation order information for all symbols in the market.
PartialBookDepth Symbol, Depth Top bids and asks, Valid are 5, 10, or 20.
DiffDepth Symbol Bids and asks, pushed every 250 milliseconds, 500 milliseconds, 100 milliseconds or in real time(if existing)

 

After a successful subcription / unsubscription, client receives a message about it, where id is the result of Subscribed / Unsubscribed method.

 


{
  "result": null,
  "id": 1
}

User Data Stream API

Requires a valid ApiKey obtained from your binance account, and ApiKey must be set in Binance.ApiKey property of component.

 

The following data is pushed to client every time there is a change. There is no need to subscribe to any method, this is done automatically if you set a valid ApiKey.

 

Method Description
Margin Call When the user's position risk ratio is too high, this stream will be pushed. This message is only used as risk guidance information and is not recommended for investment strategies. In the case of a highly volatile market, there may be the possibility that the user's position has been liquidated at the same time when this stream is pushed out.
Balance and Position Update

Balance Update occurs during the following:

 

  • When balance or position get updated, this event will be pushed.
  • When "FUNDING FEE" changes to the user's balance.
  •  
Order Update When new order created, order status changed will push such event.

 

 

REST API

All endpoints return either a JSON object or array. Data is returned in ascending order. Oldest first, newest last.

 

Public API EndPoints

 

These endpoints can be accessed without any authorization.

 

General EndPoints

 

Method Parameters Description
Ping   Test connectivity to the Rest API.
GetServerTime   Test connectivity to the Rest API and get the current server time.
GetExchangeInformation   Current exchange trading rules and symbol information

 

 

Market Data EndPoints

 

Method Parameters Description
GetOrderBook Symbol Get Order Book.
GetTrades Symbol Get recent trades
GetHistoricalTrades Symbol Get older trades.
GetAggregateTrades Symbol Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
GetKLines Symbol, Interval Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
Get24hrTicker Symbol 24 hour rolling window price change statistics. Careful when accessing this with no symbol.
GetPriceTicker Symbol Latest price for a symbol or symbols.
GetBookTicker Symbol Best price/qty on the order book for a symbol or symbols.
GetMarkPrice Symbol Mark Price and Funding Rate
GetFundingRateHistory Symbol  
GetOpenInterest Symbol Get present open interest of a specific symbol.
GetOpenInterestStatistics Symbol, Period  
GetTopTraderAccountRatio Symbol, Period  
GetTopTraderPositionRatio Symbol, Period  
GetGlobalAccountRatio Symbol, Period  
GetTakerVolume Symbol, Period
GetContinuousKLines Pair, ContractType, Interval Kline/candlestick bars for a specific contract type.
GetIndexPriceKLines Pair, Interval Kline/candlestick bars for the index price of a pair.
GetMarkPriceKLines Symbol, Interval Kline/candlestick bars for the mark price of a symbol.
GetPremiumIndexKLines Symbol, Interval Premium index kline bars of a symbol.
GetFundingInfo Get funding rate info for all symbols.
GetPriceTickerV2 Symbol Latest price for a symbol or symbols (V2).
GetIndexInfo Symbol Get index info.
GetAssetIndex Symbol Get asset index for multi-assets mode.
GetConstituents Symbol Get index constituents.
GetDeliveryPrice Pair Get delivery price.
GetBasis Pair, ContractType, Period Get basis data.

 

 

Private API EndPoints

 

Requires an APIKey and APISecret to get authorized by server.

 

Account and Trades EndPoints

 

Method Parameters Description
ChangePositionMode DualPosition Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
GetCurrentPositionMode   Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
NewOrder Symbol, Side, PositionSide, Type Send in a new order.
PlaceMarketOrder Side, Symbol, Quantity  
PlaceLimitOrder Side, Symbol, Quantity, LimitPrice  
PlaceStopOrder Side, Symbol, Quantity, StopPrice, LimitPrice  
PlaceTrailingStopOrder Side, Symbol, Quantity, aActivationPrice, aCallbackRate  
QueryOrder Symbol Check an order's status.
CancelOrder Symbol Cancel an active order. Either OrderId or OrigClientOrderId must be sent.
CancelAllOpenOrders Symbol  
AutoCancelAllOpenOrders Symbol, CountDownTimer Cancel all open orders of the specified symbol at the end of the specified countdown.
QueryCurrentOpenOrder Symbol  
GetOpenOrders Symbol Get all open orders on a symbol. Careful when accessing this with no symbol.
GetAllOrders Symbol Get all account orders; active, canceled, or filled.
GetAccountBalance    
GetAccountInformation   Get current account information.
ChangeInitialLeverage Symbol, Leverage Change user's initial leverage of specific symbol market.
ChangeMarginType Symbol, MarginType  
ModifyIsolatedPositionMargin Symbol, Amount, Type  
GetPositionMarginChangeHistory Symbol  
GetPositionInformation Symbol  
GetAccountTradeList Symbol  
GetIncomeHistory Symbol  
GetNotionalLeverageBracket Symbol
TestNewOrder Symbol, Side, PositionSide, Type Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
ModifyOrder Symbol Modify an existing order.
NewBatchOrders BatchOrders Place multiple orders.
ModifyBatchOrders BatchOrders Modify multiple orders.
CancelBatchOrders Symbol Cancel multiple orders.
GetOrderAmendment Symbol Get order modification history.
CountdownCancelAll Symbol, CountdownTime Cancel all open orders of the specified symbol at the end of the specified countdown.
GetForceOrders Symbol Get user's force liquidation orders.
GetADLQuantile Symbol Get ADL quantile estimation for positions.
GetAccountBalanceV3 Get futures account balance (V3).
GetAccountInformationV3 Get current account information (V3).
GetPositionInformationV3 Symbol Get current position information (V3).
GetCommissionRate Symbol Get user commission rate.
GetAccountConfig Get current account configuration.
GetSymbolConfig Symbol Get symbol configuration.
GetOrderRateLimit Get user's order rate limit.
GetApiTradingStatus Symbol Get API trading quantitative rules indicators.
ChangeMultiAssetsMode MultiAssetsMargin Change user's multi-assets mode. Multi-Assets Mode: true; Single-Asset Mode: false.
GetMultiAssetsMode Get user's current multi-assets mode.
SetFeeBurn FeeBurn Change user's BNB fee burn status.
GetFeeBurn Get user's BNB fee burn status.
CreateListenKey Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent.
KeepAliveListenKey Keepalive a user data stream to prevent a timeout.
CloseListenKey Close a user data stream.

 

 

 

Events

Binance Futures Messages are received in TsgcWebSocketClient component, you can use the following events:

 

OnConnect

After a successful connection to Binance server.

OnDisconnect

After a disconnection from Binance server

OnMessage

Messages sent by server to client are handled in this event.

OnError

If there is any error in protocol, this event will be called.

OnException

If there is an unhandled exception, this event will be called.

 

Additionally, there is a specific event in Binance API Component, called OnBinanceHTTPException, which is raised every time there is an error calling an HTTP Request (REST API or WebSocket User Stream).

 

(*) Due to changes in Binance Servers, Indy versions before Rad Studio 10.1, won't be able to connect to Test Servers. This issue doesn't affect to Enterprise Edition or if the Indy version has been upgraded to the latest.