Skip to content

COIN M Futures

andrea-c-binance edited this page Dec 9, 2021 · 4 revisions

binance.delivery package

binance.delivery.account module


binance.delivery.account.account(self, **kwargs)

Account Information (USER_DATA)

Get current account information

API endpoint

GET /dapi/v1/account

API doc

https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data

Parameters

  • recvWindow – optional int

Notes

  • For One-way Mode user, the “positions” will only show the “BOTH” positions
  • For Hedge Mode user, the “positions” will show “BOTH”, “LONG”, and “SHORT” positions.

binance.delivery.account.adl_quantile(self, **kwargs)

Position ADL Quantile Estimation (USER_DATA)

Get Position ADL Quantile Estimation

API endpoint

GET /dapi/v1/adlQuantile

API doc

https://binance-docs.github.io/apidocs/delivery/en/#position-adl-quantile-estimation-user_data

Parameters

  • symbol – optional string

  • recvWindow – optional int

Notes

  • 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.


binance.delivery.account.balance(self, **kwargs)

Futures Account Balance (USER_DATA)

Get current account balance

API endpoint

GET /dapi/v1/balance

API doc

https://binance-docs.github.io/apidocs/delivery/en/#futures-account-balance-user_data

Parameters

  • recvWindow – optional int

binance.delivery.account.cancel_batch_order(self, symbol: str, orderIdList: list, origClientOrderIdList: list, **kwargs)

Cancel Multiple Orders (TRADE)

Cancel a new batch order

API endpoint

DELETE /dapi/v1/batchOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#cancel-multiple-orders-trade

Parameters

  • symbol – string

  • orderIdList – int list, max length 10 e.g. [1234567,2345678]

  • origClientOrderIdList – string list, max length 10 e.g. [“my_id_1”,”my_id_2”], encode the double quotes. No space after comma.

  • recvWindow – optional int

Notes

  • Either orderIdList or origClientOrderIdList must be sent.

binance.delivery.account.cancel_open_orders(self, symbol: str, **kwargs)

Cancel All Open Orders (TRADE)

API endpoint

DELETE /dapi/v1/allOpenOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#cancel-all-open-orders-trade

Parameters

  • symbol – string

  • recvWindow – optional int, the value cannot be greater than 60000


binance.delivery.account.cancel_order(self, symbol: str, orderId: Optional[int] = None, origClientOrderId: Optional[str] = None, **kwargs)

Cancel Order (TRADE)

Cancel an active order.

API endpoint

DELETE /dapi/v1/order

API doc

https://binance-docs.github.io/apidocs/delivery/en/#cancel-order-trade

Parameters

  • symbol – string

  • orderId – optional string

  • origClientOrderId – optional string

  • newClientOrderId – optional string

  • recvWindow – optional int


binance.delivery.account.change_leverage(self, symbol: str, leverage: int, **kwargs)

Change Initial Leverage (TRADE)

Change user’s initial leverage in the specific symbol market.

For Hedge Mode, LONG and SHORT positions of one symbol use the same initial leverage and share a total notional value.

API endpoint

POST /dapi/v1/leverage

API doc

https://binance-docs.github.io/apidocs/delivery/en/#change-initial-leverage-trade

Parameters

  • symbol – string

  • leverage – int; target initial leverage: int from 1 to 125

  • recvWindow – optional int


binance.delivery.account.change_margin_type(self, symbol: str, marginType: str, **kwargs)

Change Margin Type (TRADE)

Change user’s margin type in the specific symbol market.For Hedge Mode, LONG and SHORT positions of one symbol use the same margin type.

With ISOLATED margin type, margins of the LONG and SHORT positions are isolated from each other.

API endpoint

POST /dapi/v1/marginType

API doc

https://binance-docs.github.io/apidocs/delivery/en/#change-margin-type-trade

Parameters

  • symbol – string

  • leverage – string; ISOLATED, CROSSED

  • recvWindow – optional int


binance.delivery.account.change_position_mode(self, dualSidePosition: str, **kwargs))

Change Position Mode (TRADE)

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

API endpoint

POST /dapi/v1/positionSide/dual

API doc

https://binance-docs.github.io/apidocs/delivery/en/#change-position-mode-trade

Parameters

  • dualSidePosition – string

  • recvWindow – optional int


binance.delivery.account.commission_rate(self, symbol: str, **kwargs)

