python-binance

BinanceSocketManager

Attributes

attributeSTREAM_URL
= self.STREAM_URL.format(client.tld)
attributeSTREAM_TESTNET_URL
= 'wss://stream.testnet.binance.vision/'
attributeSTREAM_DEMO_URL
= 'wss://demo-stream.binance.com/'
attributeFSTREAM_URL
= self.FSTREAM_URL.format(client.tld)
attributeFSTREAM_TESTNET_URL
= 'wss://stream.binancefuture.com/'
attributeFSTREAM_DEMO_URL
= 'wss://fstream.binancefuture.com/'
attributeDSTREAM_URL
= self.DSTREAM_URL.format(client.tld)
attributeDSTREAM_TESTNET_URL
= 'wss://dstream.binancefuture.com/'
attributeDSTREAM_DEMO_URL
= 'wss://dstream.binancefuture.com/'
attributeOPTIONS_URL
= self.OPTIONS_URL.format(client.tld)
attributeWEBSOCKET_DEPTH_5
= '5'
attributeWEBSOCKET_DEPTH_10
= '10'
attributeWEBSOCKET_DEPTH_20
= '20'
attributetestnet
= self._client.testnet
attributedemo
= self._client.demo
attributeverbose
= verbose
attributews_kwargs
= {}

Functions

func__init__(self, client, user_timeout=KEEPALIVE_TIMEOUT, max_queue_size=100, verbose=False)

Initialise the BinanceSocketManager

:param client: Binance API client :type client: binance.AsyncClient :param user_timeout: Timeout for user socket in seconds :param max_queue_size: Max size of the websocket queue, defaults to 100 :type max_queue_size: int :param verbose: Enable verbose logging for WebSocket connections :type verbose: bool

paramself
paramclientAsyncClient
paramuser_timeout
= KEEPALIVE_TIMEOUT
parammax_queue_sizeint
= 100
paramverbosebool
= False

Returns

None
func_get_stream_url(self, stream_url=None)
paramself
paramstream_urlOptional[str]
= None

Returns

None
func_get_socket(self, path, stream_url=None, prefix='ws/', is_binary=False, socket_type=BinanceSocketType.SPOT) -> ReconnectingWebsocket
paramself
parampathstr
paramstream_urlOptional[str]
= None
paramprefixstr
= 'ws/'
paramis_binarybool
= False
paramsocket_typeBinanceSocketType
= BinanceSocketType.SPOT

Returns

binance.ws.reconnecting_websocket.ReconnectingWebsocket
func_get_account_socket(self, path, stream_url=None, prefix='ws/', is_binary=False) -> KeepAliveWebsocket
paramself
parampathstr
paramstream_urlOptional[str]
= None
paramprefixstr
= 'ws/'
paramis_binarybool
= False

Returns

binance.ws.keepalive_websocket.KeepAliveWebsocket
func_get_futures_socket(self, path, futures_type, prefix='stream?streams=')
paramself
parampathstr
paramfutures_typeFuturesType
paramprefixstr
= 'stream?streams='

Returns

None
func_get_options_socket(self, path, prefix='ws/')
paramself
parampathstr
paramprefixstr
= 'ws/'

Returns

None
func_exit_socket(self, path)
paramself
parampathstr

Returns

None
funcdepth_socket(self, symbol, depth=None, interval=None)

Start a websocket for symbol market depth returning either a diff or a partial book

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#partial-book-depth-streams

:param symbol: required :type symbol: str :param depth: optional Number of depth entries to return, default None. If passed returns a partial book instead of a diff :type depth: str :param interval: optional interval for updates, default None. If not set, updates happen every second. Must be 0, None (1s) or 100 (100ms) :type interval: int

:returns: connection key string if successful, False otherwise

Partial Message Format

.. code-block:: python

