API Binance Futures

Binance

 

Binance is an international multi-language cryptocurrency exchange. It offers some APIs to access Binance data. This component allows 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. Only are only private and related to user data, those methods requires 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  

 

 

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  

 

 

 

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.