binance-futures-connector-python icon indicating copy to clipboard operation
binance-futures-connector-python copied to clipboard

onClose callback

Open fyr233 opened this issue 3 years ago • 2 comments

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.

fyr233 avatar Apr 22 '22 05:04 fyr233

Hello, have you solved this issue?

smeana avatar Jun 08 '22 12:06 smeana

Hello, have you solved this issue?

No, it seems to have some functions to deal with connection lost, but not customizable.

fyr233 avatar Jun 18 '22 13:06 fyr233

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

Sharaddition avatar Nov 10 '22 19:11 Sharaddition