
    6i>                         d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
Z
d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  G d dee      Z G d d      Z G d de      Zy)    N)Enum)OptionalListDictCallableAny)KEEPALIVE_TIMEOUT)KeepAliveWebsocket)ReconnectingWebsocket)ThreadedApiManager)AsyncClient)FuturesType)ContractType)get_loopc                        e Zd ZdZdZdZdZdZy)BinanceSocketTypeSpotUSD_M_FuturesCoin_M_FuturesVanilla_OptionsAccountN)__name__
__module____qualname__SPOTUSD_M_FUTURESCOIN_M_FUTURESOPTIONSACCOUNT     P/var/www/app/trading-bot/venv/lib/python3.12/site-packages/binance/ws/streams.pyr   r      s    D#M%NGGr!   r   c                      e Zd ZdZdZdZdZdZdZdZ	dZ
dZd	Zd
ZdZdZeddfdededefdZdXdee   fdZdddej2                  fdedee   dedededefdZ	 	 	 dYdedee   dededef
dZ	 dZdededefdZd[dedefd Z defd!Z!	 d\d"ed#ee   d$ee   fd%Z"ejF                  fd"efd&Z$ejF                  ejJ                  e&jN                  fd"eded'e&fd(Z(d]d)efd*Z)d"efd+Z*d"efd,Z+ejJ                  fd"edefd-Z,d"efd.Z-d"efd/Z.d0 Z/d1 Z0d2 Z1d^d"ed4efd5Z2d3ejJ                  fd"ed4edefd6Z3d3ejJ                  fd4edefd7Z4ejJ                  fd"edefd8Z5ejJ                  fd"edefd9Z6d:ejJ                  fd;edefd<Z7d"efd=Z8d> Z9d?e:e   fd@Z;d?e:e   fdAZ<ejJ                  fd?e:e   defdBZ=dC Z>dD Z?dE Z@dF ZAdG ZBdH ZCdI ZDd"efdJZEd"efdKZFd"edLefdMZGd"efdNZHejF                  fd"efdOZId_d"ed#efdPZJdejJ                  fd"ed#efdQZKejJ                  fd"efdRZLdS ZMd"edLefdTZNd"efdUZOd"efdVZPdW ZQy)`BinanceSocketManagerzwss://stream.binance.{}:9443/z$wss://stream.testnet.binance.vision/zwss://demo-stream.binance.com/zwss://fstream.binance.{}/zwss://stream.binancefuture.com/z wss://fstream.binancefuture.com/zwss://dstream.binance.{}/z wss://dstream.binancefuture.com/z#wss://nbstream.binance.{}/eoptions/51020d   Fclientmax_queue_sizeverbosec                    | j                   j                  |j                        | _         | j                  j                  |j                        | _        | j                  j                  |j                        | _        | j
                  j                  |j                        | _        i | _        t               | _        || _	        || _
        | j                  j                  | _        | j                  j                  | _        || _        || _        i | _        |r3t!        j"                  d      j%                  t         j&                         yy)a  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
        z
binance.wsN)
STREAM_URLformattldFSTREAM_URLDSTREAM_URLOPTIONS_URL_connsr   _loop_client_user_timeouttestnetdemo_max_queue_sizer+   	ws_kwargslogging	getLoggersetLevelDEBUG)selfr)   user_timeoutr*   r+   s        r"   __init__zBinanceSocketManager.__init__+   s    " //00<++226::>++226::>++226::>Z
)||++LL%%	-l+44W]]C r!   N
stream_urlc                     |r|S | j                   }| j                  r| j                  }|S | j                  r| j                  }|S N)r-   r7   STREAM_TESTNET_URLr8   STREAM_DEMO_URLr?   rB   s     r"   _get_stream_urlz$BinanceSocketManager._get_stream_urlN   sH    __
<<00J  YY--Jr!   ws/pathprefix	is_binarysocket_typereturnc                 D     d| }t         j                  dd       }|r| d| }| j                  vr[t        d| j	                  |      | fd| j                  j
                   j                  d j                   j                  |<    j                  |   S )N_	TIME_UNITz
