22import time
33from enum import Enum
44from typing import Optional , List , Dict , Callable , Any
5+ import logging
56
67from binance .ws .constants import KEEPALIVE_TIMEOUT
78from binance .ws .keepalive_websocket import KeepAliveWebsocket
@@ -40,10 +41,11 @@ class BinanceSocketManager:
4041 WEBSOCKET_DEPTH_20 = "20"
4142
4243 def __init__ (
43- self ,
44- client : AsyncClient ,
44+ self ,
45+ client : AsyncClient ,
4546 user_timeout = KEEPALIVE_TIMEOUT ,
4647 max_queue_size : int = 100 ,
48+ verbose : bool = False ,
4749 ):
4850 """Initialise the BinanceSocketManager
4951
@@ -52,6 +54,8 @@ def __init__(
5254 :param user_timeout: Timeout for user socket in seconds
5355 :param max_queue_size: Max size of the websocket queue, defaults to 100
5456 :type max_queue_size: int
57+ :param verbose: Enable verbose logging for WebSocket connections
58+ :type verbose: bool
5559 """
5660 self .STREAM_URL = self .STREAM_URL .format (client .tld )
5761 self .FSTREAM_URL = self .FSTREAM_URL .format (client .tld )
@@ -65,8 +69,12 @@ def __init__(
6569 self .testnet = self ._client .testnet
6670 self .demo = self ._client .demo
6771 self ._max_queue_size = max_queue_size
72+ self .verbose = verbose
6873 self .ws_kwargs = {}
6974
75+ if verbose :
76+ logging .getLogger ('binance.ws' ).setLevel (logging .DEBUG )
77+
7078 def _get_stream_url (self , stream_url : Optional [str ] = None ):
7179 if stream_url :
7280 return stream_url
@@ -872,7 +880,7 @@ def multiplex_socket(self, streams: List[str]):
872880
873881 def options_multiplex_socket (self , streams : List [str ]):
874882 """Start a multiplexed socket using a list of socket names.
875-
883+
876884 https://developers.binance.com/docs/derivatives/option/websocket-market-streams
877885
878886 """
@@ -967,7 +975,6 @@ def margin_socket(self):
967975 stream_url = self .STREAM_DEMO_URL
968976 return self ._get_account_socket ("margin" , stream_url = stream_url )
969977
970-
971978 def futures_socket (self ):
972979 """Start a websocket for futures data
973980
@@ -1041,7 +1048,7 @@ def options_ticker_socket(self, symbol: str):
10411048
10421049 API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER
10431050
1044- Stream provides real-time 24hr ticker information for all symbols. Only symbols whose ticker info
1051+ Stream provides real-time 24hr ticker information for all symbols. Only symbols whose ticker info
10451052 changed will be sent. Updates every 1000ms.
10461053
10471054 :param symbol: The option symbol to subscribe to (e.g. "BTC-220930-18000-C")
@@ -1066,7 +1073,7 @@ def options_ticker_by_expiration_socket(self, symbol: str, expiration_date: str)
10661073
10671074 def options_recent_trades_socket (self , symbol : str ):
10681075 """Subscribe to a real-time trade information stream.
1069-
1076+
10701077 API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Trade-Streams
10711078
10721079 Stream pushes raw trade information for a specific symbol or underlying asset.
@@ -1081,7 +1088,7 @@ def options_kline_socket(
10811088 self , symbol : str , interval = AsyncClient .KLINE_INTERVAL_1MINUTE
10821089 ):
10831090 """Subscribe to a Kline/Candlestick data stream.
1084-
1091+
10851092 API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Kline-Candlestick-Streams
10861093
10871094 Stream pushes updates to the current klines/candlestick every 1000ms (if existing).
0 commit comments