{ "lastUpdateId": 160, # Last update ID "bids": [ # Bids to be updated [ "0.0024", # price level to be updated "10", # quantity [] # ignore ] ], "asks": [ # Asks to be updated [ "0.0026", # price level to be updated "100", # quantity [] # ignore ] ] }

Diff Message Format

.. code-block:: python

{ "e": "depthUpdate", # Event type "E": 123456789, # Event time "s": "BNBBTC", # Symbol "U": 157, # First update ID in event "u": 160, # Final update ID in event "b": [ # Bids to be updated [ "0.0024", # price level to be updated "10", # quantity [] # ignore ] ], "a": [ # Asks to be updated [ "0.0026", # price level to be updated "100", # quantity [] # ignore ] ] }

paramself
paramsymbolstr
paramdepthOptional[str]
= None
paramintervalOptional[int]
= None

Returns

None
funckline_socket(self, symbol, interval=AsyncClient.KLINE_INTERVAL_1MINUTE)

Start a websocket for symbol kline data

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#klinecandlestick-streams

:param symbol: required :type symbol: str :param interval: Kline interval, default KLINE_INTERVAL_1MINUTE :type interval: str

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e": "kline", # event type "E": 1499404907056, # event time "s": "ETHBTC", # symbol "k": { "t": 1499404860000, # start time of this bar "T": 1499404919999, # end time of this bar "s": "ETHBTC", # symbol "i": "1m", # interval "f": 77462, # first trade id "L": 77465, # last trade id "o": "0.10278577", # open "c": "0.10278645", # close "h": "0.10278712", # high "l": "0.10278518", # low "v": "17.47929838", # volume "n": 4, # number of trades "x": false, # whether this bar is final "q": "1.79662878", # quote volume "V": "2.34879839", # volume of active buy "Q": "0.24142166", # quote volume of active buy "B": "13279784.01349473" # can be ignored } }

paramself
paramsymbolstr
paraminterval
= AsyncClient.KLINE_INTERVAL_1MINUTE

Returns

None
funckline_futures_socket(self, symbol, interval=AsyncClient.KLINE_INTERVAL_1MINUTE, futures_type=FuturesType.USD_M, contract_type=ContractType.PERPETUAL)

Start a websocket for symbol kline data for the perpeual futures stream

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

:param symbol: required :type symbol: str :param interval: Kline interval, default KLINE_INTERVAL_1MINUTE :type interval: str :param futures_type: use USD-M or COIN-M futures default USD-M :param contract_type: use PERPETUAL or CURRENT_QUARTER or NEXT_QUARTER default PERPETUAL

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e":"continuous_kline", // Event type "E":1607443058651, // Event time "ps":"BTCUSDT", // Pair "ct":"PERPETUAL" // Contract type "k":{ "t":1607443020000, // Kline start time "T":1607443079999, // Kline close time "i":"1m", // Interval "f":116467658886, // First trade ID "L":116468012423, // Last trade ID "o":"18787.00", // Open price "c":"18804.04", // Close price "h":"18804.04", // High price "l":"18786.54", // Low price "v":"197.664", // volume "n": 543, // Number of trades "x":false, // Is this kline closed? "q":"3715253.19494", // Quote asset volume "V":"184.769", // Taker buy volume "Q":"3472925.84746", //Taker buy quote asset volume "B":"0" // Ignore } } <pair><contractType>@continuousKline<interval>

paramself
paramsymbolstr
paraminterval
= AsyncClient.KLINE_INTERVAL_1MINUTE
paramfutures_typeFuturesType
= FuturesType.USD_M
paramcontract_typeContractType
= ContractType.PERPETUAL

Returns

None
funcminiticker_socket(self, update_time=1000)

Start a miniticker websocket for all trades

This is not in the official Binance api docs, but this is what feeds the right column on a ticker page on Binance.

:param update_time: time between callbacks in milliseconds, must be 1000 or greater :type update_time: int

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

[ { 'e': '24hrMiniTicker', # Event type 'E': 1515906156273, # Event time 's': 'QTUMETH', # Symbol 'c': '0.03836900', # close 'o': '0.03953500', # open 'h': '0.04400000', # high 'l': '0.03756000', # low 'v': '147435.80000000', # volume 'q': '5903.84338533' # quote volume } ]

paramself
paramupdate_timeint
= 1000

Returns

None
functrade_socket(self, symbol)

Start a websocket for symbol trade data

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#trade-streams

:param symbol: required :type symbol: str

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e": "trade", # Event type "E": 123456789, # Event time "s": "BNBBTC", # Symbol "t": 12345, # Trade ID "p": "0.001", # Price "q": "100", # Quantity "b": 88, # Buyer order Id "a": 50, # Seller order Id "T": 123456785, # Trade time "m": true, # Is the buyer the market maker? "M": true # Ignore. }

paramself
paramsymbolstr

Returns

None
funcaggtrade_socket(self, symbol)

Start a websocket for symbol trade data

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#aggregate-trade-streams

:param symbol: required :type symbol: str

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e": "aggTrade", # event type "E": 1499405254326, # event time "s": "ETHBTC", # symbol "a": 70232, # aggregated tradeid "p": "0.10281118", # price "q": "8.15632997", # quantity "f": 77489, # first breakdown trade id "l": 77489, # last breakdown trade id "T": 1499405254324, # trade time "m": false, # whether buyer is a maker "M": true # can be ignored }

paramself
paramsymbolstr

Returns

None
funcaggtrade_futures_socket(self, symbol, futures_type=FuturesType.USD_M)

Start a websocket for aggregate symbol trade data for the futures stream

:param symbol: required :param futures_type: use USD-M or COIN-M futures default USD-M

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e": "aggTrade", // Event type "E": 123456789, // Event time "s": "BTCUSDT", // Symbol "a": 5933014, // Aggregate trade ID "p": "0.001", // Price "q": "100", // Quantity "f": 100, // First trade ID "l": 105, // Last trade ID "T": 123456785, // Trade time "m": true, // Is the buyer the market maker? }

paramself
paramsymbolstr
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcsymbol_miniticker_socket(self, symbol)

Start a websocket for a symbol's miniTicker data

https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream

:param symbol: required :type symbol: str

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e": "24hrMiniTicker", // Event type "E": 123456789, // Event time "s": "BNBBTC", // Symbol "c": "0.0025", // Close price "o": "0.0010", // Open price "h": "0.0025", // High price "l": "0.0010", // Low price "v": "10000", // Total traded base asset volume "q": "18" // Total traded quote asset volume }

paramself
paramsymbolstr

Returns

None
funcsymbol_ticker_socket(self, symbol)

Start a websocket for a symbol's ticker data

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-ticker-streams

:param symbol: required :type symbol: str

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "e": "24hrTicker", # Event type "E": 123456789, # Event time "s": "BNBBTC", # Symbol "p": "0.0015", # Price change "P": "250.00", # Price change percent "w": "0.0018", # Weighted average price "x": "0.0009", # Previous day's close price "c": "0.0025", # Current day's close price "Q": "10", # Close trade's quantity "b": "0.0024", # Best bid price "B": "10", # Bid bid quantity "a": "0.0026", # Best ask price "A": "100", # Best ask quantity "o": "0.0010", # Open price "h": "0.0025", # High price "l": "0.0010", # Low price "v": "10000", # Total traded base asset volume "q": "18", # Total traded quote asset volume "O": 0, # Statistics open time "C": 86400000, # Statistics close time "F": 0, # First trade ID "L": 18150, # Last trade Id "n": 18151 # Total number of trades }

paramself
paramsymbolstr

Returns

None
functicker_socket(self)

Start a websocket for all ticker data

By default all markets are included in an array.

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-tickers-stream

:param coro: callback function to handle messages :type coro: function

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

[ { 'F': 278610, 'o': '0.07393000', 's': 'BCCBTC', 'C': 1509622420916, 'b': '0.07800800', 'l': '0.07160300', 'h': '0.08199900', 'L': 287722, 'P': '6.694', 'Q': '0.10000000', 'q': '1202.67106335', 'p': '0.00494900', 'O': 1509536020916, 'a': '0.07887800', 'n': 9113, 'B': '1.00000000', 'c': '0.07887900', 'x': '0.07399600', 'w': '0.07639068', 'A': '2.41900000', 'v': '15743.68900000' } ]

paramself

Returns

None
funcfutures_ticker_socket(self)

Start a websocket for all ticker data

By default all markets are included in an array.

https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

[ { "e": "24hrTicker", // Event type "E": 123456789, // Event time "s": "BTCUSDT", // Symbol "p": "0.0015", // Price change "P": "250.00", // Price change percent "w": "0.0018", // Weighted average price "c": "0.0025", // Last price "Q": "10", // Last quantity "o": "0.0010", // Open price "h": "0.0025", // High price "l": "0.0010", // Low price "v": "10000", // Total traded base asset volume "q": "18", // Total traded quote asset volume "O": 0, // Statistics open time "C": 86400000, // Statistics close time "F": 0, // First trade ID "L": 18150, // Last trade Id "n": 18151 // Total number of trades } ]

paramself

Returns

None
funcfutures_coin_ticker_socket(self)

Start a websocket for all ticker data

By default all markets are included in an array.

https://binance-docs.github.io/apidocs/delivery/en/#all-market-tickers-streams

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

[ { "e": "24hrTicker", // Event type "E": 123456789, // Event time "s": "BTCUSDT", // Symbol "p": "0.0015", // Price change "P": "250.00", // Price change percent "w": "0.0018", // Weighted average price "c": "0.0025", // Last price "Q": "10", // Last quantity "o": "0.0010", // Open price "h": "0.0025", // High price "l": "0.0010", // Low price "v": "10000", // Total traded base asset volume "q": "18", // Total traded quote asset volume "O": 0, // Statistics open time "C": 86400000, // Statistics close time "F": 0, // First trade ID "L": 18150, // Last trade Id "n": 18151 // Total number of trades } ]

paramself

Returns

None
funcindex_price_socket(self, symbol, fast=True)

Start a websocket for a symbol's futures mark price https://binance-docs.github.io/apidocs/delivery/en/#index-price-stream :param symbol: required :param fast: use faster or 1s default :returns: connection key string if successful, False otherwise

Message Format .. code-block:: python { "e": "indexPriceUpdate", // Event type "E": 1591261236000, // Event time "i": "BTCUSD", // Pair "p": "9636.57860000", // Index Price }

paramself
paramsymbolstr
paramfastbool
= True

Returns

None
funcsymbol_mark_price_socket(self, symbol, fast=True, futures_type=FuturesType.USD_M)

Start a websocket for a symbol's futures mark price https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream :param symbol: required :param fast: use faster or 1s default :param futures_type: use USD-M or COIN-M futures default USD-M :returns: connection key string if successful, False otherwise Message Format .. code-block:: python { "e": "markPriceUpdate", // Event type "E": 1562305380000, // Event time "s": "BTCUSDT", // Symbol "p": "11185.87786614", // Mark price "r": "0.00030000", // Funding rate "T": 1562306400000 // Next funding time }

paramself
paramsymbolstr
paramfastbool
= True
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcall_mark_price_socket(self, fast=True, futures_type=FuturesType.USD_M)

Start a websocket for all futures mark price data By default all symbols are included in an array. https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market :param fast: use faster or 1s default :param futures_type: use USD-M or COIN-M futures default USD-M :returns: connection key string if successful, False otherwise Message Format .. code-block:: python

[ { "e": "markPriceUpdate", // Event type "E": 1562305380000, // Event time "s": "BTCUSDT", // Symbol "p": "11185.87786614", // Mark price "r": "0.00030000", // Funding rate "T": 1562306400000 // Next funding time } ]

paramself
paramfastbool
= True
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcsymbol_ticker_futures_socket(self, symbol, futures_type=FuturesType.USD_M)

Start a websocket for a symbol's ticker data By default all markets are included in an array. https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-book-ticker-streams :param symbol: required :param futures_type: use USD-M or COIN-M futures default USD-M :returns: connection key string if successful, False otherwise .. code-block:: python [ { "u":400900217, // order book updateId "s":"BNBUSDT", // symbol "b":"25.35190000", // best bid price "B":"31.21000000", // best bid qty "a":"25.36520000", // best ask price "A":"40.66000000" // best ask qty } ]

paramself
paramsymbolstr
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcindividual_symbol_ticker_futures_socket(self, symbol, futures_type=FuturesType.USD_M)

Start a futures websocket for a single symbol's ticker data https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams :param symbol: required :type symbol: str :param futures_type: use USD-M or COIN-M futures default USD-M :returns: connection key string if successful, False otherwise .. code-block:: python { "e": "24hrTicker", // Event type "E": 123456789, // Event time "s": "BTCUSDT", // Symbol "p": "0.0015", // Price change }

paramself
paramsymbolstr
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcall_ticker_futures_socket(self, channel='!bookTicker', futures_type=FuturesType.USD_M)

Start a websocket for all ticker data By default all markets are included in an array.

https://binance-docs.github.io/apidocs/futures/en/#all-book-tickers-stream

https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams

:param channel: optional channel type, default '!bookTicker', but '!ticker@arr' is also available :param: futures_type: use USD-M or COIN-M futures default USD-M :returns: connection key string if successful, False otherwise Message Format .. code-block:: python [ { "u":400900217, // order book updateId "s":"BNBUSDT", // symbol "b":"25.35190000", // best bid price "B":"31.21000000", // best bid qty "a":"25.36520000", // best ask price "A":"40.66000000" // best ask qty } ]

paramself
paramchannelstr
= '!bookTicker'
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcsymbol_book_ticker_socket(self, symbol)

Start a websocket for the best bid or ask's price or quantity for a specified symbol.

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-book-ticker-streams

:param symbol: required :type symbol: str

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ "u":400900217, // order book updateId "s":"BNBUSDT", // symbol "b":"25.35190000", // best bid price "B":"31.21000000", // best bid qty "a":"25.36520000", // best ask price "A":"40.66000000" // best ask qty }

paramself
paramsymbolstr

Returns

None
funcbook_ticker_socket(self)

Start a websocket for the best bid or ask's price or quantity for all symbols.

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-book-tickers-stream

:returns: connection key string if successful, False otherwise

Message Format

.. code-block:: python

{ // Same as <symbol>@bookTicker payload }

paramself

Returns

None
funcmultiplex_socket(self, streams)

Start a multiplexed socket using a list of socket names. User stream sockets can not be included.

Symbols in socket name must be lowercase i.e bnbbtc@aggTrade, neobtc@ticker

Combined stream events are wrapped as follows: {"stream":"<streamName>","data":<rawPayload>}

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md

:param streams: list of stream names in lower case :type streams: list

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself
paramstreamsList[str]

Returns

None
funcoptions_multiplex_socket(self, streams)

Start a multiplexed socket using a list of socket names.

https://developers.binance.com/docs/derivatives/option/websocket-market-streams

paramself
paramstreamsList[str]

Returns

None
funcfutures_multiplex_socket(self, streams, futures_type=FuturesType.USD_M)

Start a multiplexed socket using a list of socket names. User stream sockets can not be included.

Symbols in socket name must be lowercase i.e bnbbtc@aggTrade, neobtc@ticker

Combined stream events are wrapped as follows: {"stream":"<streamName>","data":<rawPayload>}

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md

:param streams: list of stream names in lower case :param futures_type: use USD-M or COIN-M futures default USD-M

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself
paramstreamsList[str]
paramfutures_typeFuturesType
= FuturesType.USD_M

Returns

None
funcuser_socket(self)

Start a websocket for user data

https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself

Returns

None
funcfutures_user_socket(self)

Start a websocket for futures user data

https://binance-docs.github.io/apidocs/futures/en/#user-data-streams

:returns: connection key string if successful, False otherwise

Message Format - see Binanace API docs for all types

paramself

Returns

None
funccoin_futures_user_socket(self)

Start a websocket for coin futures user data

https://binance-docs.github.io/apidocs/delivery/en/#user-data-streams

:returns: connection key string if successful, False otherwise

Message Format - see Binanace API docs for all types

paramself

Returns

None
funcmargin_socket(self)

Start a websocket for cross-margin data

https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself

Returns

None
funcfutures_socket(self)

Start a websocket for futures data

https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself

Returns

None
funccoin_futures_socket(self)

Start a websocket for coin futures data

https://binance-docs.github.io/apidocs/delivery/en/#websocket-market-streams

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself

Returns

None
funcportfolio_margin_socket(self)

Start a websocket for portfolio margin user data

https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself

Returns

None
funcisolated_margin_socket(self, symbol)

Start a websocket for isolated margin data

https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin

:param symbol: required - symbol for the isolated margin account :type symbol: str

:returns: connection key string if successful, False otherwise

Message Format - see Binance API docs for all types

paramself
paramsymbolstr

Returns

None
funcoptions_ticker_socket(self, symbol)

Subscribe to a 24-hour ticker info stream for options trading.

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER

Stream provides real-time 24hr ticker information for all symbols. Only symbols whose ticker info changed will be sent. Updates every 1000ms.

:param symbol: The option symbol to subscribe to (e.g. "BTC-220930-18000-C") :type symbol: str

paramself
paramsymbolstr

Returns

None
funcoptions_ticker_by_expiration_socket(self, symbol, expiration_date)

Subscribe to a 24-hour ticker info stream by underlying asset and expiration date.

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER-by-underlying-asset-and-expiration-data

Stream provides real-time 24hr ticker information grouped by underlying asset and expiration date. Updates every 1000ms.

:param symbol: The underlying asset (e.g., "ETH") :type symbol: str :param expiration_date: The expiration date (e.g., "220930" for Sept 30, 2022) :type expiration_date: str

paramself
paramsymbolstr
paramexpiration_datestr

Returns

None
funcoptions_recent_trades_socket(self, symbol)

Subscribe to a real-time trade information stream.

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Trade-Streams

Stream pushes raw trade information for a specific symbol or underlying asset. Updates every 50ms.

:param symbol: The option symbol or underlying asset (e.g., "BTC-200630-9000-P" or "BTC") :type symbol: str

paramself
paramsymbolstr

Returns

None
funcoptions_kline_socket(self, symbol, interval=AsyncClient.KLINE_INTERVAL_1MINUTE)

Subscribe to a Kline/Candlestick data stream.

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Kline-Candlestick-Streams

Stream pushes updates to the current klines/candlestick every 1000ms (if existing).

Available intervals:

  • Minutes: "1m", "3m", "5m", "15m", "30m"
  • Hours: "1h", "2h", "4h", "6h", "12h"
  • Days: "1d", "3d"
  • Weeks: "1w"

:param symbol: The option symbol (e.g., "BTC-200630-9000-P") :type symbol: str :param interval: Kline interval, default KLINE_INTERVAL_1MINUTE :type interval: str

paramself
paramsymbolstr
paraminterval
= AsyncClient.KLINE_INTERVAL_1MINUTE

Returns

None
funcoptions_depth_socket(self, symbol, depth='10')

Subscribe to partial book depth stream for options trading.

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Partial-Book-Depth-Streams

Stream provides top N bids and asks from the order book. Default update speed is 500ms if not specified in the stream name.

:param symbol: The option symbol (e.g., "BTC-200630-9000-P") :type symbol: str :param depth: Number of price levels. Valid values: "10", "20", "50", "100" :type depth: str

paramself
paramsymbolstr
paramdepthstr
= '10'

Returns

None
funcfutures_depth_socket(self, symbol, depth='10', futures_type=FuturesType.USD_M)

Subscribe to a futures depth data stream

https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams

:param symbol: required :type symbol: str :param depth: optional Number of depth entries to return, default 10. :type depth: str :param futures_type: use USD-M or COIN-M futures default USD-M

paramself
paramsymbolstr
paramdepthstr
= '10'
paramfutures_type
= FuturesType.USD_M

Returns

None
funcfutures_rpi_depth_socket(self, symbol, futures_type=FuturesType.USD_M)

Subscribe to a futures RPI (Retail Price Improvement) depth data stream

RPI orders are included and aggregated in the stream. Crossed price levels are hidden. Updates every 500ms.

https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-market-streams/RPI-Order-Book

:param symbol: required :type symbol: str :param futures_type: use USD-M or COIN-M futures default USD-M

paramself
paramsymbolstr
paramfutures_type
= FuturesType.USD_M

Returns

None
funcoptions_new_symbol_socket(self)

Subscribe to a new symbol listing information stream.

Stream provides real-time notifications when new option symbols are listed. Updates every 50ms.

Stream name: option_pair

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/New-Symbol-Info

Response fields include:

  • Event type and timestamps
  • Underlying index (e.g., 'BTCUSDT')
  • Quotation asset (e.g., 'USDT')
  • Trading pair name (e.g., 'BTC-221116-21000-C')
  • Conversion ratio and minimum trade volume
  • Option type (CALL/PUT)
  • Strike price and expiration time
paramself

Returns

None
funcoptions_open_interest_socket(self, symbol, expiration_date)

Subscribe to an options open interest stream.

Stream provides open interest information for specific underlying asset on specific expiration date. Updates every 60 seconds.

Stream name format: <underlyingAsset>@openInterest@<expirationDate>

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Open-Interest

Response fields include:

  • Event type and timestamps
  • Option symbol (e.g., 'ETH-221125-2700-C')
  • Open interest in contracts
  • Open interest in USDT

:param symbol: The underlying asset (e.g., "ETH") :type symbol: str :param expiration_date: The expiration date (e.g., "221125" for Nov 25, 2022) :type expiration_date: str

paramself
paramsymbolstr
paramexpiration_datestr

Returns

None
funcoptions_mark_price_socket(self, symbol)

Subscribe to an options mark price stream.

Stream provides mark price information for all option symbols on specific underlying asset. Updates every 1000ms.

Stream name format: <underlyingAsset>@markPrice

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Mark-Price

Response fields include:

  • Event type and timestamps
  • Option symbol (e.g., 'ETH-220930-1500-C')
  • Option mark price

:param symbol: The underlying asset (e.g., "ETH") :type symbol: str

paramself
paramsymbolstr

Returns

None
funcoptions_index_price_socket(self, symbol)

Subscribe to an options index price stream.

API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Index-Price-Streams

Stream provides index price information for underlying assets (e.g., ETHUSDT). Updates every 1000ms.

Response fields include:

  • Event type and timestamps
  • Underlying symbol (e.g., 'ETHUSDT')
  • Index price

:param symbol: The underlying symbol (e.g., "ETHUSDT") :type symbol: str

paramself
paramsymbolstr

Returns

None
func_stop_socket(self, conn_key)

Stop a websocket given the connection key

:param conn_key: Socket connection key :type conn_key: string

:returns: None

paramself
paramconn_key

Returns

None

On this page