Binance get all orders

Содержание
  1. How to Get Binance Market Prices and Other Data
  2. All Binance Markets in One Listing
  3. Binance Market Data
  4. Market Current Price
  5. Best Ask Price
  6. Best Bid Price
  7. Last Trade Price
  8. 24h Price Change
  9. Open Price
  10. 24h Highest Price
  11. 24h Lowest Price
  12. Close Price
  13. Market Volume
  14. Market Base Volume
  15. Binance Historical Data
  16. Historical Price
  17. Historical Open Price
  18. Historical High Price
  19. Historical Low Price
  20. Historical Close Price
  21. Historical Market Volume
  22. Historical Market Base Volume
  23. Change Log
  24. General Info
  25. testnet
  26. SDK and Code Demonstration
  27. Python3
  28. General API Information
  29. HTTP Return Codes
  30. Error Codes and Messages
  31. General Information on Endpoints
  32. LIMITS
  33. IP Limits
  34. Order Rate Limits
  35. Endpoint Security Type
  36. SIGNED (TRADE and USER_DATA) Endpoint Security
  37. Timing Security
  38. SIGNED Endpoint Examples for POST /fapi/v1/order
  39. Example 1: As a query string
  40. Example 2: As a request body
  41. Example 3: Mixed query string and request body
  42. Public Endpoints Info
  43. Terminology
  44. ENUM definitions
  45. Filters
  46. Symbol filters
  47. PRICE_FILTER
  48. LOT_SIZE
  49. MARKET_LOT_SIZE
  50. MAX_NUM_ORDERS
  51. MAX_NUM_ALGO_ORDERS
  52. PERCENT_PRICE
  53. MIN_NOTIONAL
  54. Postman Collections
  55. Market Data Endpoints
  56. Test Connectivity
  57. Check Server Time
  58. Exchange Information
  59. Order Book
  60. Recent Trades List
  61. Old Trades Lookup (MARKET_DATA)
  62. Compressed/Aggregate Trades List
  63. Kline/Candlestick Data
  64. Continuous Contract Kline/Candlestick Data
  65. Index Price Kline/Candlestick Data
  66. Mark Price Kline/Candlestick Data
  67. Mark Price
  68. Get Funding Rate History
  69. 24hr Ticker Price Change Statistics
  70. Symbol Price Ticker
  71. Symbol Order Book Ticker
  72. Open Interest
  73. Open Interest Statistics
  74. Top Trader Long/Short Ratio (Accounts) (MARKET_DATA)
  75. Top Trader Long/Short Ratio (Positions)
  76. Long/Short Ratio
  77. Taker Buy/Sell Volume
  78. Historical BLVT NAV Kline/Candlestick
  79. Composite Index Symbol Information
  80. Websocket Market Streams
  81. Live Subscribing/Unsubscribing to streams
  82. Subscribe to a stream
  83. Unsubscribe to a stream
  84. Listing Subscriptions
  85. Setting Properties
  86. Retrieving Properties
  87. Error Messages
  88. Aggregate Trade Streams
  89. Mark Price Stream
  90. Mark Price Stream for All market
  91. Kline/Candlestick Streams
  92. Continuous Contract Kline/Candlestick Streams
  93. Individual Symbol Mini Ticker Stream
  94. All Market Mini Tickers Stream
  95. Individual Symbol Ticker Streams
  96. All Market Tickers Streams
  97. Individual Symbol Book Ticker Streams
  98. All Book Tickers Stream
  99. Liquidation Order Streams
  100. All Market Liquidation Order Streams
  101. Partial Book Depth Streams
  102. Diff. Book Depth Streams
  103. How to manage a local order book correctly
  104. BLVT Info Streams
  105. BLVT NAV Kline/Candlestick Streams
  106. Composite Index Symbol Information Streams
  107. Account/Trades Endpoints
  108. New Future Account Transfer
  109. Get Future Account Transaction History List (USER_DATA)
  110. Change Position Mode(TRADE)
  111. Get Current Position Mode(USER_DATA)
  112. Change Multi-Assets Mode (TRADE)
  113. Get Current Multi-Assets Mode (USER_DATA)
  114. New Order (TRADE)
  115. Place Multiple Orders (TRADE)
  116. Query Order (USER_DATA)
  117. Cancel Order (TRADE)
  118. Cancel All Open Orders (TRADE)
  119. Cancel Multiple Orders (TRADE)
  120. Auto-Cancel All Open Orders (TRADE)
  121. Query Current Open Order (USER_DATA)
  122. Current All Open Orders (USER_DATA)
  123. All Orders (USER_DATA)
  124. Futures Account Balance V2 (USER_DATA)
  125. Account Information V2 (USER_DATA)
  126. Change Initial Leverage (TRADE)
  127. Change Margin Type (TRADE)
  128. Modify Isolated Position Margin (TRADE)
  129. Get Position Margin Change History (TRADE)
  130. Position Information V2 (USER_DATA)
  131. Account Trade List (USER_DATA)
  132. Get Income History(USER_DATA)
  133. Notional and Leverage Brackets (USER_DATA)
  134. Position ADL Quantile Estimation (USER_DATA)
  135. User’s Force Orders (USER_DATA)
  136. User API Trading Quantitative Rules Indicators (USER_DATA)
  137. User Commission Rate (USER_DATA)
  138. User Data Streams
  139. Start User Data Stream (USER_STREAM)
  140. Keepalive User Data Stream (USER_STREAM)
  141. Close User Data Stream (USER_STREAM)
  142. Event: User Data Stream Expired
  143. Event: Margin Call
  144. Event: Balance and Position Update
  145. Event: Order Update
  146. Event: Account Configuration Update previous Leverage Update
  147. Error Codes

How to Get Binance Market Prices and Other Data

All Binance Markets in One Listing

This function call will return the list of all markets along with all their data point. It is recommended to use this to avoid the Google Sheets imposed API call quota.

The following market data will be returned:

  • last_updated , when the data has been fetched from the exchange, timezone is UTC time.
  • market , the market name following the syntax BASE/QUOTE .
  • price , the current price, either the last trade price when available or the current ask price.
  • ask , the best ask price currently in the order book.
  • bid , the best bid price currently in the other book.
  • open , the 24h open price.
  • high , the 24h high price.
  • low , the 24h low price.
  • close , the 24h close price, often the same as the last price.
  • last , the price of the last trade.
  • change 24h , the price change in percentage over the last 24h.
  • volume , the volume traded over the last 24h in quote currency ( USD in BTC/USD ).
  • volume_base , the volume traded over the last 24h in base currency ( BTC in BTC/USD ).

Notes:

  • When the exchange doesn’t provide a given market data, a hyphen (-) will be shown.
  • Binance doesn’t have USD markets. Due to a large number of users getting Market not available error, any query for a Binance pair with a USD quote will be transparently mapped to USDT.

Binance Market Data

Market Current Price

This will return Ethereum price in Bitcoin as currently traded on Binance:

Same thing as calling =CRYPTOFINANCE(«BINANCE:ETH/BTC», «price») .

Best Ask Price

This will return Ethereum best ask price in Bitcoin as currently available on Binance order book:

Best Bid Price

This will return Ethereum best bid price in Bitcoin as currently available on Binance order book:

Last Trade Price

This call will return Ethereum last trade price in Bitcoin as it just happened on Binance:

24h Price Change

This call will return Ethereum price change percentage in Bitcoin over the last 24h on Binance:

Open Price

This call will return Ethereum open price in Bitcoin as of 24h ago on Binance:

24h Highest Price

This call will return Ethereum highest price in Bitcoin over the last 24h ago on Binance:

24h Lowest Price

This call will return Ethereum lowest price in Bitcoin over the last 24h ago on Binance:

Close Price

This call will return Ethereum last trade price in Bitcoin as it just happened on Binance:

Same thing as calling =CRYPTOFINANCE(«BINANCE:ETH/BTC», «last») .

Market Volume

This call will return Ethereum traded volume in Bitcoin over the last 24h on Binance:

Market Base Volume

This call will return Ethereum traded volume in ETH over the last 24h on Binance:

Binance Historical Data

Historical prices are available on daily and hourly candles, including open , high , low , close , volume and volume_base .

Quota: Historical data has with a quota of 25 calls per day per user. The quota reset itself everyday at midnight UTC. For unlimited data and full historical listing the Historical Data subscription is available.

ProTip: See here for how to reference other cells to build the date or specifying the hour.

Historical Price

Same thing as calling close .

Historical Open Price

Historical High Price

Historical Low Price

Historical Close Price

Historical Market Volume

Historical Market Base Volume

CRYPTOFINANCE (Google Sheets add-on) and its authors are not responsible for any trading or financial loss incurred by following the data returned. The service is provided «as is», without any warranty of any kind, expressed or implied.

Источник

Change Log