?timeUnit=c                 0    j                   d|        S )NrP   _exit_socket)pr?   rM   s    r"   <lambda>z2BinanceSocketManager._get_socket.<locals>.<lambda>i   s    D$5$5Qqc6J$K r!   )rJ   urlrK   	exit_cororL   https_proxyr*   r    )getattrr5   r3   r   rH   rY   r9   r:   )r?   rJ   rB   rK   rL   rM   conn_id	time_units   `    `  r"   _get_socketz BinanceSocketManager._get_socketX   s     !M4&)DLL+t<	V:i[1D$++%#8 	$((4K# LL44#33	$ ..	$DKK  {{7##r!   c                 L    t         j                   d|  j                  vrqt        d j                   j                  |      || fd| j                   j                  j                   j                  d	 j                   j                  <    j                     S )NrP   c                 &    j                        S rD   rS   )rU   r[   r?   s    r"   rV   z:BinanceSocketManager._get_account_socket.<locals>.<lambda>   s    D$5$5g$> r!   )	r)   rW   keepalive_typerK   rX   rL   r@   rY   r*   r    )
r   r   r3   r
   r5   rH   r6   rY   r9   r:   )r?   rJ   rB   rK   rL   r[   s   `    @r"   _get_account_socketz(BinanceSocketManager._get_account_socketr   s     '../q7$++%#5 $||((4#>#!// LL44#33$ ..$DKK  {{7##r!   futures_typec                 h   t         j                  }|t        j                  k(  r>| j                  }| j
                  r| j                  }nV| j                  rJ| j                  }n=| j                  }| j
                  r| j                  }n| j                  r| j                  }| j                  ||||      S )N)rM   )r   r   r   USD_Mr0   r7   FSTREAM_TESTNET_URLr8   FSTREAM_DEMO_URLr1   DSTREAM_TESTNET_URLDSTREAM_DEMO_URLr]   )r?   rJ   rb   rK   rM   rB   s         r"   _get_futures_socketz(BinanceSocketManager._get_futures_socket   s     *;)H)H;,,,))J||!55
!22
))J||!55
!22
j&kRRr!   c                 b    | j                   }| j                  |||dt        j                        S )NF)rL   rM   )r2   r]   r   r   )r?   rJ   rK   rB   s       r"   _get_options_socketz(BinanceSocketManager._get_options_socket   s:    %%
)11   
 	
r!   c                 B   K   | j                  |       d {    y 7 wrD   )_stop_socket)r?   rJ   s     r"   rT   z!BinanceSocketManager._exit_socket   s     %%%s   symboldepthintervalc                     |j                         dz   }|r|dk7  r| | }|r|dv r	| d| d}nt        d      | j                  |      S )a		  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
                    ]
                ]
            }

        @depth1)r   r(   @mszAWebsocket interval value not allowed. Allowed values are [0, 100])lower
ValueErrorr]   )r?   rn   ro   rp   socket_names        r"   depth_socketz!BinanceSocketManager.depth_socket   sl    D llnx/Uc\(M%1K8#!,Qxj; W  ,,r!   c                 N    |j                          d| }| j                  |      S )aW  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
                    }
            }
        @kline_)rv   r]   )r?   rn   rp   rJ   s       r"   kline_socketz!BinanceSocketManager.kline_socket   s-    R ,,.!
3%%r!   contract_typec                 n    |j                          d|j                   d| }| j                  |d|      S )a  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>
        rP   z@continuousKline_rI   rK   rb   )rv   valueri   )r?   rn   rp   rb   r}   rJ   s         r"   kline_futures_socketz)BinanceSocketManager.kline_futures_socket#  sB    f ,,.!=#6#6"77H
S''U'VVr!   update_timec                 ,    | j                  d| d      S )a  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
                }
            ]
        z!miniTicker@arr@ru   r]   )r?   r   s     r"   miniticker_socketz&BinanceSocketManager.miniticker_socketY  s    < "2;-r BCCr!   c                 F    | j                  |j                         dz         S )a  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.
            }

        @trader]   rv   r?   rn   s     r"   trade_socketz!BinanceSocketManager.trade_sockety  s     <  9::r!   c                 F    | j                  |j                         dz         S )a  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
            }

        	@aggTrader   r   s     r"   aggtrade_socketz$BinanceSocketManager.aggtrade_socket  s     :  <==r!   c                 J    | j                  |j                         dz   |      S )aP  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?
            }

        r   rb   ri   rv   r?   rn   rb   s      r"   aggtrade_futures_socketz,BinanceSocketManager.aggtrade_futures_socket  s,    8 ''LLN[(| ( 
 	
r!   c                 F    | j                  |j                         dz         S )a{  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
            }

        z@miniTickerr   r   s     r"   symbol_miniticker_socketz-BinanceSocketManager.symbol_miniticker_socket  s     6  >??r!   c                 F    | j                  |j                         dz         S )a  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
            }

        @tickerr   r   s     r"   symbol_ticker_socketz)BinanceSocketManager.symbol_ticker_socket  s!    R  :;;r!   c                 $    | j                  d      S )a"  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'
                }
            ]
        !ticker@arrr   r?   s    r"   ticker_socketz"BinanceSocketManager.ticker_socket   s    T ..r!   c                 B    | j                  dt        j                        S )a  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
                }
            ]
        r   )ri   r   rd   r   s    r"   futures_ticker_socketz*BinanceSocketManager.futures_ticker_socketL  s    H ''{7H7HIIr!   c                 B    | j                  dt        j                        S )a  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
                }
            ]
        r   )ri   r   COIN_Mr   s    r"   futures_coin_ticker_socketz/BinanceSocketManager.futures_coin_ticker_socketr  s    H ''{7I7IJJr!   Tfastc                 r    |rdnd}| j                  |j                         |z   t        j                        S )aP  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
              }
        z@indexPrice@1sz@indexPricer   )ri   rv   r   r   )r?   rn   r   stream_names       r"   index_price_socketz'BinanceSocketManager.index_price_socket  s<      +/&M''LLN[({7I7I ( 
 	
r!   c                 V    |rdnd}| j                  |j                         |z   |      S )a  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
            }
        z@markPrice@1s
@markPricer   r   )r?   rn   r   rb   r   s        r"   symbol_mark_price_socketz-BinanceSocketManager.symbol_mark_price_socket  s5    . *.o<''LLN[(| ( 
 	
r!   c                 4    |rdnd}| j                  ||      S )ai  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
                }
            ]
        z!markPrice@arr@1sz!markPrice@arrr   ri   )r?   r   rb   r   s       r"   all_mark_price_socketz*BinanceSocketManager.all_mark_price_socket  s%    . .2)7G'','OOr!   c                 J    | j                  |j                         dz   |      S )a  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
                }
            ]
        @bookTickerr   r   r   s      r"   symbol_ticker_futures_socketz1BinanceSocketManager.symbol_ticker_futures_socket  s,    * ''LLN]* ( 
 	
r!   c                 J    | j                  |j                         dz   |      S )ai  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
            }
        r   r   r   r   s      r"   'individual_symbol_ticker_futures_socketz<BinanceSocketManager.individual_symbol_ticker_futures_socket  s,    " ''LLNY&\ ( 
 	
r!   !bookTickerchannelc                 (    | j                  ||      S )a  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
                }
            ]
        r   r   )r?   r   rb   s      r"   all_ticker_futures_socketz.BinanceSocketManager.all_ticker_futures_socket  s    : ''l'KKr!   c                 F    | j                  |j                         dz         S )a  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
            }

        r   r   r   s     r"   symbol_book_ticker_socketz.BinanceSocketManager.symbol_book_ticker_socket0  s     0  >??r!   c                 $    | j                  d      S )a  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
            }

        r   r   r   s    r"   book_ticker_socketz'BinanceSocketManager.book_ticker_socketJ  s      ..r!   streamsc                 P    ddj                  |       }| j                  |d      S )at  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

        streams=/stream?rK   )joinr]   )r?   r   rJ   s      r"   multiplex_socketz%BinanceSocketManager.multiplex_socket\  s0    $ #((7+,-Y77r!   c                 z    dj                  |D cg c]  }| c}      }d| }| j                  |d      S c c}w )zStart a multiplexed socket using a list of socket names.

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

        r   r   r   r   )r   rk   )r?   r   sr   stream_paths        r"   options_multiplex_socketz-BinanceSocketManager.options_multiplex_socketq  sD     hh73a34 .''I'FF  4s   	8c                 R    ddj                  |       }| j                  |d|      S )a  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

        r   r   r   r   )r   ri   )r?   r   rb   rJ   s       r"   futures_multiplex_socketz-BinanceSocketManager.futures_multiplex_socket{  s9    ( #((7+,-'' ( 
 	
r!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }| j                  d|      S )a\  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
        userrB   r-   r7   rE   r8   rF   ra   rG   s     r"   user_socketz BinanceSocketManager.user_socket  sG     __
<<00JYY--J'':'FFr!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }| j                  d|      S )a  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
        futuresr   r0   r7   re   r8   rf   ra   rG   s     r"   futures_user_socketz(BinanceSocketManager.futures_user_socket  sI     %%
<<11JYY..J''	j'IIr!   c                 <    | j                  d| j                        S )a
  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
        coin_futuresr   )ra   r1   r   s    r"   coin_futures_user_socketz-BinanceSocketManager.coin_futures_user_socket  s      ''4CSCS'TTr!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }| j                  d|      S )a   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
        marginr   r   rG   s     r"   margin_socketz"BinanceSocketManager.margin_socket  sG     __
<<00JYY--J''Z'HHr!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }| j                  d|      S )a	  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
        r   r   r   rG   s     r"   futures_socketz#BinanceSocketManager.futures_socket  sI     %%
<<11JYY..J''	j'IIr!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }| j                  d|      S )a  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
        r   r   )r1   r7   rg   r8   rh   ra   rG   s     r"   coin_futures_socketz(BinanceSocketManager.coin_futures_socket  sI     %%
<<11JYY..J'':'NNr!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }|dz  }| j                  d|      S )a  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
        zpm/portfolio_marginr   r   rG   s     r"   portfolio_margin_socketz,BinanceSocketManager.portfolio_margin_socket  sT     %%
<<11JYY..Je
''(:z'RRr!   c                     | j                   }| j                  r| j                  }n| j                  r| j                  }| j                  ||      S )ap  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
        r   r   )r?   rn   rB   s      r"   isolated_margin_socketz+BinanceSocketManager.isolated_margin_socket  sG     __
<<00JYY--J'':'FFr!   c                 F    | j                  |j                         dz         S )a  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
        r   rk   upperr   s     r"   options_ticker_socketz*BinanceSocketManager.options_ticker_socket  s      ''(BCCr!   expiration_datec                 L    | j                  |j                         dz   |z         S )aS  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
        z@ticker@r   r?   rn   r   s      r"   #options_ticker_by_expiration_socketz8BinanceSocketManager.options_ticker_by_expiration_socket#  s%     ''(Co(UVVr!   c                 F    | j                  |j                         dz         S )a  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
        r   r   r   s     r"   options_recent_trades_socketz1BinanceSocketManager.options_recent_trades_socket2  s      ''(ABBr!   c                 L    | j                  |j                         dz   |z         S )a  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
        r{   r   )r?   rn   rp   s      r"   options_kline_socketz)BinanceSocketManager.options_kline_socket?  s%    ( ''(BX(MNNr!   c                 ^    | j                  |j                         dz   t        |      z         S )a!  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
        rr   )rk   r   str)r?   rn   ro   s      r"   options_depth_socketz)BinanceSocketManager.options_depth_socketU  s)     ''(ACJ(NOOr!   c                 b    | j                  |j                         dz   t        |      z   |      S )aq  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
        rr   r   )ri   rv   r   )r?   rn   ro   rb   s       r"   futures_depth_socketz)BinanceSocketManager.futures_depth_socketd  s5     ''LLNX%E
2 ( 
 	
r!   c                 J    | j                  |j                         dz   |      S )a  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
        z@rpiDepth@500msr   r   r   s      r"   futures_rpi_depth_socketz-BinanceSocketManager.futures_rpi_depth_sockets  s-     ''LLN..\ ( 
 	
r!   c                 $    | j                  d      S )a  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
        option_pair)rk   r   s    r"   options_new_symbol_socketz.BinanceSocketManager.options_new_symbol_socket  s    & ''66r!   c                 L    | j                  |j                         dz   |z         S )a  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
        z@openInterest@r   r   s      r"   options_open_interest_socketz1BinanceSocketManager.options_open_interest_socket  s&    * ''9I(IO([\\r!   c                 F    | j                  |j                         dz         S )aM  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
        r   r   r   s     r"   options_mark_price_socketz.BinanceSocketManager.options_mark_price_socket  s     $ ''(EFFr!   c                 F    | j                  |j                         dz         S )a
  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
        z@indexr   r   s     r"   options_index_price_socketz/BinanceSocketManager.options_index_price_socket  s       ''(ABBr!   c                 D   K   || j                   vry| j                   |= yw)zStop a websocket given the connection key

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

        :returns: None
        N)r3   )r?   conn_keys     r"   rm   z!BinanceSocketManager._stop_socket  s#      4;;&KK!s    rD   )NrI   F)zstream?streams=)rI   NNi  Tr&   )Rr   r   r   r-   rE   rF   r0   re   rf   r1   rg   rh   r2   WEBSOCKET_DEPTH_5WEBSOCKET_DEPTH_10WEBSOCKET_DEPTH_20r	   r   intboolrA   r   r   rH   r   r   r   r]   r
   ra   r   ri   rk   rT   ry   KLINE_INTERVAL_1MINUTEr|   rd   r   	PERPETUALr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   r    r!   r"   r$   r$      s   0J?6O-K;9-K<97K
 '!!D!D 	!D
 !DF(3-  %)):)?)?$$ SM$ 	$
 $ '$ 
$: %)$$ SM$ 	$
 $ 
$2 CTSS'2S<?S$
 
S 
&s & SWL-L-"*3-L-BJ3-L-\ 2=1S1S *&3 *&^ 33$/$5$5&2&<&<4W4W "	4W
 $4WlDS D@;3 ;@>c >@ 8C7H7H

)4
@@s @:)<3 )<V*/X$JL$KL
 
D 
0 $/$5$5	

 
 "	
:  [=N=NPP/:P6 8C7H7H

)4
4 8C7H7H

)4
. %$/$5$5LL "L>@ @4/$8S	 8*GS	 G ?J>O>O
Cy
0;
2G"J"
UI J O S"GS G&DC DW# WPS WC3 C %0$F$FOO,P3 Ps P >BP[PaPa 
3 
s 
 BMARAR 
s 
 7*]3 ] ].G G(C C$"r!   r$   c                       e Zd Z	 	 	 	 	 	 	 	 	 d?dee   dee   deeeef      dededeeeef      dee   deej                     d	e
f fd
Zd Z	 d@dededeeef   dee   def
dZ	 	 dAdededee   dee
   def
dZej"                  fdededefdZej"                  ej(                  ej,                  fdededededef
dZ	 dBdede
defdZdededefdZdededefdZej(                  fdedededefdZdededefdZdededefd Zdedefd!Z	 dCdeded#edefd$Zd"ej(                  fdeded#ededef
d%Z d"ej(                  fded#ededefd&Z!ej(                  fdedededefd'Z"ej(                  fdedededefd(Z#ej(                  fdededefd)Z$dededefd*Z%dedefd+Z&ded,e'e   defd-Z(ded,e'e   defd.Z)ej(                  fded,e'e   dedefd/Z*dedefd0Z+dedefd1Z,dedefd2Z-dedefd3Z.dedefd4Z/dedefd5Z0dededefd6Z1dededefd7Z2deded8edefd9Z3dededefd:Z4ej"                  fdededefd;Z5	 dDdedededefd=Z6d<ej(                  fdedededefd>Z7 xZ8S )EThreadedWebsocketManagerapi_key
api_secretrequests_paramsr/   r7   session_paramsrY   loopr*   c
           
      N    t         
|   ||||||||       d | _        |	| _        y rD   )superrA   _bsmr9   )r?   r	  r
  r  r/   r7   r  rY   r  r*   	__class__s             r"   rA   z!ThreadedWebsocketManager.__init__  s;     			
 59	-r!   c                 t   K   | j                   sJ t        | j                   | j                        | _        y w)N)r)   r*   )r5   r$   r9   r  r   s    r"   _before_socket_listener_startz6ThreadedWebsocketManager._before_socket_listener_start  s.     |||(<<//
	s   68callbackrx   paramsrJ   rN   c                    t        j                          }| j                  sGt        j                          |z
  dkD  rt        d      t        j                  d       | j                  sG t	        | j                  |      di |}|xs |j
                  }d| j                  |<   | j                  j                  t        j                  | j                  |||             |S )N   z;Binance Socket Manager failed to initialize after 5 secondsg?Tr    )timer  RuntimeErrorsleeprZ   _path_socket_runningr4   call_soon_threadsafeasynciocreate_taskstart_listener)r?   r  rx   r  rJ   
start_timesocketsocket_paths           r"   _start_async_socketz,ThreadedWebsocketManager._start_async_socket  s     YY[
))yy{Z'!+"#`aaJJsO )) 1K0:6:/6<<,0[)