User Commission Rate (USER_DATA)

Get commission rate of symbol

API endpoint

GET /dapi/v1/commissionRate

API doc

https://binance-docs.github.io/apidocs/delivery/en/#user-commission-rate-user_data

Parameters

  • symbol – optional string

  • recvWindow – optional int


binance.delivery.account.countdown_cancel_order(self, symbol: str, countdownTime: int, **kwargs)

Auto-Cancel All Open Orders (TRADE)

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

API endpoint

POST /dapi/v1/countdownCancelAll

API doc

https://binance-docs.github.io/apidocs/delivery/en/#auto-cancel-all-open-orders-trade

Parameters

  • symbol – string

  • countdownTime – int list, countdown time, 1000 for 1 second. 0 to cancel the timer

  • recvWindow – optional int

Notes

  • 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.


binance.delivery.account.force_orders(self, **kwargs)

User’s Force Orders (USER_DATA)

Get User’s Force Orders

API endpoint

GET /dapi/v1/forceOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#user-39-s-force-orders-user_data

Parameters

  • symbol – optional string

  • autoCloseType – optional string; “LIQUIDATION” for liquidation orders, “ADL” for ADL orders.

  • startTime – optional string

  • endTime – optional string

  • limit – optional int; default 50, max 100

  • recvWindow – optional int

Notes

  • If “autoCloseType” is not sent, orders with both of the types will be returned

  • If “startTime” is not sent, data within 200 days before “endTime” can be queried


binance.delivery.account.get_account_trades(self, **kwargs)

Account Trade List (USER_DATA)

Get trades for a specific account and symbol.

API endpoint

GET /dapi/v1/userTrades

API doc

https://binance-docs.github.io/apidocs/delivery/en/#account-trade-list-user_data

Parameters

  • symbol – optional string

  • pair – optional string

  • startTime – optional string

  • endTime – optional string

  • fromId – optional int; trade ID to fetch from, default is to get the most recent trades.

  • limit – optional int; default 50, max 100

  • recvWindow – optional int

Notes

  • Either symbol or pair must be sent

  • Symbol and pair cannot be sent together

  • Pair and fromId cannot be sent together

  • If a pair is sent,tickers for all symbols of the pair will be returned

  • The parameter fromId cannot be sent with startTime or endTime


binance.delivery.account.get_all_orders(self, **kwargs)

All Orders (USER_DATA)

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

API endpoint

GET /dapi/v1/allOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#all-orders-user_data

Parameters

  • symbol – string

  • orderId – optional int

  • startTime – optional int

  • endTime – optional int

  • limit – optional int; default 50, max 100.

  • recvWindow – optional int; the value cannot be greater than 60000


binance.delivery.account.get_income_history(self, **kwargs)

Get Income History (USER_DATA)

Get trades for a specific account and symbol.

API endpoint

GET /dapi/v1/income

API doc

https://binance-docs.github.io/apidocs/delivery/en/#get-income-history-user_data

Parameters

  • symbol – optional string

  • incomeType – optional string; “TRANSFER”, “WELCOME_BONUS”, “REALIZED_PNL”, “FUNDING_FEE”, “COMMISSION” and “INSURANCE_CLEAR”

  • startTime – optional string; timestamp in ms to get funding from INCLUSIVE.

  • endTime – optional string; timestamp in ms to get funding from INCLUSIVE.

  • limit – optional int; default 50, max 100

  • recvWindow – optional int

Notes

  • If incomeType is not sent, all kinds of flow will be returned

  • “trandId” is unique in the same incomeType for a user


binance.delivery.account.get_open_orders(self, symbol: str, orderId: Optional[int] = None, origClientOrderId: Optional[str] = None, **kwargs)

Query Current Open Order (USER_DATA)

Get all open orders on a symbol.

API endpoint

GET /dapi/v1/openOrder

API doc

https://binance-docs.github.io/apidocs/delivery/en/#query-current-open-order-user_data

Parameters

  • symbol – string

  • orderId – optional string

  • origClientOrderId – optional string

  • recvWindow – optional int, the value cannot be greater than 60000

Notes

  • 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.


binance.delivery.account.get_orders(self, **kwargs)

Current All Open Orders (USER_DATA)

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

If the symbol is not sent, orders for all symbols will be returned in an array.

