binance-futures-connector-python
binance-futures-connector-python copied to clipboard
onClose callback
from binance.websocket.futures.websocket_client import FuturesWebsocketClient
ws_client = WebsocketClient()
ws_client.instant_subscribe(
stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'],
callback=message_handler,
)
websocket接口怎么做掉线重连?在哪里指定onClose回调函数?
How can I set an onCLose() callback function for FuturesWebsocketClient? I want to reconnect to the server when I loss the connect.
Hello, have you solved this issue?
Hello, have you solved this issue?
No, it seems to have some functions to deal with connection lost, but not customizable.
You may use is_alive() with a loop to check if the connection is not closed.
while True:
if ws_client.is_alive():
time.sleep(1)
else:
print('WS closed')
break