ThreadedWebsocketManager does not require asyncio programming, while BinanceSocketManager does.
ThreadedWebsocketManager function begin with start_ , binance qr-kode werk nie e.g start_ticker_socket while BinanceSocketManager is simply ticker_socket .
Multiple socket connections can be made through either manager.
Only one instance of each socket type will be created, i.e. only one BNBBTC Depth socket can be created and there can be both a BNBBTC Depth and binance Bot iwwerschaffen a BNBBTC Trade socket open at once.
Messages are received as dictionary objects relating to the message formats defined in the Binance WebSocket API documentation.
Websockets are setup to reconnect with a maximum of 5 retries with an exponential backoff strategy.
ThreadedWebsocketManager Websocket Usage¶
Starting sockets on the ThreadedWebsocketManager requires a callback parameter, similar to the old implementations of websockets on python-binance.
ThreadedWebsocketManager takes similar parameters to the Client class as it creates an AsyncClient internally.
authenticated streams api_key and api_stream are required.
As these use threads start() is required to be called before starting any sockets.
To keep the ThreadedWebsocketManager running, use join() to join it to the main thread.
Stop Individual Stream.
When starting a stream, בינאַנסע ויספרעג ענטפֿערס a name for that stream will be returned. This can be used to stop that individual stream.
Stop All Streams.
Attempting to start a stream after stop is called will not work.
BinanceSocketManager Websocket Usage¶
Create the manager like so, passing an AsyncClient.
Set a custom timeout for the websocket connections.
Manually enter and exit the Asynchronous context manager.
Using a different TLD¶
The ThreadedWebsocketManager can take the tld when created if required.
The BinanceSocketManager uses the same tld value as the AsyncClient that is passed in. To use the ‘us’ tld we can do this.
If the websocket is disconnected and is unable to reconnect, a message is sent to the callback to indicate this. The format is.
Create a socket combining multiple streams.
These streams can include the depth, binance hashrate belirteci kline, binance có dogecoin ticker and trade streams but not the user stream which requires extra authentication.
Symbols in socket name must be lowercase i.e bnbbtc @ aggTrade, neobtc @ ticker.
Depth sockets have an optional depth parameter to receive partial book rather than a diff response. By default this the diff response is returned. Valid depth values are 5, 10 and 20 and محدودیت های binance kyc defined as enums.
Kline sockets have an optional interval parameter. By default this is set to 1 minute. Valid interval values are defined as enums.