API endpoint

GET /dapi/v1/openOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#current-all-open-orders-user_data

Parameters

  • symbol – string

  • recvWindow – optional int, the value cannot be greater than 60000


binance.delivery.account.get_position_margin_history(self, symbol: str, **kwargs)

Get Position Margin Change History (TRADE)

Get position margin history on a symbol.

API endpoint

GET /dapi/v1/positionMargin/history

API doc

https://binance-docs.github.io/apidocs/delivery/en/#get-position-margin-change-history-trade

Parameters

  • symbol – string

  • type – optional int; 1: Add position margin,2: Reduce position margin

  • startTime – optional string

  • endTime – optional string

  • limit – optional int; default 50

  • recvWindow – optional int


binance.delivery.account.get_position_mode(self, **kwargs)

Get Current Position Mode (USER_DATA)

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

API endpoint

GET /dapi/v1/positionSide/dual

API doc

https://binance-docs.github.io/apidocs/delivery/en/#get-current-position-mode-user_data

Parameters

  • recvWindow – optional int

binance.delivery.account.get_position_risk(self, **kwargs)

Position Information (USER_DATA)

Get current position information.

API endpoint

GET /dapi/v1/positionRisk

API doc

https://binance-docs.github.io/apidocs/delivery/en/#position-information-user_data

Parameters

  • symbol – string

  • recvWindow – optional int


binance.delivery.account.leverage_brackets(self, symbol: Optional[str] = None, pair: Optional[str] = None, **kwargs)

Notional and Leverage Brackets (USER_DATA)

Get notional and leverage bracket.

API endpoint

GET /dapi/v1/leverageBracket

API doc

https://binance-docs.github.io/apidocs/delivery/en/#notional-bracket-for-pair-user_data

API endpoint

GET /dapi/v2/leverageBracket

API doc

https://binance-docs.github.io/apidocs/delivery/en/#notional-bracket-for-pair-user_data-2

Parameters

  • symbol – optional string

  • pair – optional string

  • recvWindow – optional int


binance.delivery.account.modify_batch_order(self, batchOrders: list)

Place Multiple Orders (TRADE)

Post a new batch order

API endpoint

PUT /dapi/v1/batchOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#modify-multiple-orders-trade

Parameters

  • batchOrders – list

  • recvWindow – optional int

Notes

  • 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.

    batchOrders (list): order list. Max 5 orders

  • batchOrders is the list of order parameters in JSON


binance.delivery.account.modify_isolated_position_margin(self, symbol: str, amount: float, type: int, **kwargs)

Modify Isolated Position Margin (TRADE)

API endpoint

POST /dapi/v1/positionMargin

API doc

https://binance-docs.github.io/apidocs/delivery/en/#modify-isolated-position-margin-trade

Parameters

  • symbol – string

  • amount – float

  • type – int; 1: Add position margin,2: Reduce position margin

  • positionSide – optional string; default BOTH for One-way Mode, LONG or SHORT for Hedge Mode. It must be sent with Hedge Mode.

  • recvWindow – optional int


binance.delivery.account.modify_order(self, symbol: str, side: str, orderId: Optional[int] = None, origClientOrderId: Optional[str] = None, **kwargs)

Modify Order (TRADE)

Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.

API endpoint

POST /dapi/v1/order

API doc

https://binance-docs.github.io/apidocs/delivery/en/#modify-order-trade

Parameters

  • symbol – string

  • side – string

  • orderId – optional int

  • origClientOrderId – optional string

  • quantity – optional float

  • price – optional float

  • recvWindow – optional int

Notes

  • Either orderId or origClientOrderId must be sent, and the orderId will prevail if both are sent.

  • Either quantity or price must be sent.

  • If the modification will cause the order to be cancelled immediately, the modification request will be rejected, in this case the user can force the modification by sending both quantity and price parameters and let the the order be cancelled immediately. So if you want to ensure the success of the modification request, we strongly recommend sending both quantity and price parameters at the same, for example:

  • When the new order quantity in the modification request is less than the partially filled quantity, if the user only sends quantity then the modification will fail, if the user sends both quantity and price then the modification will be successful and the order will be cancelled immediately.

  • When the new order price in the modification request prevents the GTX order from becoming a pending order (post only), if the user only sends price then the modification will fail, if the user sends both quantity and price then the modification will be successful and the order will be cancelled immediately.