2021-05-06

  • Update streams:
    • Previous Leverage Update event ACCOUNT_CONFIG_UPDATE expanded as account configuration update event, including leverage update and Multi-Assets margin status update.
    • Balance and Position Update event ACCOUNT_UPDATE add new event reason type m as AUTO_EXCHANGE to represent Multi-Assets margin auto-exchange event
  • POST /fapi/v1/multiAssetsMargin to change Multi-Assets margin mode
  • GET /fapi/v1/multiAssetsMargin to check Multi-Assets margin mode
  • New object assets as asset information in response of GET /fapi/v1/exchangeInfo .
  • New field marginAvailable in response of GET /fapi/v2/balance and GET /fapi/v2/account to indicate whether the asset can be used as margin in Multi-Assets mode.

2021-04-27

  • The following liquidation orders streams do not push realtime order data anymore. Instead, they push snapshot order data at a maximum frequency of 1 order push per second.:
    • @forceOrder
    • !forceOrder@arr
  • The endpoint GET /fapi/v1/allForceOrders stop being maintained and no longer accepts request.

2021-04-22

  • New field «bc» for balance change in event «ACCOUNT_UPDATE»

2021-03-02

New endpoint GET /fapi/v1/indexPriceKlines to get index price kline/candlestick data.

New endpoint GET /fapi/v1/markPriceKlines to get mark price kline/candlestick data.

2021-02-24

REST RATE LIMIT WEIGHT

  • The weight of endpoint GET /fapi/v2/balance is updated to 5
  • The weight of endpoint GET /fapi/v2/positionRisk is updated to 5

2021-02-22

REST RATE LIMIT WEIGHT

  • The weight of endpoint GET /fapi/v1/income is updated to 30
  • The query time period for endpoint GET /fapi/v1/allOrders must be less than 7 days.
  • The query time period for endpoint GET /fapi/v1/allForceOrders must be within the recent 7 days.

2021-01-26

WEB SOCKET USER DATA STREAM

  • New WebSocket stream ACCOUNT_CONFIG_UPDATE in USER-DATA-STREAM for leverage changed update

REST RATE LIMIT WEIGHT

  • Following endpoints’ weights will be updated to 20 with symbol and 50 without symbol:
    • GET /fapi/v1/allForceOrders
    • GET /fapi/v1/forceOrders
  • New filter «MIN_NOTIONAL» whicht defines the minimum notional value allowed for an order on a symbol, and shown in the /fapi/v1/exchangeInfo

2021-01-21

The regular expression rule for newClientOrderId updated as ^[\.A-Z\:/a-z0-9_-]<1,36>$

2021-01-04

REST RATE LIMIT WEIGHT

Following endpoints will use new weight rule based on the paremeter «LIMIT» in the request:

  • GET /fapi/v1/klines
  • GET /fapi/v1/continuousKlines

Following endpoints’ weights will be updated to 20:

  • GET /fapi/v1/historicalTrades
  • GET /fapi/v1/allForceOrders
  • GET /fapi/v1/forceOrders
  • GET /fapi/v1/aggTrades

2020-12-08

  • New field e for event type in payload of streams @bookTicker and !bookTicker
  • New field P for estimated settle price in payload of streams @markPrice , @markPrice@1s , !markPrice@arr , and !markPrice@arr@1s .
  • New stream

_ @continuousKline_ for continuous contract kline

    New field «estimatedSettlePrice» in response to GET /fapi/v1/premiumIndex

New fields in response to GET /fapi/v1/exchangeInfo :

New endpoint GET /fapi/v1/continuousKlines to get continuous contract kline data

  • Contract types:
    • PERPETUAL
    • CURRENT_MONTH
    • NEXT_MONTH
    • CURRENT_QUARTER
    • NEXT_QUARTER

2020-11-27

  • New endpoint GET /fapi/v1/commissionRate to get user commission rate.

2020-11-13

WEB SOCKET STREAM

  • In order to provide users with more secure and stable services, the update time of depth@0ms and @depth @0ms is dynamically adjusted according to the total amount of data traffic and other objective conditions.

2020-11-10

  • New field «marginAsset» for margin asset in the response to GET /fapi/v1/exchangeInfo .
  • New field «positionAmt» for position amount in the response to GET /fapi/v2/account .

2020-11-09

WEB SOCKET USER DATA STREAM

Please notice: new streamlined and optimized push rules on event ACCOUNT_UPDATE in USER-DATA-STREAM

When an asset of a user is changed:

  • Only this asset and its balance information will be pushed
  • Other assets and information will no longer be pushed even the balances may not be 0
  • If none of the open positions change, the position «P» will only return an empty []

When a position or the margin type of a symbol is changed:

  • «P» will push the details in the «BOTH» position of this symbol
  • If the change happens in «LONG» or «SHORT» position, the changed «LONG» or «SHORT» position of this symbol will be pushed
  • Initialized «LONG» or «SHORT» isolated position of this symbol will also be pushed
  • Position information of other symbols will no longer be pushed, even their positions may not be 0

In short, the full information of assets and positions should be obtained via the related RESTful endpoints( GET /fapi/v2/account and GET /fapi/v2/positionRisk ), and the locally cached asset or position data can be updated via the event ACCOUNT_UPDATE in Websocket USER-DATA-STREAM with the information of changed asset or position.

Please visit here to get examples for helping to understand the upgrade.

2020-10-27

WEB SOCKET STREAM

  • The maximum stream number that a single connection can listen to changes as 200.

2020-10-10

  • New WebSocket streams @compositeIndex for composite index symbol information.

2020-10-09

  • New endpoint GET /fapi/v1/indexInfo to get information of composite index.

2020-09-18

  • New endpoint GET /fapi/v1/apiTradingStatus to get futures API trading quantitative rules indicators

2020-09-16

  • New endpoint GET /fapi/v1/lvtKlines to get gistorical BLVT Kline.
    The BLVT NAV system is working relatively with Binance Futures, so the endpoint is based on fapi.
  • New WebSocket streams for BLVT
    The BLVT NAV system is working relatively with Binance Futures, so the endpoint is based on futures websocket service.
    • @tokenNav for BLVT Info streams
    • @nav_Kline_ for BLVT NAV Kline streams

2020-09-09

  • Some orders that were cancelled/expired will be removed gradually from API endpoints.
    • Orders that meet criteria
      • order status is CANCELED or EXPIRED , AND
      • order has NO filled trade, AND
      • created time + 7 days GET /fapi/v1/order
      • GET /fapi/v1/allOrders

2020-08-14

  • New field «indexPrice» in response to endpoint GET /fapi/v1/premiumIndex .
  • New field «i» for indexPrice in payload of ws streams:
    • @markPrice ,
    • @markPrice@1s ,
    • !markPrice@arr ,
    • !markPrice@arr@1s

2020-08-12

  • New endpoint GET /fapi/v1/forceOrders to get the user’s force orderes.

2020-07-30

  • New endpoint GET /fapi/v1/adlQuantile to get the positions’ ADL quantile estimation values

2020-07-17

  • Weights of endpoint GET /fapi/v1/income has been changed as 20

2020-07-02

  • New field «m» for event reason type in event «ACCOUNT_UPDATE»
  • New field «rp» for the realized profit of the trade in event «ORDER_TRADE_UPDATE»

2020-06-15

  • New fields in responses to GET /fapi/v2/account and GET /fapi/v2/balance :
    • availableBalance
    • maxWithdrawAmount

2020-06-04

  • New endpoints of version 2 of fapi, having better performance than the v1 endpoints:
    • GET /fapi/v2/account
    • GET /fapi/v2/balance

2020-06-02

  • New endpoint GET /fapi/v2/positionRisk in version 2 of fapi:
    • User can choose to send specific «symbol».
    • All symbols in the market can be returned.
    • Different responses for «One-way» or «Hedge» position mode.
    • Better performance than the v1 endpoint.

2020-05-18

New parameter closePosition for endpoint POST /fapi/v1/order :
If a STOP_MARKET or TAKE_PROFIT_MARKET order with closePosition=true is triggered,all of the current long position( if SELL order) or current short position( if BUY order) will be closed.

New field closePosition in response to endpoints:

  • POST /fapi/v1/order
  • POST /fapi/v1/batchOrders
  • GET /fapi/v1/order
  • DELETE /fapi/v1/order
  • DELETE /fapi/v1/batchOrders
  • GET /fapi/v1/openOrder
  • GET /fapi/v1/openOrders
  • GET /fapi/v1/allOrders

2020-05-18

  • Some orders that were cancelled/expired will be removed gradually from API endpoints, but they are still available from Web UI.
    • Orders that meet criteria
      • order status is CANCELED or EXPIRED , AND
      • order has NO filled trade, AND
      • created time + 30 days GET /fapi/v1/order
      • GET /fapi/v1/allOrders

2020-05-15

  • New fields in payloads of @bookTicker and !bookTicker :
    • E for event time
    • T for transaction time

2020-05-14

  • New field time for transaction time in response to endpoints:
    • GET /fapi/v1/ticker/price
    • GET /fapi/v1/ticker/bookTicker
    • GET /fapi/v1/openInterest

2020-05-11

  • New endpoint POST /fapi/v1/s/countdownCancelAll to cancel all open orders of the specified symbol at the end of the specified countdown.
    This rest endpoint means to ensure your open orders are canceled in case of an outage. The endpoint should be called repeatedly as heartbeats so that the existing countdown time can be canceled and repalced by a new one.