''!4!4V[(!S	
 r!   rn   ro   rp   c                 2    | j                  |d|||d      S )Nry   )rn   ro   rp   r  rx   r  r$  )r?   r  rn   ro   rp   s        r"   start_depth_socketz+ThreadedWebsocketManager.start_depth_socket  s0     ''& $ ( 
 	
r!   c                 0    | j                  |d||d      S )Nr|   rn   rp   r&  r'  r?   r  rn   rp   s       r"   start_kline_socketz+ThreadedWebsocketManager.start_kline_socket)  s-     ''& $ ( 
 	
r!   rb   r}   c           	      4    | j                  |d||||d      S )Nr   )rn   rp   rb   r}   r&  r'  )r?   r  rn   rp   rb   r}   s         r"   start_kline_futures_socketz3ThreadedWebsocketManager.start_kline_futures_socket8  s3     ''. $ ,!.	 ( 	
 		
r!   r   c                 .    | j                  |dd|i      S )Nr   r   r&  r'  )r?   r  r   s      r"   start_miniticker_socketz0ThreadedWebsocketManager.start_miniticker_socketK  s,     ''+{ ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r?   r  rn   s      r"   start_trade_socketz+ThreadedWebsocketManager.start_trade_socketV  s*    ''&& ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   start_aggtrade_socketz.ThreadedWebsocketManager.start_aggtrade_socket_  s*    '')& ( 
 	