binance.delivery.account.new_batch_order(self, batchOrders: list)

Place Multiple Orders (TRADE)

Post a new batch order

API endpoint

POST /dapi/v1/batchOrders

API doc

https://binance-docs.github.io/apidocs/delivery/en/#place-multiple-orders-trade

Parameters

  • batchOrders – list

  • recvWindow – optional int

Notes

  • 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.

    batchOrders (list): order list. Max 5 orders

  • batchOrders is the list of order parameters in JSON


binance.delivery.account.new_order(self, symbol: str, side: str, type: str, **kwargs)

New Order (TRADE)

Send a new order

API endpoint

POST /dapi/v1/order

API doc

https://binance-docs.github.io/apidocs/delivery/en/#new-order-trade

Parameters

  • symbol – string

  • side – string

  • type – string

  • positionSide – optional string. Default BOTH for One-way Mode; LONG or SHORT for Hedge Mode. It must be passed in Hedge Mode.

  • timeInForce – optional string

  • quantity – optional float

  • reduceOnly – optional string

  • price – optional float

  • newClientOrderId – optional string. An unique ID among open orders. Automatically generated if not sent.

  • stopPrice – optional float. Use with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders.

  • closePosition – optional string. true or false; Close-All, use with STOP_MARKET or TAKE_PROFIT_MARKET.

  • activationPrice – optional float. Use with TRAILING_STOP_MARKET orders, default is the latest price (supporting different workingType).

  • callbackRate – optional float. Use with TRAILING_STOP_MARKET orders, min 0.1, max 5 where 1 for 1%.

  • workingType – optional string. stopPrice triggered by: “MARK_PRICE”, “CONTRACT_PRICE”. Default “CONTRACT_PRICE”.

  • priceProtect – optional string. “TRUE” or “FALSE”, default “FALSE”. Use with STOP/STOP_MARKET or TAKE_PROFIT/TAKE_PROFIT_MARKET orders.

  • newOrderRespType – optional float. “ACK” or “RESULT”, default “ACK”.

  • recvWindow – optional int


binance.delivery.account.order_modify_history(self, symbol: str, orderId: Optional[int] = None, origClientOrderId: Optional[str] = None, **kwargs)

Get Order Modify History (USER_DATA)

Get order modification history

API endpoint

GET /dapi/v1/orderAmendment

API doc

https://binance-docs.github.io/apidocs/delivery/en/#get-order-modify-history-user_data

Parameters

  • symbol – string

  • orderId – optional int

  • origClientOrderId – optional string

  • startTime – optional int; Timestamp in ms to get modification history from INCLUSIVE

  • endTime – optional int; Timestamp in ms to get modification history from INCLUSIVE

  • limit – optional int

  • recvWindow – optional int


binance.delivery.account.query_order(self, symbol: str, orderId: Optional[int] = None, origClientOrderId: Optional[str] = None, **kwargs)

Query Order (USER_DATA)

Query a order

API endpoint

GET /dapi/v1/order

API doc

https://binance-docs.github.io/apidocs/delivery/en/#query-order-user_data

Parameters

  • symbol – string

  • orderId – optional string

  • origClientOrderId – optional string

  • recvWindow – optional int


binance.delivery.data_stream module


binance.delivery.data_stream.close_listen_key(self, listenKey: str)

Close a ListenKey (USER_STREAM)

API endpoint

DELETE /dapi/v1/listenKey

API doc

https://binance-docs.github.io/apidocs/delivery/en/#close-user-data-stream-user_stream

Parameters

  • listenKey – string

binance.delivery.data_stream.new_listen_key(self)

Create a ListenKey (USER_STREAM)

API endpoint

POST /dapi/v1/listenKey

API doc

https://binance-docs.github.io/apidocs/delivery/en/#start-user-data-stream-user_stream


binance.delivery.data_stream.renew_listen_key(self, listenKey: str)

Ping/Keep-alive a ListenKey (USER_STREAM)

API endpoint

PUT /dapi/v1/listenKey

API doc

https://binance-docs.github.io/apidocs/delivery/en/#keepalive-user-data-stream-user_stream

Parameters

  • listenKey – string

binance.delivery.market module


binance.delivery.market.agg_trades(self, symbol: str, **kwargs)

Compressed/Aggregate Trades List

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