2020-05-06

  • Endpoint GET /fapi/v1/leverageBracket is changed as «USER-DATA». It need to be signed, and timestamp is needed.

WEB SOCKET USER DATA STREAM

  • Please notice: event ACCOUNT_UPDATE in USER-DATA-STREAM will be pushed with only account balance or relative position when «FUNDING FEE» occurs.
    • When «FUNDING FEE» occurs in a crossed position, ACCOUNT_UPDATE will be pushed with only the balance B (including the «FUNDING FEE» asset only), without any position P message.
    • When «FUNDING FEE» occurs in an isolated position, ACCOUNT_UPDATE will be pushed with only the balance B (including the «FUNDING FEE» asset only) and the relative position message P ( including the isolated position on which the «FUNDING FEE» occurs only, without any other position message).

2020-04-25

New fields in USER DATA STREAM event ORDER_TRADE_UPDATE :

  • cp stands for Close-All conditional order
  • AP for Activation Price with TRAILING_STOP_MARKET order
  • cr for Callback Rate with TRAILING_STOP_MARKET order

New USER DATA STREAM event MARGIN_CALL .

2020-04-17

  • New parameter newOrderRespType for response type in endpoint POST /fapi/v1/order .
    ACK and RESULT are supported. And for newOrderRespType= RESULT :
    • MARKET order: the final FILLED result of the order will be return directly.
    • LIMIT order with special timeInForce : the final status result of the order(FILLED or EXPIRED) will be returned directly.

2020-04-14

WEB SOCKET STREAM

  • WebSocket connections have a limit of 5 incoming messages per second. A message is considered:
    • A PING frame
    • A PONG frame
    • A JSON control message (e.g. subscribe, unsubscribe)
  • A connection that goes beyond the limit will be disconnected; IPs that are repeatedly disconnected may be banned.
  • A single connection can listen to a maximum of 1024 streams.
Читайте также:  Можно ли научится инвестировать

2020-04-09

  • New endpoint of futures trading data: GET /futures/data/takerlongshortRatio

2020-04-08

  • New endpoint GET /fapi/v1/positionSide/dual to get current position mode.
  • New endpoint POST /fapi/v1/batchOrders to place multiple orders.

2020-04-06

Please notice: event ACCOUNT_UPDATE in USER-DATA-STREAM will not be pushed without update of account balances or positions.

  • ACCOUNT_UPDATE will be pushed only when update happens on user’s account, including changes on balances, positions, or margin type.
  • Unfilled orders or cancelled orders will not make the event ACCOUNT_UPDATE pushed, since there’s no change on positions.
  • Only positions of symbols with non-zero isolatd wallet or non-zero position amount will be pushed in the «position» part of the event ACCOUNT_UPDATE .

New endpoint POST /fapi/v1/positionSide/dual to change position mode: Hedge Mode or One-way Mode.

New parameter positionSide in the following endpoints:

  • POST /fapi/v1/order
  • POST /fapi/v1/positionMargin

New field positionSide in the responses to the following endpoints:

  • POST /fapi/v1/order
  • GET /fapi/v1/order
  • DELETE /fapi/v1/order
  • DELETE /fapi/v1/batchOrders
  • GET /fapi/v1/openOrder
  • GET /fapi/v1/openOrders
  • GET /fapi/v1/allOrders
  • GET /fapi/v1/account
  • GET /fapi/v1/positionMargin/history
  • GET /fapi/v1/positionRisk
  • GET /fapi/v1/userTrades

New field ps for «position side»in USER_DATA_STREAM events ACCOUNT_UPDATE and ORDER_TRADE_UPDATE .

2020-03-30

  • New endpoints of futures trading data:
    • GET /futures/data/openInterestHist
    • GET /futures/data/topLongShortAccountRatio
    • GET /futures/data/topLongShortPositionRatio
    • GET /futures/data/globalLongShortAccountRatio

2020-02-26

  • New order type: TRAILING_STOP_MARKET

2020-02-20

  • New endpoint to query specific current open order: GET /fapi/v1/openOrder

2020-02-17

  • Update time changed as 1000ms for streams @ticker and !ticker@arr
  • New diff depth data with 500ms updates: @depth@500ms
  • New partial depth data with 500ms updates: @depth @500ms

2020-02-12

Faster mark price websocket data with 1s updates: @markPrice@1s and !markPrice@arr@1s

2020-02-05

  • New market data endpoint GET /fapi/v1/leverageBracket to check notional and leverage brackets.

2020-01-19

  • «cumQty» is going to be removed from the responses to DELETE /fapi/v1/order , DELETE /fapi/v1/batchOrders and other order relatived endpoints in the coming weeks.
    Please use «executedQty» instead.

2020-01-17

2020-01-06

  • Faster diff data with real time updates: @depth@0ms

2020-01-03

New endpoints related to isolated position:

  • POST /fapi/v1/marginType
  • POST /fapi/v1/positionMargin
  • GET /fapi/v1/positionMargin/history

New field in response to GET /fapi/v1/positionRisk related to isolated position:

New field in response to GET /fapi/v1/account related to isolated position: isolated

New field in event ACCOUNT_UPDATE :

  • «cw» for cross wallet
  • «mt» for margin type
  • «iw» for isolated wallet (if isolated)

2019-12-19

  • New endpoint GET /fapi/v1/openInterest to get present open interest of a specific symbol.

2019-12-18

  • New event type in user data stream: listenKeyExpired .

2019-12-12

  • New endpoint DELETE /fapi/v1/allOpenOrders to cancel all open orders of a specific symbol.
  • New endpoint DELETE /fapi/v1/batchOrders to cancel a list of open orders.
  • reduceOnly has been supported in orders with type:
    • TAKE_PROFIT
    • TAKE_PROFIT_MARKET
    • STOP
    • STOP_MARKET

2019-11-29

  • New endpoint GET /fapi/v1/allForceOrders to get all liquidation orders.
  • New websocket streams:
    • @forceOrder for liquidation order streams
    • !forceOrder@arr for all market liquidation order streams

2019-11-25

  • GET /fapi/v1/account has new field: positions
  • Added new field time for order creation time in:
    • GET /fapi/v1/openOrders
    • GET /fapi/v1/order
    • GET /fapi/v1/allOrders

2019-11-15

  • New websocket streams:
    • !miniTicker@arr : All market 24hr mini-tickers stream.
    • !ticker@arr : : All market 24hr tickers stream.

2019-11-12

  • WSS now supports live subscribing/unsubscribing to streams.

2019-11-05

  • New order type:
    • STOP_MARKET ,
    • TAKE_PROFIT_MARKET .
  • New parameter workingType in POST /fapi/v1/order :
    order with stop price can be triggered by «CONTRACT_PRICE» or «MARK_PRICE»
  • New keys in USER-DATA-STREAMS:
    • in ORDER_TRADE_UPDATE :
      • «T» as transaction time
      • «wt» as workingType
    • in ACCOUNT_UPDATE :
      • «T» as transaction time

2019-10-28

  • New rest endpoint for income flow history GET /fapi/v1/income

2019-10-25

  • Added «up» in event ACCOUNT_UPDATE in user data stream: the unrealized PnL of the position.
  • Added «R» in event ORDER_TRADE_UPDATE in user data stream, showing if the trade is reduce only.

2019-10-24

  • New WebSocket streams for booktickers added: @bookTicker and !bookTicker .
  • New WebSocket streams for partial orderbook added: @depth and @depth @100ms
  • Faster diff data with 100ms updates: @depth@100ms
  • Added Update Speed : to Websocket Market Streams

2019-10-18

  • New endpoint POST /fapi/v1/leverage for changing user’s initial leverage in specific symbol market.
  • Added «leverage» for current initial leverage and «maxNotionalValue» for notional value limit of current initial leverage in response to GET /fapi/v1/positionRisk .
  • reduceOnly now is supported in the MARKET orders.

2019-10-14

  • Added GET /fapi/v1/fundingRate for getting funding fee rate history.

2019-10-11

  • Added «m» in event ORDER_TRADE_UPDATE in user data stream, showing if the trade is the maker side.

2019-10-08

  • New order parameter reduceOnly for LIMIT orders.
  • New order type TAKE_PROFIT .

2019-09-20

New retured values in response to GET /fapi/v1/account:
maxWithdrawAmount , openOrderInitialMargin , positionInitialMargin

New retured values in response to GET /fapi/v1/positionRisk:
liquidationPrice

General Info

testnet

  • Most of the endpoints can be used in the testnet platform.
  • The REST baseurl for testnet is «https://testnet.binancefuture.com»
  • The Websocket baseurl for testnet is «wss://stream.binancefuture.com»

SDK and Code Demonstration

Disclaimer:

  • The following SDKs are provided by partners and users, and are not officially produced. They are only used to help users become familiar with the API endpoint. Please use it with caution and expand R&D according to your own situation.
  • Binance does not make any commitment to the safety and performance of the SDKs, nor will be liable for the risks or even losses caused by using the SDKs.

Python3

To get the provided SDK for Binance Futures,
please visit https://github.com/Binance-docs/Binance_Futures_python,
or use the command below:
git clone https://github.com/Binance-docs/Binance_Futures_python.git