r!   c                 0    | j                  |d||d      S )Nr   rn   rb   r&  r'  r?   r  rn   rb   s       r"   start_aggtrade_futures_socketz6ThreadedWebsocketManager.start_aggtrade_futures_socketh  s-     ''1  , ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   start_symbol_miniticker_socketz7ThreadedWebsocketManager.start_symbol_miniticker_socketw  s*    ''2& ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   start_symbol_ticker_socketz3ThreadedWebsocketManager.start_symbol_ticker_socket  s*    ''.& ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?   r  s     r"   start_ticker_socketz,ThreadedWebsocketManager.start_ticker_socket  !    ''?2 ( 
 	
r!   Tr   c                 0    | j                  |d||d      S )Nr   )rn   r   r&  r'  )r?   r  rn   r   s       r"   start_index_price_socketz1ThreadedWebsocketManager.start_index_price_socket  s*     '',$d3 ( 
 	
r!   c                 2    | j                  |d|||d      S )Nr   )rn   r   rb   r&  r'  )r?   r  rn   r   rb   s        r"   start_symbol_mark_price_socketz7ThreadedWebsocketManager.start_symbol_mark_price_socket  s,     ''2$dLQ ( 
 	
r!   c                 0    | j                  |d||d      S )Nr   )r   rb   r&  r'  )r?   r  r   rb   s       r"   start_all_mark_price_socketz4ThreadedWebsocketManager.start_all_mark_price_socket  s*     ''/ ,? ( 
 	