API endpoint

GET /dapi/v1/aggTrades

API doc

https://binance-docs.github.io/apidocs/delivery/en/#compressed-aggregate-trades-list

Parameters

  • symbol – string; the trading pair

  • limit – optional int; limit the results. Default 500, max 1000.

  • formId – optional int; trade ID to fetch from. Default gets most recent trades.

  • startTime – optional int; Timestamp in ms to get aggregate trades from INCLUSIVE.

  • endTime – optional int; Timestamp in ms to get aggregate trades until INCLUSIVE.


binance.delivery.market.basis(self, pair: str, contractType: str, period: str, **kwargs)

Get Index Composite

API endpoint

GET /futures/data/basis

API doc

xshttps://binance-docs.github.io/apidocs/delivery/en/#basis-market-data

Parameters

  • pair – string; the trading pair

  • contractType – string; CURRENT_QUARTER, NEXT_QUARTER, PERPETUAL.

  • period – string; the period of open interest, “5m”, “15m”, “30m”, “1h”, “2h”, “4h”, “6h”, “12h”, “1d”. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 30, max 500.

  • startTime – optional int

  • endTime – optional int

Notes

  • If startTime and endTime are not sent, the most recent data is returned.

  • Only the data of the latest 30 days is available.


binance.delivery.market.book_ticker(self, symbol: Optional[str] = None, pair: Optional[str] = None)

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

API endpoint

GET /dapi/v1/ticker/bookTicker

API doc

https://binance-docs.github.io/apidocs/delivery/en/#symbol-order-book-ticker

Parameters

symbol – optional string; the trading symbol

Notes

  • If the symbol is not sent, bookTickers for all symbols will be returned in an array.

binance.delivery.market.continuous_klines(self, pair: str, contractType: str, interval: str, **kwargs)

Continuous Kline/Candlestick Data

Kline/candlestick bars for a specific contract type. Klines are uniquely identified by their open time.

API endpoint

GET /dapi/v1/continuousKlines

API doc

https://binance-docs.github.io/apidocs/delivery/en/#continuous-contract-kline-candlestick-data

Parameters

  • pair – string; the trading pair

  • contractType – string; PERPETUAL, CURRENT_MONTH, NEXT_MONTH, CURRENT_QUARTER, NEXT_QUARTER.

  • interval – string; the interval of kline, e.g 1m, 5m, 1h, 1d, etc. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 500, max 1000.

  • startTime – optional int; Timestamp in ms to get aggregate trades from INCLUSIVE.

  • endTime – optional int; Timestamp in ms to get aggregate trades until INCLUSIVE.


binance.delivery.market.depth(self, symbol: str, **kwargs)

Get Orderbook

API endpoint

GET /dapi/v1/depth

API doc

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

Parameters

  • symbol – string; the trading pair

  • limit – optional int; limit the results. Default 500, valid limits: [5, 10, 20, 50, 100, 500, 1000].


binance.delivery.market.exchange_info(self)

Exchange Information

Current exchange trading rules and symbol information

API endpoint

GET /dapi/v1/exchangeInfo

API doc

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


binance.delivery.market.funding_rate(self, symbol: str, **kwargs)

Funding Rate History

API endpoint

GET /dapi/v1/fundingRate

API doc

https://binance-docs.github.io/apidocs/delivery/en/#get-funding-rate-history-of-perpetual-futures

Parameters

  • symbol – string; the trading pair

  • limit – optional int; limit the results. Default 500, max 1000.

  • startTime – optional int; Timestamp in ms to get aggregate trades from INCLUSIVE.

  • endTime – optional int; Timestamp in ms to get aggregate trades until INCLUSIVE.

Notes

  • Empty array will be returned for delivery symbols.

binance.delivery.market.historical_trades(self, symbol: str, **kwargs)

Old Trade Lookup

Get older market historical trades.

API endpoint

GET /dapi/v1/historicalTrades

API doc

https://binance-docs.github.io/apidocs/delivery/en/#old-trades-lookup-market_data

Parameters

  • symbol – string; the trading pair

  • limit – optional int; limit the results. Default 500, max 1000.

  • formId – optional int; trade ID to fetch from. Default gets most recent trades.


binance.delivery.market.index_price_klines(self, pair: str, interval: str, **kwargs)

Kline/Candlestick Data for the index price of a pair.