To get the provided SDK for Binance Futures,
please visit https://github.com/Binance-docs/Binance_Futures_Java,
or use the command below:
git clone https://github.com/Binance-docs/Binance_Futures_Java.git

General API Information

  • Some endpoints will require an API Key. Please refer to this page
  • The base endpoint is: https://fapi.binance.com
  • All endpoints return either a JSON object or array.
  • Data is returned in ascending order. Oldest first, newest last.
  • All time and timestamp related fields are in milliseconds.
  • All data types adopt definition in JAVA.

HTTP Return Codes

  • HTTP 4XX return codes are used for for malformed requests; the issue is on the sender’s side.
  • HTTP 403 return code is used when the WAF Limit (Web Application Firewall) has been violated.
  • HTTP 429 return code is used when breaking a request rate limit.
  • HTTP 418 return code is used when an IP has been auto-banned for continuing to send requests after receiving 429 codes.
  • HTTP 5XX return codes are used for internal errors; the issue is on Binance’s side.
    HTTP 503 return code is used when the API successfully sent the message but not get a response within the timeout period.
    It is important to NOT treat this as a failure operation; the execution status is UNKNOWN and could have been a success.

Error Codes and Messages

  • Any endpoint can return an ERROR

The error payload is as follows:

  • Specific error codes and messages defined in Error Codes.

General Information on Endpoints

  • For GET endpoints, parameters must be sent as a query string .
  • For POST , PUT , and DELETE endpoints, the parameters may be sent as a query string or in the request body with content type application/x-www-form-urlencoded . You may mix parameters between both the query string and request body if you wish to do so.
  • Parameters may be sent in any order.
  • If a parameter sent in both the query string and request body , the query string parameter will be used.

LIMITS

  • The /fapi/v1/exchangeInfo rateLimits array contains objects related to the exchange’s RAW_REQUEST , REQUEST_WEIGHT , and ORDER rate limits. These are further defined in the ENUM definitions section under Rate limiters (rateLimitType) .
  • A 429 will be returned when either rate limit is violated.

Binance has the right to further tighten the rate limits on users with intent to attack.

IP Limits

  • Every request will contain X-MBX-USED-WEIGHT-(intervalNum)(intervalLetter) in the response headers which has the current used weight for the IP for all request rate limiters defined.
  • Each route has a weight which determines for the number of requests each endpoint counts for. Heavier endpoints and endpoints that do operations on multiple symbols will have a heavier weight .
  • When a 429 is received, it’s your obligation as an API to back off and not spam the API.
  • Repeatedly violating rate limits and/or failing to back off after receiving 429s will result in an automated IP ban (HTTP status 418).
  • IP bans are tracked and scale in duration for repeat offenders, from 2 minutes to 3 days.
  • The limits on the API are based on the IPs, not the API keys.

It is strongly recommended to use websocket stream for getting data as much as possible, which can not only ensure the timeliness of the message, but also reduce the access restriction pressure caused by the request.

Order Rate Limits

  • Every order response will contain a X-MBX-ORDER-COUNT-(intervalNum)(intervalLetter) header which has the current order count for the account for all order rate limiters defined.
  • Rejected/unsuccessful orders are not guaranteed to have X-MBX-ORDER-COUNT-** headers in the response.
  • The order rate limit is counted against each account.

Endpoint Security Type

  • Each endpoint has a security type that determines the how you will interact with it.
  • API-keys are passed into the Rest API via the X-MBX-APIKEY header.
  • API-keys and secret-keys are case sensitive.
  • API-keys can be configured to only access certain types of secure endpoints. For example, one API-key could be used for TRADE only, while another API-key can access everything except for TRADE routes.
  • By default, API-keys can access all secure routes.
Security Type Description
NONE Endpoint can be accessed freely.
TRADE Endpoint requires sending a valid API-Key and signature.
USER_DATA Endpoint requires sending a valid API-Key and signature.
USER_STREAM Endpoint requires sending a valid API-Key.
MARKET_DATA Endpoint requires sending a valid API-Key.
  • TRADE and USER_DATA endpoints are SIGNED endpoints.

SIGNED (TRADE and USER_DATA) Endpoint Security

  • SIGNED endpoints require an additional parameter, signature , to be sent in the query string or request body .
  • Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation.
  • The signature is not case sensitive.
  • Please make sure the signature is the end part of your query string or request body .
  • totalParams is defined as the query string concatenated with the request body .

Timing Security

  • A SIGNED endpoint also requires a parameter, timestamp , to be sent which should be the millisecond timestamp of when the request was created and sent.
  • An additional parameter, recvWindow , may be sent to specify the number of milliseconds after timestamp the request is valid for. If recvWindow is not sent, it defaults to 5000.

Serious trading is about timing. Networks can be unstable and unreliable, which can lead to requests taking varying amounts of time to reach the servers. With recvWindow , you can specify that the request must be processed within a certain number of milliseconds or be rejected by the server.

SIGNED Endpoint Examples for POST /fapi/v1/order

Here is a step-by-step example of how to send a vaild signed payload from the Linux command line using echo , openssl , and curl .

Key Value
apiKey dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83
secretKey 2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9
Parameter Value
symbol BTCUSDT
side BUY
type LIMIT
timeInForce GTC
quantity 1
price 9000
recvWindow 5000
timestamp 1591702613943

Example 1: As a query string

HMAC SHA256 signature:

queryString:

symbol=BTCUSDT
&side=BUY
&type=LIMIT
&timeInForce=GTC
&quantity=1
&price=9000
&recvWindow=5000
&timestamp=1591702613943

Example 2: As a request body

HMAC SHA256 signature:

requestBody:

symbol=BTCUSDT
&side=BUY
&type=LIMIT
&timeInForce=GTC
&quantity=1
&price=9000
&recvWindow=5000
&timestamp=1591702613943

Example 3: Mixed query string and request body

HMAC SHA256 signature:

  • queryString: symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC
  • requestBody: quantity=1&price=9000&recvWindow=5000&timestamp= 1591702613943

Note that the signature is different in example 3.
There is no & between «GTC» and «quantity=1».

Public Endpoints Info

Terminology

  • base asset refers to the asset that is the quantity of a symbol.
  • quote asset refers to the asset that is the price of a symbol.

ENUM definitions

Symbol type:

Contract type (contractType):

  • PERPETUAL
  • CURRENT_MONTH
  • NEXT_MONTH
  • CURRENT_QUARTER 当季交割合约
  • NEXT_QUARTER 次季交割合约

Contract status(contractStatus,status):

  • PENDING_TRADING
  • TRADING
  • PRE_DELIVERING
  • DELIVERING
  • DELIVERED
  • PRE_SETTLE
  • SETTLING
  • CLOSE

Order status (status):

Order types (orderTypes, type):

  • LIMIT
  • MARKET
  • STOP
  • STOP_MARKET
  • TAKE_PROFIT
  • TAKE_PROFIT_MARKET
  • TRAILING_STOP_MARKET

Order side (side):

Position side (positionSide):

Time in force (timeInForce):

  • GTC — Good Till Cancel
  • IOC — Immediate or Cancel
  • FOK — Fill or Kill
  • GTX — Good Till Crossing (Post Only)

Working Type (workingType)

Response Type (newOrderRespType)

Kline/Candlestick chart intervals:

m -> minutes; h -> hours; d -> days; w -> weeks; M -> months

Rate limiters (rateLimitType)

Rate limit intervals (interval)

Filters

Filters define trading rules on a symbol or an exchange.

Symbol filters

PRICE_FILTER

The PRICE_FILTER defines the price rules for a symbol. There are 3 parts:

  • minPrice defines the minimum price / stopPrice allowed; disabled on minPrice == 0.
  • maxPrice defines the maximum price / stopPrice allowed; disabled on maxPrice == 0.
  • tickSize defines the intervals that a price / stopPrice can be increased/decreased by; disabled on tickSize == 0.

Any of the above variables can be set to 0, which disables that rule in the price filter . In order to pass the price filter , the following must be true for price / stopPrice of the enabled rules:

  • price >= minPrice
  • price maxPrice
  • ( price — minPrice ) % tickSize == 0

LOT_SIZE

The LOT_SIZE filter defines the quantity (aka «lots» in auction terms) rules for a symbol. There are 3 parts:

  • minQty defines the minimum quantity allowed.
  • maxQty defines the maximum quantity allowed.
  • stepSize defines the intervals that a quantity can be increased/decreased by.

In order to pass the lot size , the following must be true for quantity :

  • quantity >= minQty
  • quantity maxQty
  • ( quantity — minQty ) % stepSize == 0

MARKET_LOT_SIZE

The MARKET_LOT_SIZE filter defines the quantity (aka «lots» in auction terms) rules for MARKET orders on a symbol. There are 3 parts:

  • minQty defines the minimum quantity allowed.
  • maxQty defines the maximum quantity allowed.
  • stepSize defines the intervals that a quantity can be increased/decreased by.

In order to pass the market lot size , the following must be true for quantity :

  • quantity >= minQty
  • quantity maxQty
  • ( quantity — minQty ) % stepSize == 0