r!   c                 0    | j                  |d||d      S )Nr   r7  r&  r'  r8  s       r"   "start_symbol_ticker_futures_socketz;ThreadedWebsocketManager.start_symbol_ticker_futures_socket  s*     ''6$lC ( 
 	
r!   c                 0    | j                  |d||d      S )Nr   r7  r&  r'  r8  s       r"   -start_individual_symbol_ticker_futures_socketzFThreadedWebsocketManager.start_individual_symbol_ticker_futures_socket  s*     ''A$lC ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rb   r&  r'  )r?   r  rb   s      r"   start_all_ticker_futures_socketz8ThreadedWebsocketManager.start_all_ticker_futures_socket  s*     ''3"L1 ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   start_symbol_book_ticker_socketz8ThreadedWebsocketManager.start_symbol_book_ticker_socket  s(    ''3f% ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_book_ticker_socketz1ThreadedWebsocketManager.start_book_ticker_socket  s"    ''+? ( 
 	
r!   r   c                 .    | j                  |dd|i      S )Nr   r   r&  r'  r?   r  r   s      r"   start_multiplex_socketz/ThreadedWebsocketManager.start_multiplex_socket  s(    ''*w' ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   r   r&  r'  rS  s      r"   start_options_multiplex_socketz7ThreadedWebsocketManager.start_options_multiplex_socket  s*     ''2w' ( 
 	
r!   c                 0    | j                  |d||d      S )Nr   )r   rb   r&  r'  )r?   r  r   rb   s       r"   start_futures_multiplex_socketz7ThreadedWebsocketManager.start_futures_multiplex_socket  s*     ''2&E ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_user_socketz*ThreadedWebsocketManager.start_user_socket  s!    ''= ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_futures_user_socketz2ThreadedWebsocketManager.start_futures_user_socket  "    ''+@ ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_coin_futures_user_socketz7ThreadedWebsocketManager.start_coin_futures_user_socket  s"    ''+Eb ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_margin_socketz,ThreadedWebsocketManager.start_margin_socket  rA  r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_futures_socketz-ThreadedWebsocketManager.start_futures_socket  s"    ''+;B ( 
 	
