Crypto-toolbox / btfxwss

Bitfinex Websocket API Client written in Python3
MIT License
284 stars 125 forks source link

how to reconnect properly #154

Open yufeng0528 opened 6 years ago

yufeng0528 commented 6 years ago
    while True:
        tpool.starmap(get_data_from_websocket, task_list)

        if wss.conn and wss.conn.connected.is_set():
            time.sleep(5)
        else:
            wss = wss.reset()
            time.sleep(10)

and when the connection is close got unlimited print as below

INFO:btfxwss.client:reset(): Waiting for connection to be set up..
INFO:btfxwss.client:reset(): Waiting for connection to be set up..
INFO:btfxwss.client:reset(): Waiting for connection to be set up..
INFO:btfxwss.client:reset(): Waiting for connection to be set up..
INFO:btfxwss.client:reset(): Waiting for connection to be set up..
INFO:btfxwss.client:reset(): Waiting for connection to be set up..

what's wrong with my code, or right way to reconnect?

deepbrook commented 6 years ago

Hey @yufeng0528 , reconnection should be handled by btfwss automatically. Check out the latest version, which should have any issues with this function fixed.

Cheers, Nils

yufeng0528 commented 6 years ago

thanks for your reply you mean that

if wss.conn and wss.conn.connected.is_set():
            time.sleep(5)
        else:
            wss = wss.reset()
            time.sleep(10)

is useless ? i will verify it

VictorHVS commented 6 years ago

Any news guys?

2018-09-27 14:01:38,751 - btfxwss.connection - INFO - Connection opened
2018-09-27 14:01:38,752 - btfxwss.connection - INFO - Connection Error - filedescriptor out of range in select()
2018-09-27 14:01:38,752 - websocket - ERROR - close status: 31522
2018-09-27 14:01:38,753 - btfxwss.connection - INFO - Connection is closed by Bitfinex.
2018-09-27 14:01:38,754 - btfxwss.connection - INFO - Attempting to connect again in 10 seconds.
2018-09-27 14:01:50,118 - btfxwss.connection - INFO - Connection opened
2018-09-27 14:01:50,119 - btfxwss.connection - INFO - _on_open(): Connection reconnected, re-subscribing..
2018-09-27 14:01:50,119 - btfxwss.connection - INFO - Connection Error - filedescriptor out of range in select()
2018-09-27 14:01:50,119 - websocket - ERROR - close status: 31522
2018-09-27 14:01:50,120 - btfxwss.connection - INFO - Connection is closed by Bitfinex.
2018-09-27 14:01:50,122 - btfxwss.connection - INFO - Attempting to connect again in 10 seconds.
2018-09-27 14:02:00,666 - btfxwss.connection - INFO - Connection opened
2018-09-27 14:02:00,666 - btfxwss.connection - INFO - Connection Error - filedescriptor out of range in select()
2018-09-27 14:02:00,667 - websocket - ERROR - close status: 31522
2018-09-27 14:02:00,667 - btfxwss.connection - INFO - Connection is closed normally.