MAX_NUM_ORDERS

The MAX_NUM_ORDERS filter defines the maximum number of orders an account is allowed to have open on a symbol.

Note that both «algo» orders and normal orders are counted for this filter.

MAX_NUM_ALGO_ORDERS

The MAX_NUM_ALGO_ORDERS filter defines the maximum number of all kinds of algo orders an account is allowed to have open on a symbol.

The algo orders include STOP , STOP_MARKET , TAKE_PROFIT , TAKE_PROFIT_MARKET , and TRAILING_STOP_MARKET orders.

PERCENT_PRICE

The PERCENT_PRICE filter defines valid range for a price based on the mark price.

In order to pass the percent price , the following must be true for price :

  • BUY: price markPrice * multiplierUp
  • SELL: price >= markPrice * multiplierDown

MIN_NOTIONAL

The MIN_NOTIONAL filter defines the minimum notional value allowed for an order on a symbol. An order’s notional value is the price * quantity . Since MARKET orders have no price, the mark price is used.

Postman Collections

There is now a Postman collection containing the API endpoints for quick and easy use.

For more information please refer to this page: Binance API Postman

Market Data Endpoints

Test Connectivity

Test connectivity to the Rest API.

Weight: 1

Parameters: NONE

Check Server Time

Test connectivity to the Rest API and get the current server time.

Weight: 1

Parameters: NONE

Exchange Information

Current exchange trading rules and symbol information

Weight: 1

Parameters: NONE

Order Book

Weight:

Adjusted based on the limit:

Limit Weight
5, 10, 20, 50 2
100 5
500 10
1000 20

Parameters:

Name Type Mandatory Description
symbol STRING YES
limit INT NO Default 500; Valid limits:[5, 10, 20, 50, 100, 500, 1000]

Recent Trades List

Get recent trades

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
limit INT NO Default 500; max 1000.

Old Trades Lookup (MARKET_DATA)

Get older market historical trades.

Weight: 20

Parameters:

Name Type Mandatory Description
symbol STRING YES
limit INT NO Default 500; max 1000.
fromId LONG NO TradeId to fetch from. Default gets most recent trades.

Compressed/Aggregate Trades List

Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.

Weight: 20

Parameters:

Name Type Mandatory Description
symbol STRING YES
fromId LONG NO ID to get aggregate trades from INCLUSIVE.
startTime LONG NO Timestamp in ms to get aggregate trades from INCLUSIVE.
endTime LONG NO Timestamp in ms to get aggregate trades until INCLUSIVE.
limit INT NO Default 500; max 1000.
  • If both startTime and endTime are sent, time between startTime and endTime must be less than 1 hour.
  • If fromId, startTime, and endTime are not sent, the most recent aggregate trades will be returned.

Kline/Candlestick Data

Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.

Weight: based on parameter LIMIT

LIMIT weight
[1,100) 1
[100, 500) 2
[500, 1000] 5
> 1000 10

Parameters:

Name Type Mandatory Description
symbol STRING YES
interval ENUM YES
startTime LONG NO
endTime LONG NO
limit INT NO Default 500; max 1500.
  • If startTime and endTime are not sent, the most recent klines are returned.

Continuous Contract Kline/Candlestick Data

Kline/candlestick bars for a specific contract type.

Klines are uniquely identified by their open time.

Weight: based on parameter LIMIT

LIMIT weight
[1,100) 1
[100, 500) 2
[500, 1000] 5
> 1000 10

Parameters:

Name Type Mandatory Description
pair STRING YES
contractType ENUM YES
interval ENUM YES
startTime LONG NO
endTime LONG NO
limit INT NO Default 500; max 1500.

If startTime and endTime are not sent, the most recent klines are returned.

  • PERPETUAL
  • CURRENT_MONTH
  • NEXT_MONTH
  • CURRENT_QUARTER 当季交割合约
  • NEXT_QUARTER 次季交割合约

Index Price Kline/Candlestick Data

Kline/candlestick bars for the index price of a pair.

Klines are uniquely identified by their open time.

Weight: based on parameter LIMIT

LIMIT weight
[1,100) 1
[100, 500) 2
[500, 1000] 5
> 1000 10

Parameters:

Name Type Mandatory Description
pair STRING YES
interval ENUM YES
startTime LONG NO
endTime LONG NO
limit INT NO Default 500; max 1500.
  • If startTime and endTime are not sent, the most recent klines are returned.

Mark Price Kline/Candlestick Data

Kline/candlestick bars for the mark price of a symbol.

Klines are uniquely identified by their open time.

Weight: based on parameter LIMIT

LIMIT weight
[1,100) 1
[100, 500) 2
[500, 1000] 5
> 1000 10

Parameters:

Name Type Mandatory Description
symbol STRING YES
interval ENUM YES
startTime LONG NO
endTime LONG NO
limit INT NO Default 500; max 1500.
  • If startTime and endTime are not sent, the most recent klines are returned.

Mark Price

OR (when symbol not sent)

Mark Price and Funding Rate

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING NO

Get Funding Rate History

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING NO
startTime LONG NO Timestamp in ms to get funding rate from INCLUSIVE.
endTime LONG NO Timestamp in ms to get funding rate until INCLUSIVE.
limit INT NO Default 100; max 1000
  • If startTime and endTime are not sent, the most recent limit datas are returned.
  • If the number of data between startTime and endTime is larger than limit , return as startTime + limit .
  • In ascending order.

24hr Ticker Price Change Statistics

24 hour rolling window price change statistics.
Careful when accessing this with no symbol.

Weight:
1 for a single symbol;
40 when the symbol parameter is omitted

Parameters:

Name Type Mandatory Description
symbol STRING NO
  • If the symbol is not sent, tickers for all symbols will be returned in an array.

Symbol Price Ticker

Latest price for a symbol or symbols.

Weight:
1 for a single symbol;
2 when the symbol parameter is omitted

Parameters:

Name Type Mandatory Description
symbol STRING NO
  • If the symbol is not sent, prices for all symbols will be returned in an array.

Symbol Order Book Ticker

Best price/qty on the order book for a symbol or symbols.

Weight:
1 for a single symbol;
2 when the symbol parameter is omitted

Parameters:

Name Type Mandatory Description
symbol STRING NO
  • If the symbol is not sent, bookTickers for all symbols will be returned in an array.

Open Interest

Get present open interest of a specific symbol.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES

Open Interest Statistics

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
period ENUM YES «5m»,»15m»,»30m»,»1h»,»2h»,»4h»,»6h»,»12h»,»1d»
limit LONG NO default 30, max 500
startTime LONG NO
endTime LONG NO
  • If startTime and endTime are not sent, the most recent data is returned.
  • Only the data of the latest 30 days is available.

Top Trader Long/Short Ratio (Accounts) (MARKET_DATA)

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
period ENUM YES «5m»,»15m»,»30m»,»1h»,»2h»,»4h»,»6h»,»12h»,»1d»
limit LONG NO default 30, max 500
startTime LONG NO
endTime LONG NO
  • If startTime and endTime are not sent, the most recent data is returned.
  • Only the data of the latest 30 days is available.

Top Trader Long/Short Ratio (Positions)

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
period ENUM YES «5m»,»15m»,»30m»,»1h»,»2h»,»4h»,»6h»,»12h»,»1d»
limit LONG NO default 30, max 500
startTime LONG NO
endTime LONG NO
  • If startTime and endTime are not sent, the most recent data is returned.
  • Only the data of the latest 30 days is available.

Long/Short Ratio

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
period ENUM YES «5m»,»15m»,»30m»,»1h»,»2h»,»4h»,»6h»,»12h»,»1d»
limit LONG NO default 30, max 500
startTime LONG NO
endTime LONG NO
  • If startTime and endTime are not sent, the most recent data is returned.
  • Only the data of the latest 30 days is available.

Taker Buy/Sell Volume

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
period ENUM YES «5m»,»15m»,»30m»,»1h»,»2h»,»4h»,»6h»,»12h»,»1d»
limit LONG NO default 30, max 500
startTime LONG NO
endTime LONG NO
  • If startTime and endTime are not sent, the most recent data is returned.
  • Only the data of the latest 30 days is available.

Historical BLVT NAV Kline/Candlestick

The BLVT NAV system is based on Binance Futures, so the endpoint is based on fapi

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES token name, e.g. «BTCDOWN», «BTCUP»
interval ENUM YES
startTime LONG NO
endTime LONG NO
limit INT NO default 500, max 1000

Composite Index Symbol Information

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING NO
  • Only for composite index symbols

Websocket Market Streams

  • The baseurl for websocket is wss://fstream.binance.com
  • Streams can be access either in a single raw stream or a combined stream
  • Raw streams are accessed at /ws/
  • Combined streams are accessed at /stream?streams= / /
  • Combined stream events are wrapped as follows:
  • All symbols for streams are lowercase
  • A single connection is only valid for 24 hours; expect to be disconnected at the 24 hour mark
  • The websocket server will send a ping frame every 5 minutes. If the websocket server does not receive a pong frame back from the connection within a 15 minute period, the connection will be disconnected. Unsolicited pong frames are allowed.
  • WebSocket connections have a limit of 10 incoming messages per second.
  • A connection that goes beyond the limit will be disconnected; IPs that are repeatedly disconnected may be banned.
  • A single connection can listen to a maximum of 200 streams.
  • Considering the possible data latency from RESTful endpoints during an extremely volatile market, it is highly recommended to get the order status, position, etc from the Websocket user data stream.