r!   c                 *    | j                  |di       S )Nr   r&  r'  r?  s     r"   start_coin_futures_socketz2ThreadedWebsocketManager.start_coin_futures_socket  r]  r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   start_isolated_margin_socketz5ThreadedWebsocketManager.start_isolated_margin_socket  s(    ''0f% ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   start_options_ticker_socketz4ThreadedWebsocketManager.start_options_ticker_socket  s(    ''/f% ( 
 	
r!   r   c                 0    | j                  |d||d      S )Nr   )rn   r   r&  r'  )r?   r  rn   r   s       r"   )start_options_ticker_by_expiration_socketzBThreadedWebsocketManager.start_options_ticker_by_expiration_socket%  s*     ''=$I ( 
 	
r!   c                 .    | j                  |dd|i      S )Nr   rn   r&  r'  r2  s      r"   "start_options_recent_trades_socketz;ThreadedWebsocketManager.start_options_recent_trades_socket.  s*     ''6f% ( 
 	
r!   c                 0    | j                  |d||d      S )Nr   r*  r&  r'  r+  s       r"   start_options_kline_socketz3ThreadedWebsocketManager.start_options_kline_socket7  s*     ''.$(; ( 
 	
r!   r&   c                 0    | j                  |d||d      S )Nr   )rn   ro   r&  r'  )r?   r  rn   ro   s       r"   start_options_depth_socketz3ThreadedWebsocketManager.start_options_depth_socketC  s*     ''.$u5 ( 
 	