Klines are uniquely identified by their open time.

API endpoint

GET /dapi/v1/indexPriceKlines

API doc

https://binance-docs.github.io/apidocs/delivery/en/#index-price-kline-candlestick-data

Parameters

  • pair – string; the trading pair

  • interval – string; the interval of kline, e.g 1m, 5m, 1h, 1d, etc. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 500, max 1000.

  • startTime – optional int; Timestamp in ms to get aggregate trades from INCLUSIVE.

  • endTime – optional int; Timestamp in ms to get aggregate trades until INCLUSIVE.


binance.delivery.market.klines(self, symbol: str, interval: str, **kwargs)

Kline/Candlestick Data

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

API endpoint

GET /dapi/v1/klines

API doc

https://binance-docs.github.io/apidocs/delivery/en/#kline-candlestick-data

Parameters

  • symbol – string; the trading pair

  • interval – string; the interval of kline, e.g 1m, 5m, 1h, 1d, etc. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 500, max 1000.

  • startTime – optional int; Timestamp in ms to get aggregate trades from INCLUSIVE.

  • endTime – optional int; Timestamp in ms to get aggregate trades until INCLUSIVE.


binance.delivery.market.long_short_account_ratio(self, pair: str, period: str, **kwargs)

Get top long short account ratio

API endpoint

GET /futures/data/globalLongShortAccountRatio

API doc

https://binance-docs.github.io/apidocs/delivery/en/#top-trader-long-short-ratio-accounts-market-data

Parameters

  • pair – string; the trading pair

  • period – string; the period of open interest, “5m”, “15m”, “30m”, “1h”, “2h”, “4h”, “6h”, “12h”, “1d”. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 30, max 500.

  • startTime – optional int

  • endTime – optional int

Notes

  • If startTime and endTime are not sent, the most recent data is returned.

  • Only the data of the latest 30 days is available.


binance.delivery.market.mark_price(self, symbol: str)

Mark Price and Funding Rate

API endpoint

GET /dapi/v1/premiumIndex

API doc

https://binance-docs.github.io/apidocs/delivery/en/#index-price-and-mark-price

Parameters

  • symbol – string; the trading pair

binance.delivery.market.mark_price_klines(self, symbol: str, interval: str, **kwargs)

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

Klines are uniquely identified by their open time.

API endpoint

GET /dapi/v1/markPriceKlines

API doc

https://binance-docs.github.io/apidocs/delivery/en/#mark-price-kline-candlestick-data

Parameters

  • pair – string; the trading pair

  • interval – string; the interval of kline, e.g 1m, 5m, 1h, 1d, etc. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 500, max 1000.

  • startTime – optional int; Timestamp in ms to get aggregate trades from INCLUSIVE.

  • endTime – optional int; Timestamp in ms to get aggregate trades until INCLUSIVE.

Notes

  • The difference between startTime and endTime can only be up to 200 days

  • Between startTime and endTime, the most recent limit data from endTime will be returned:

  • If startTime and endTime are not sent, current timestamp will be set as endTime, and the most recent data will be returned.

  • If startTime is sent only, the timestamp of 200 days after startTime will be set as endTime(up to the current time)

  • If endTime is sent only, the timestamp of 200 days before endTime will be set as startTime


binance.delivery.market.open_interest(self, symbol: str)

Get present open interest of a specific symbol

API endpoint

GET /dapi/v1/openInterest

API doc

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

Parameters

  • symbol – string; the trading symbol

binance.delivery.market.open_interest_hist(self, pair: str, contractType: str, period: str, **kwargs)

Get historical open interest of a specific symbol

API endpoint

GET /futures/data/openInterestHist

API doc

https://binance-docs.github.io/apidocs/delivery/en/#open-interest-statistics-market-data

Parameters

  • pair – string; the trading pair

  • contractType – string; ALL, CURRENT_QUARTER, NEXT_QUARTER, PERPETUAL.

  • period – string; the period of open interest, “5m”, “15m”, “30m”, “1h”, “2h”, “4h”, “6h”, “12h”, “1d”. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 30, max 500.

  • startTime – optional int

  • endTime – optional int

Notes

  • If startTime and endTime are not sent, the most recent data is returned.

  • Only the data of the latest 30 days is available.


binance.delivery.market.ping(self)

Test Connectivity

Test connectivity to the Rest API.