Live Subscribing/Unsubscribing to streams

  • The following data can be sent through the websocket instance in order to subscribe/unsubscribe from streams. Examples can be seen below.
  • The id used in the JSON payloads is an unsigned INT used as an identifier to uniquely identify the messages going back and forth.

Subscribe to a stream

Request

Unsubscribe to a stream

Listing Subscriptions

<
«method»: «LIST_SUBSCRIPTIONS»,
«id»: 3
>

Setting Properties

Currently, the only property can be set is to set whether combined stream payloads are enabled are not. The combined property is set to false when connecting using /ws/ («raw streams») and true when connecting using /stream/ .

Retrieving Properties

Error Messages

Error Message Description
Parameter used in the SET_PROPERTY or GET_PROPERTY was invalid
Value should only be true or false
Property name provided was invalid
Parameter id had to be provided or the value provided in the id parameter is an unsupported type
Possible typo in the provided method or provided method was neither of the expected values
Unnecessary parameters provided in the data
Property name was not provided
method was not provided in the data
JSON data sent has incorrect syntax.

Aggregate Trade Streams

The Aggregate Trade Streams push trade information that is aggregated for a single taker order every 100 milliseconds.

Stream Name:
@aggTrade

Update Speed: 100ms

Mark Price Stream

Mark price and funding rate for a single symbol pushed every 3 seconds or every second.

Stream Name:
@markPrice or @markPrice@1s

Update Speed: 3000ms or 1000ms

Mark Price Stream for All market

Mark price and funding rate for all symbols pushed every 3 seconds or every second.

Stream Name:
!markPrice@arr or !markPrice@arr@1s

Update Speed: 3000ms or 1000ms

Kline/Candlestick Streams

The Kline/Candlestick Stream push updates to the current klines/candlestick every 250 milliseconds (if existing).

Kline/Candlestick chart intervals:

m -> minutes; h -> hours; d -> days; w -> weeks; M -> months

Stream Name:
@kline_

Update Speed: 250ms

Continuous Contract Kline/Candlestick Streams

Contract type:

  • perpetual
  • current_quarter
  • next_quarter

Kline/Candlestick chart intervals:

m -> minutes; h -> hours; d -> days; w -> weeks; M -> months

Stream Name:

Update Speed: 250ms

Individual Symbol Mini Ticker Stream

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.

Stream Name:
@miniTicker

Update Speed: 500ms

All Market Mini Tickers Stream

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.

Stream Name:
!miniTicker@arr

Update Speed: 1000ms

Individual Symbol Ticker Streams

24hr rollwing 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.

Stream Name:
@ticker

Update Speed: 500ms

All Market Tickers Streams

24hr rollwing 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.

Stream Name:
!ticker@arr

Update Speed: 1000ms

Individual Symbol Book Ticker Streams

Pushes any update to the best bid or ask’s price or quantity in real-time for a specified symbol.

Stream Name: @bookTicker

Update Speed: Real-time

All Book Tickers Stream

Pushes any update to the best bid or ask’s price or quantity in real-time for all symbols.

Stream Name: !bookTicker

Update Speed: Real-time

Liquidation Order Streams

The Liquidation Order Snapshot Streams push force liquidation order information for specific symbol.

For each symbol,only the latest one liquidation order within 1000ms will be pushed as the snapshot. If no liquidation happens in the interval of 1000ms, no stream will be pushed.

Stream Name: @forceOrder

Update Speed: 1000ms

All Market Liquidation Order Streams

The All Liquidation Order Snapshot Streams push force liquidation order information for all symbols in the market.

For each symbol,only the latest one liquidation order within 1000ms will be pushed as the snapshot. If no liquidation happens in the interval of 1000ms, no stream will be pushed.

Stream Name: !forceOrder@arr

Update Speed: 1000ms

Partial Book Depth Streams

Top bids and asks, Valid are 5, 10, or 20.

Stream Names: @depth OR @depth @500ms OR @depth @100ms .

Update Speed: 250ms, 500ms or 100ms

Diff. Book Depth Streams

Bids and asks, pushed every 250 milliseconds, 500 milliseconds, 100 milliseconds (if existing)

Stream Name:
@depth OR @depth@500ms OR @depth@100ms

Update Speed: 250ms, 500ms, 100ms

How to manage a local order book correctly

  1. Open a stream to wss://fstream.binance.com/stream?streams=btcusdt@depth.
  2. Buffer the events you receive from the stream. For same price, latest received update covers the previous one.
  3. Get a depth snapshot from https://fapi.binance.com/fapi/v1/depth?symbol=BTCUSDT&limit=1000 .
  4. Drop any event where u is lastUpdateId in the snapshot.
  5. The first processed event should have U lastUpdateId AND u >= lastUpdateId
  6. While listening to the stream, each new event’s pu should be equal to the previous event’s u , otherwise initialize the process from step 3.
  7. The data in each event is the absolute quantity for a price level.
  8. If the quantity is 0, remove the price level.
  9. Receiving an event that removes a price level that is not in your local order book can happen and is normal.

BLVT Info Streams

Stream Name: @tokenNav

  • Note: tokenName must be uppercase, e.g. «TRXDOWN»

BLVT NAV Kline/Candlestick Streams

Stream Name: @nav_Kline_

  • Note: tokenName must be uppercase, e.g. «TRXDOWN»

Update Speed: 300ms

Kline/Candlestick chart intervals:

m -> minutes; h -> hours; d -> days; w -> weeks; M -> months

Composite Index Symbol Information Streams

Composite index information for index symbols pushed every second.

Stream Name: @compositeIndex

Update Speed: 1000ms

Account/Trades Endpoints

New Future Account Transfer

Please find details from here.

Get Future Account Transaction History List (USER_DATA)

Please find details from here.

Change Position Mode(TRADE)

POST /fapi/v1/positionSide/dual (HMAC SHA256)

Change user’s position mode (Hedge Mode or One-way Mode ) on EVERY symbol

Weight: 1

Parameters:

Name Type Mandatory Description
dualSidePosition STRING YES «true»: Hedge Mode; «false»: One-way Mode
recvWindow LONG NO
timestamp LONG YES

Get Current Position Mode(USER_DATA)

GET /fapi/v1/positionSide/dual (HMAC SHA256)

Get user’s position mode (Hedge Mode or One-way Mode ) on EVERY symbol

Weight: 30

Parameters:

Name Type Mandatory Description
recvWindow LONG NO
timestamp LONG YES

Change Multi-Assets Mode (TRADE)

POST /fapi/v1/multiAssetsMargin (HMAC SHA256)

Change user’s Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on Every symbol

Weight: 1

Parameters:

Name Type Mandatory Description
multiAssetsMargin STRING YES «true»: Multi-Assets Mode; «false»: Single-Asset Mode
recvWindow LONG NO
timestamp LONG YES

Get Current Multi-Assets Mode (USER_DATA)

GET /fapi/v1/multiAssetsMargin (HMAC SHA256)

Get user’s Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on Every symbol

Weight: 30

Parameters:

Name Type Mandatory Description
recvWindow LONG NO
timestamp LONG YES

New Order (TRADE)

POST /fapi/v1/order (HMAC SHA256)

Send in a new order.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES
side ENUM YES
positionSide ENUM NO Default BOTH for One-way Mode ; LONG or SHORT for Hedge Mode. It must be sent in Hedge Mode.
type ENUM YES
timeInForce ENUM NO
quantity DECIMAL NO Cannot be sent with closePosition = true (Close-All)
reduceOnly STRING NO «true» or «false». default «false». Cannot be sent in Hedge Mode; cannot be sent with closePosition = true
price DECIMAL NO
newClientOrderId STRING NO A unique id among open orders. Automatically generated if not sent. Can only be string following the rule: ^[\.A-Z\:/a-z0-9_-]<1,36>$
stopPrice DECIMAL NO Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders.
closePosition STRING NO true , false ;Close-All,used with STOP_MARKET or TAKE_PROFIT_MARKET .
activationPrice DECIMAL NO Used with TRAILING_STOP_MARKET orders, default as the latest price(supporting different workingType )
callbackRate DECIMAL NO Used with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1%
workingType ENUM NO stopPrice triggered by: «MARK_PRICE», «CONTRACT_PRICE». Default «CONTRACT_PRICE»
priceProtect STRING NO «TRUE» or «FALSE», default «FALSE». Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders.
newOrderRespType ENUM NO «ACK», «RESULT», default «ACK»
recvWindow LONG NO
timestamp LONG YES

Additional mandatory parameters based on type :