r!   c                 2    | j                  |d|||d      S )Nr   )rn   ro   rb   r&  r'  )r?   r  rn   ro   rb   s        r"   start_futures_depth_socketz3ThreadedWebsocketManager.start_futures_depth_socketL  s,     ''.$ulS ( 
 	
r!   )	NNNcomFNNNr(   rD   r   r   r   r   )9r   r   r   r   r   r   r   r  r  AbstractEventLoopr  rA   r  r   r$  r(  r   r  r,  r   rd   r   r  r.  r0  r3  r5  r9  r;  r=  r@  rC  rE  rG  rI  rK  rM  rO  rQ  r   rT  rV  rX  rZ  r\  r_  ra  rc  re  rg  ri  rk  rm  ro  rq  rs  __classcell__)r  s   @r"   r  r    s    "&$(4837%)48!.#. SM. "$sCx.1	.
 . . !c3h0. c]. w001. .2
 #  S#X	
 sm 
0  $"&

 
 }	

 3-
 

* 33	

 

 

& 33$/$5$5&2&<&<

 

 "
 $
 

( 6:	
 	
/2	
		

8 
S 
S 

h 
 
 
 %0$5$5	

 
 "	

 


x 
 
QT 

8 
S 
S 

H 
 
 =A
 
*-
59
	
 $/$5$5

 
 	

 "
 

  $/$5$5	



 

 "	


 


  %0$5$5	



 

 "	


 


  %0$5$5	



 

 "	


 


 ?J>O>O
 
0;
	

 
# 
RU 

 
c 


x 
$s) 
PS 

 
+/9
	
 %0$5$5	



 c

 "	


 



( 
s 


( 
s 


x 
C 


H 
 


X 
# 


( 
s 


X 
s 
s 

H 
c 
c 

 
*-
@C
	

 
*-
	
 33	



 


 


 =A
 
*-
69
	
  &&

 
 	
 

r!   r  )r  r  enumr   typingr   r   r   r   r   r;   binance.ws.constantsr	   binance.ws.keepalive_websocketr
   !binance.ws.reconnecting_websocketr   binance.ws.threaded_streamr   binance.async_clientr   binance.enumsr   r   binance.helpersr   r   r   r$   r  r    r!   r"   <module>r     s[       6 6  2 = C 9 - % & $T E" E"P&t
1 t
r!   