API endpoint

GET /dapi/v1/ping

API doc

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


binance.delivery.market.taker_long_short_ratio(self, pair: str, contractType: str, period: str, **kwargs)

Get taker long short ratio

API endpoint

GET /futures/data/takerBuySellVol

API doc

https://binance-docs.github.io/apidocs/delivery/en/#taker-buy-sell-volume-market-data

Parameters

  • pair – string; the trading pair

  • contractType – string; CURRENT_QUARTER, NEXT_QUARTER, PERPETUAL.

  • period – string; the period of open interest, “5m”, “15m”, “30m”, “1h”, “2h”, “4h”, “6h”, “12h”, “1d”. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 30, max 500.

  • startTime – optional int

  • endTime – optional int

Notes

  • If startTime and endTime are not sent, the most recent data is returned.

  • Only the data of the latest 30 days is available.


binance.delivery.market.ticker_24hr_price_change(self, symbol: Optional[str] = None, pair: Optional[str] = None)

24 hour rolling window price change statistics.

Careful when accessing this with no symbol.

If the symbol is not sent, tickers for all symbols will be returned in an array.

API endpoint

GET /dapi/v1/ticker/24hr

API doc

https://binance-docs.github.io/apidocs/delivery/en/#24hr-ticker-price-change-statistics

Parameters

  • symbol – optional string; the trading symbol

  • pair – optional string; the trading pair

Notes

  • Symbol and pair cannot be sent together

  • If a pair is sent, tickers for all symbols of the pair will be returned

  • If either a pair or symbol is sent, tickers for all symbols of all pairs will be returned


binance.delivery.market.ticker_price(self, symbol: Optional[str] = None, pair: Optional[str] = None)

Latest price for a symbol or symbols

API endpoint

GET /dapi/v1/ticker/price

API doc

https://binance-docs.github.io/apidocs/delivery/en/#symbol-price-ticker

Parameters

  • symbol – optional string; the trading symbol

  • pair – optional string; the trading pair

Notes

  • Symbol and pair cannot be sent together

  • If a pair is sent,tickers for all symbols of the pair will be returned

  • If either a pair or symbol is sent, tickers for all symbols of all pairs will be returned


binance.delivery.market.time(self)

Check Server Time

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

API endpoint

GET /dapi/v1/time

API doc

https://binance-docs.github.io/apidocs/delivery/en/#check-server-time


binance.delivery.market.top_long_short_account_ratio(self, pair: str, period: str, **kwargs)

Get top long short account ratio

API endpoint

GET /futures/data/topLongShortAccountRatio

API doc

https://binance-docs.github.io/apidocs/delivery/en/#top-trader-long-short-ratio-accounts-market-data

Parameters

  • pair – string; the trading pair

  • period – string; the period of open interest, “5m”, “15m”, “30m”, “1h”, “2h”, “4h”, “6h”, “12h”, “1d”. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 30, max 500.

  • startTime – optional int

  • endTime – optional int

Notes

  • If startTime and endTime are not sent, the most recent data is returned.

  • Only the data of the latest 30 days is available.


binance.delivery.market.top_long_short_position_ratio(self, pair: str, period: str, **kwargs)

Get top long short position ratio

API endpoint

GET /futures/data/topLongShortPositionRatio

API doc

https://binance-docs.github.io/apidocs/delivery/en/#top-trader-long-short-ratio-positions-market-data

Parameters

  • pair – string; the trading pair

  • period – string; the period of open interest, “5m”, “15m”, “30m”, “1h”, “2h”, “4h”, “6h”, “12h”, “1d”. (see more in https://binance-docs.github.io/apidocs/delivery/en/#public-endpoints-info)

  • limit – optional int; limit the results. Default 30, max 500.

  • startTime – optional int

  • endTime – optional int

Notes

  • If startTime and endTime are not sent, the most recent data is returned.

  • Only the data of the latest 30 days is available.


binance.delivery.market.trades(self, symbol: str, **kwargs)

Get Recent Market Trades

API endpoint

GET /dapi/v1/trades

API doc

https://binance-docs.github.io/apidocs/delivery/en/#recent-trades-list

Parameters

  • symbol – string; the trading pair

  • limit – optional int; limit the results. Default 500, max 1000.



© Copyright 2021, Binance Futures.

Clone this wiki locally