Type Additional mandatory parameters
LIMIT timeInForce , quantity , price
MARKET quantity
STOP/TAKE_PROFIT quantity , price , stopPrice
STOP_MARKET/TAKE_PROFIT_MARKET stopPrice
TRAILING_STOP_MARKET callbackRate
  • Order with type STOP , parameter timeInForce can be sent ( default GTC ).
  • Order with type TAKE_PROFIT , parameter timeInForce can be sent ( default GTC ).

Condition orders will be triggered when:

  • If parameter priceProtect is sent as true:
    • when price reaches the stopPrice ,the difference rate between «MARK_PRICE» and «CONTRACT_PRICE» cannot be larger than the «triggerProtect» of the symbol
    • «triggerProtect» of a symbol can be got from GET /fapi/v1/exchangeInfo
  • STOP , STOP_MARKET :
    • BUY: latest price («MARK_PRICE» or «CONTRACT_PRICE») >= stopPrice
    • SELL: latest price («MARK_PRICE» or «CONTRACT_PRICE») stopPrice
  • TAKE_PROFIT , TAKE_PROFIT_MARKET :
    • BUY: latest price («MARK_PRICE» or «CONTRACT_PRICE») stopPrice
    • SELL: latest price («MARK_PRICE» or «CONTRACT_PRICE») >= stopPrice
  • TRAILING_STOP_MARKET :
    • BUY: the lowest price after order placed activationPrice , and the latest price >= the lowest price * (1 + callbackRate )
    • SELL: the highest price after order placed >= activationPrice , and the latest price callbackRate )

For TRAILING_STOP_MARKET , if you got such error code.
<"code": -2021, "msg": "Order would immediately trigger.">
means that the parameters you send do not meet the following requirements:

  • BUY: activationPrice should be smaller than latest price.
  • SELL: activationPrice should be larger than latest price.

If newOrderRespType is sent as RESULT :

  • MARKET order: the final FILLED result of the order will be return directly.
  • LIMIT order with special timeInForce : the final status result of the order(FILLED or EXPIRED) will be returned directly.

STOP_MARKET , TAKE_PROFIT_MARKET with closePosition = true :

  • Follow the same rules for condition orders.
  • If triggered,close all current long position( if SELL ) or current short position( if BUY ).
  • Cannot be used with quantity paremeter
  • Cannot be used with reduceOnly parameter
  • In Hedge Mode,cannot be used with BUY orders in LONG position side. and cannot be used with SELL orders in SHORT position side

Place Multiple Orders (TRADE)

POST /fapi/v1/batchOrders (HMAC SHA256)

Weight: 5

Parameters:

Name Type Mandatory Description
batchOrders LIST YES order list. Max 5 orders
recvWindow LONG NO
timestamp LONG YES

Where batchOrders is the list of order parameters in JSON

Name Type Mandatory Description
symbol STRING YES
side ENUM YES
positionSide ENUM NO Default BOTH for One-way Mode ; LONG or SHORT for Hedge Mode. It must be sent with Hedge Mode.
type ENUM YES
timeInForce ENUM NO
quantity DECIMAL YES
reduceOnly STRING NO «true» or «false». default «false».
price DECIMAL NO
newClientOrderId STRING NO A unique id among open orders. Automatically generated if not sent. Can only be string following the rule: ^[\.A-Z\:/a-z0-9_-]<1,36>$
stopPrice DECIMAL NO Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders.
activationPrice DECIMAL NO Used with TRAILING_STOP_MARKET orders, default as the latest price(supporting different workingType )
callbackRate DECIMAL NO Used with TRAILING_STOP_MARKET orders, min 0.1, max 4 where 1 for 1%
workingType ENUM NO stopPrice triggered by: «MARK_PRICE», «CONTRACT_PRICE». Default «CONTRACT_PRICE»
priceProtect STRING NO «TRUE» or «FALSE», default «FALSE». Used with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders.
newOrderRespType ENUM NO «ACK», «RESULT», default «ACK»
  • Paremeter rules are same with New Order
  • Batch orders are processed concurrently, and the order of matching is not guaranteed.
  • The order of returned contents for batch orders is the same as the order of the order list.

Query Order (USER_DATA)

GET /fapi/v1/order (HMAC SHA256)

Check an order’s status.

Weight: 1

  • These orders will not be found:
    • order status is CANCELED or EXPIRED , AND
    • order has NO filled trade, AND
    • created time + 7 days orderId or origClientOrderId must be sent.

    Cancel Order (TRADE)

    DELETE /fapi/v1/order (HMAC SHA256)

    Cancel an active order.

    Weight: 1

    Parameters:

    Name Type Mandatory Description
    symbol STRING YES
    orderId LONG NO
    origClientOrderId STRING NO
    recvWindow LONG NO
    timestamp LONG YES

    Either orderId or origClientOrderId must be sent.

    Cancel All Open Orders (TRADE)

    DELETE /fapi/v1/allOpenOrders (HMAC SHA256)

    Weight: 1

    Parameters:

    Name Type Mandatory Description
    symbol STRING YES
    recvWindow LONG NO
    timestamp LONG YES

    Cancel Multiple Orders (TRADE)

    DELETE /fapi/v1/batchOrders (HMAC SHA256)

    Weight: 1

    Parameters:

    Name Type Mandatory Description
    symbol STRING YES
    orderIdList LIST NO max length 10
    e.g. [1234567,2345678]
    origClientOrderIdList LIST NO max length 10
    e.g. [«my_id_1″,»my_id_2»], encode the double quotes. No space after comma.
    recvWindow LONG NO
    timestamp LONG YES

    Either orderIdList or origClientOrderIdList must be sent.

    Auto-Cancel All Open Orders (TRADE)

    Cancel all open orders of the specified symbol at the end of the specified countdown.

    POST /fapi/v1/countdownCancelAll (HMAC SHA256)

    Weight: 10

    Parameters:

    Name Type Mandatory Description
    symbol STRING YES
    countdownTime LONG YES countdown time, 1000 for 1 second. 0 to cancel the timer
    recvWindow LONG NO
    timestamp LONG YES

    The endpoint should be called repeatedly as heartbeats so that the existing countdown time can be canceled and replaced by a new one.

    Example usage:
    Call this endpoint at 30s intervals with an countdownTime of 120000 (120s).
    If this endpoint is not called within 120 seconds, all your orders of the specified symbol will be automatically canceled.
    If this endpoint is called with an countdownTime of 0, the countdown timer will be stopped.

    The system will check all countdowns approximately every 10 milliseconds, so please note that sufficient redundancy should be considered when using this function. We do not recommend setting the countdown time to be too precise or too small.

    Query Current Open Order (USER_DATA)

    GET /fapi/v1/openOrder (HMAC SHA256)

    Weight: 1

    Parameters:

    Name Type Mandatory Description
    symbol STRING YES
    orderId LONG NO
    origClientOrderId STRING NO
    recvWindow LONG NO
    timestamp LONG YES
    • Either orderId or origClientOrderId must be sent
    • If the queried order has been filled or cancelled, the error message «Order does not exist» will be returned.

    Current All Open Orders (USER_DATA)

    GET /fapi/v1/openOrders (HMAC SHA256)

    Get all open orders on a symbol. Careful when accessing this with no symbol.

    Weight: 1 for a single symbol; 40 when the symbol parameter is omitted

    Parameters:

    Name Type Mandatory Description
    symbol STRING NO
    recvWindow LONG NO
    timestamp LONG YES
    • If the symbol is not sent, orders for all symbols will be returned in an array.

    All Orders (USER_DATA)

    GET /fapi/v1/allOrders (HMAC SHA256)

    Get all account orders; active, canceled, or filled.

    • These orders will not be found:
      • order status is CANCELED or EXPIRED , AND
      • order has NO filled trade, AND
      • created time + 7 days orderId is set, it will get orders >= that orderId . Otherwise most recent orders are returned.
      • The query time period must be less then 7 days( default as the recent 7 days).

      Futures Account Balance V2 (USER_DATA)

      GET /fapi/v2/balance (HMAC SHA256)

      Weight: 5

      Parameters:

      Name Type Mandatory Description
      recvWindow LONG NO
      timestamp LONG YES

      Account Information V2 (USER_DATA)

      GET /fapi/v2/account (HMAC SHA256)

      Get current account information.

      Weight: 5

      Parameters:

      Name Type Mandatory Description
      recvWindow LONG NO
      timestamp LONG YES

      Change Initial Leverage (TRADE)

      POST /fapi/v1/leverage (HMAC SHA256)

      Change user’s initial leverage of specific symbol market.

      Weight: 1

      Parameters:

      Name Type Mandatory Description
      symbol STRING YES
      leverage INT YES target initial leverage: int from 1 to 125
      recvWindow LONG NO
      timestamp LONG YES

      Change Margin Type (TRADE)

      POST /fapi/v1/marginType (HMAC SHA256)

      Weight: 1

      Parameters:

      Name Type Mandatory Description
      symbol STRING YES
      marginType ENUM YES ISOLATED, CROSSED
      recvWindow LONG NO
      timestamp LONG YES

      Modify Isolated Position Margin (TRADE)

      POST /fapi/v1/positionMargin (HMAC SHA256)

      Weight: 1

      Parameters:

      Name Type Mandatory Description
      symbol STRING YES
      positionSide ENUM NO Default BOTH for One-way Mode ; LONG or SHORT for Hedge Mode. It must be sent with Hedge Mode.
      amount DECIMAL YES
      type INT YES 1: Add position margin,2: Reduce position margin
      recvWindow LONG NO
      timestamp LONG YES
      • Only for isolated symbol

      Get Position Margin Change History (TRADE)

      GET /fapi/v1/positionMargin/history (HMAC SHA256)

      Weight: 1

      Parameters:

      Name Type Mandatory Description
      symbol STRING YES
      type INT NO 1: Add position margin,2: Reduce position margin
      startTime LONG NO
      endTime LONG NO
      limit INT NO Default: 500
      recvWindow LONG NO
      timestamp LONG YES

      Position Information V2 (USER_DATA)

      For One-way position mode:

      GET /fapi/v2/positionRisk (HMAC SHA256)

      Get current position information.

      Weight: 5

      Parameters:

      Name Type Mandatory Description
      symbol STRING NO
      recvWindow LONG NO
      timestamp LONG YES

      Note
      Please use with user data stream ACCOUNT_UPDATE to meet your timeliness and accuracy needs.

      Account Trade List (USER_DATA)

      GET /fapi/v1/userTrades (HMAC SHA256)

      Get trades for a specific account and symbol.

      Weight: 5

      Parameters:

      Name Type Mandatory Description
      symbol STRING YES
      startTime LONG NO
      endTime LONG NO
      fromId LONG NO Trade id to fetch from. Default gets most recent trades.
      limit INT NO Default 500; max 1000.
      recvWindow LONG NO
      timestamp LONG YES
      • The time between startTime and endTime cannot be longer than 7 days.
      • The parameter fromId cannot be sent with startTime or endTime .

      Get Income History(USER_DATA)

      GET /fapi/v1/income (HMAC SHA256)

      Weight: 30

      Parameters:

      Name Type Mandatory Description
      symbol STRING NO
      incomeType STRING NO «TRANSFER»,»WELCOME_BONUS», «REALIZED_PNL»,»FUNDING_FEE», «COMMISSION» and «INSURANCE_CLEAR»
      startTime LONG NO Timestamp in ms to get funding from INCLUSIVE.
      endTime LONG NO Timestamp in ms to get funding until INCLUSIVE.
      limit INT NO Default 100; max 1000
      recvWindow LONG NO
      timestamp LONG YES
      • If neither startTime nor endTime is sent, the recent 7-day data will be returned.
      • If incomeType is not sent, all kinds of flow will be returned
      • «trandId» is unique in the same incomeType for a user

      Notional and Leverage Brackets (USER_DATA)

      Weight: 1

      Parameters:

      Name Type Mandatory Description
      symbol STRING NO
      recvWindow LONG NO
      timestamp LONG YES

      Position ADL Quantile Estimation (USER_DATA)

      Weight: 5

      Parameters:

      Name Type Mandatory Description
      symbol STRING NO
      recvWindow LONG NO
      timestamp LONG YES

      Values update every 30s.

      Values 0, 1, 2, 3, 4 shows the queue position and possibility of ADL from low to high.

      For positions of the symbol are in One-way Mode or isolated margined in Hedge Mode, «LONG», «SHORT», and «BOTH» will be returned to show the positions’ adl quantiles of different position sides.

      If the positions of the symbol are crossed margined in Hedge Mode:

      • «HEDGE» as a sign will be returned instead of «BOTH»;
      • A same value caculated on unrealized pnls on long and short sides’ positions will be shown for «LONG» and «SHORT» when there are positions in both of long and short sides.

    User’s Force Orders (USER_DATA)

    Weight: 20 with symbol, 50 without symbol

    Parameters:

    Name Type Mandatory Description
    symbol STRING NO
    autoCloseType ENUM NO «LIQUIDATION» for liquidation orders, «ADL» for ADL orders.
    startTime LONG NO
    endTime LONG NO
    limit INT NO Default 50; max 100.
    recvWindow LONG NO
    timestamp LONG YES
    • If «autoCloseType» is not sent, orders with both of the types will be returned
    • If «startTime» is not sent, data within 7 days before «endTime» can be queried

    User API Trading Quantitative Rules Indicators (USER_DATA)

    • For more information on this, please refer to the Futures API Trading Quantitative Rules

    Weight:

    • 1 for a single symbol
    • 10 when the symbol parameter is omitted

    Parameters:

    Name Type Mandatory Description
    symbol STRING NO
    recvWindow LONG NO
    timestamp LONG YES

    User Commission Rate (USER_DATA)

    GET /fapi/v1/commissionRate (HMAC SHA256)

    Weight: 20

    Parameters:

    Name Type Mandatory Description
    symbol STRING YES
    recvWindow LONG NO
    timestamp LONG YES

    User Data Streams

    • The base API endpoint is: https://fapi.binance.com
    • A User Data Stream listenKey is valid for 60 minutes after creation.
    • Doing a PUT on a listenKey will extend its validity for 60 minutes.
    • Doing a DELETE on a listenKey will close the stream and invalidate the listenKey .
    • Doing a POST on an account with an active listenKey will return the currently active listenKey and extend its validity for 60 minutes.
    • The baseurl for websocket is wss://fstream.binance.com
    • User Data Streams are accessed at /ws/
    • User data stream payloads are not guaranteed to be in order during heavy periods; make sure to order your updates using E
    • A single connection to fstream.binance.com is only valid for 24 hours; expect to be disconnected at the 24 hour mark

    Start User Data Stream (USER_STREAM)

    Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent. If the account has an active listenKey , that listenKey will be returned and its validity will be extended for 60 minutes.

    Weight: 1

    Parameters:

    Keepalive User Data Stream (USER_STREAM)

    Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It’s recommended to send a ping about every 60 minutes.

    Weight: 1

    Parameters:

    Close User Data Stream (USER_STREAM)

    Close out a user data stream.

    Weight: 1

    Parameters:

    Event: User Data Stream Expired

    When the listenKey used for the user data stream turns expired, this event will be pushed.

    Notice:

    • This event is not related to the websocket disconnection.
    • This event will be received only when a valid listenKey in connection got expired.
    • No more user data event will be updated after this event received until a new valid listenKey used.

    Event: 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.

    Event: Balance and Position Update

    Event type is ACCOUNT_UPDATE .

    When balance or position get updated, this event will be pushed.

    • ACCOUNT_UPDATE will be pushed only when update happens on user’s account, including changes on balances, positions, or margin type.
    • Unfilled orders or cancelled orders will not make the event ACCOUNT_UPDATE pushed, since there’s no change on positions.
    • Only positions of symbols with non-zero isolatd wallet or non-zero position amount will be pushed in the «position» part of the event ACCOUNT_UPDATE when any position changes.

    When «FUNDING FEE» changes to the user’s balance, the event will be pushed with the brief message:

    • When «FUNDING FEE» occurs in a crossed position, ACCOUNT_UPDATE will be pushed with only the balance B (including the «FUNDING FEE» asset only), without any position P message.
    • When «FUNDING FEE» occurs in an isolated position, ACCOUNT_UPDATE will be pushed with only the balance B (including the «FUNDING FEE» asset only) and the relative position message P ( including the isolated position on which the «FUNDING FEE» occurs only, without any other position message).

    The field «m» represents the reason type for the event and may shows the following possible types:

    • DEPOSIT
    • WITHDRAW
    • ORDER
    • FUNDING_FEE
    • WITHDRAW_REJECT
    • ADJUSTMENT
    • INSURANCE_CLEAR
    • ADMIN_DEPOSIT
    • ADMIN_WITHDRAW
    • MARGIN_TRANSFER
    • MARGIN_TYPE_CHANGE
    • ASSET_TRANSFER
    • OPTIONS_PREMIUM_FEE
    • OPTIONS_SETTLE_PROFIT
    • AUTO_EXCHANGE

    The field «bc» represents the balance change except for PnL and commission.

    Event: Order Update

    When new order created, order status changed will push such event. event type is ORDER_TRADE_UPDATE .

    Side

    Order Type

    Execution Type

    • NEW
    • CANCELED
    • CALCULATED — Liquidation Execution
    • EXPIRED
    • TRADE

    Order Status

    • NEW
    • PARTIALLY_FILLED
    • FILLED
    • CANCELED
    • EXPIRED
    • NEW_INSURANCE — Liquidation with Insurance Fund
    • NEW_ADL — Counterparty Liquidation`

    Time in force

    Working Type

    Event: Account Configuration Update previous Leverage Update

    When the account configuration is changed, the event type will be pushed as ACCOUNT_CONFIG_UPDATE

    When the leverage of a trade pair changes, the payload will contain the object ac to represent the account configuration of the trade pair, where s represents the specific trade pair and l represents the leverage

    When the user Multi-Assets margin mode changes the payload will contain the object ai representing the user account configuration, where j represents the user Multi-Assets margin mode

    Error Codes

    Here is the error JSON payload:

    Errors consist of two parts: an error code and a message.
    Codes are universal,but messages can vary.

    Источник

    Читайте также:  Модель оценки доходности долгосрочных активов сарм увязывает тест
Оцените статью