nardew / cryptoxlib-aio

cryptoxlib-aio - asynchronous python client for various crypto exchanges with full REST API and websocket support. Supported exchanges: AAX, Bibox, BiboxEurope, Binance (spot, margin, USDS-M futures, COIN-M futures, BLVT, BSwap), Bitforex, BitpandaPro, Bitvavo, BTSE, Coinmate, Eterbase, HitBTC, Liquid.
https://pypi.org/project/cryptoxlib-aio/
MIT License
133 stars 37 forks source link

auto reconnection for binance websocket #64

Closed xiandong79 closed 2 years ago

xiandong79 commented 3 years ago

E [2021-06-25 11:01:36,670] ************************************************************
E [2021-06-25 11:01:36,671] [.spot_account_update] ReadTimeout(ReadTimeoutError("HTTPSConnectionPool(host='api.binance.com', port=443): Read timed out. (read timeout=10)")) 
E [2021-06-25 11:01:36,671] ************************************************************
I [2021-06-25 11:01:36,673] [.execute_logic] for UNIUSD_PERP, spot_balance: 11.891,  swap_position: {"platform": "BINANCE", "account": null, "strategy": null, "symbol": "UNIUSD_PERP", "short_quantity": 20657.0, "short_avg_price": 17.352, "long_quantity": 0, "long_avg_price": 0, "liquid_price": 0, "timestamp": 1624618866914} 
E [2021-06-25 11:01:36,678] [3] An exception [] occurred. The websocket manager will be closed.
I [2021-06-25 11:01:36,678] [3] Subscriptions: ['ku1BBJk6y9sDTb8THUVLsnvG8c7vkr9gewfQtuDub5hNCWGmuR0Ccz5fRHLR']
E [2021-06-25 11:01:36,678] Unrecoverable exception occurred while processing messages: 
I [2021-06-25 11:01:36,678] Remaining websocket managers scheduled for shutdown.
I [2021-06-25 11:01:36,679] [2] Exception [<class 'cryptoxlib.exceptions.WebsocketClosed'>]: Websocket was closed: None
E [2021-06-25 11:01:36,679] Task exception was never retrieved
future: <Task finished name='Task-4' coro=<CryptoXLibClient.start_websockets() done, defined at /home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/CryptoXLibClient.py:217> exception=AttributeError("'NoneType' object has no attribute 'close'")>
Traceback (most recent call last):
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/CryptoXLibClient.py", line 233, in start_websockets
    task.result()
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 366, in run
    task.result()
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 331, in main_loop
    await self._process_message(self.websocket, message)
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/clients/binance/BinanceCommonWebsocket.py", line 80, in _process_message
    await self.publish_message(WebsocketMessage(subscription_id = message['stream'], message = message))
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 414, in publish_message
    await subscription.process_message(message)
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 219, in process_message
    await self.process_callbacks(message)
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 231, in process_callbacks
    await asyncio.gather(*tasks)
  File "/home/ubuntu/deployment/strategy/utils/decorator.py", line 43, in wrapper
    return await asyncio.wait_for(method(*args, **kwargs), timeout)
  File "/usr/lib/python3.8/asyncio/tasks.py", line 501, in wait_for
    raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/CryptoXLibClient.py", line 238, in start_websockets
    await self.shutdown_websockets()
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/CryptoXLibClient.py", line 248, in shutdown_websockets
    await subscription_set.websocket_mgr.shutdown()
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 434, in shutdown
    await self.websocket.close()
  File "/home/ubuntu/deployment/cryptoxlib-aio/cryptoxlib/WebsocketMgr.py", line 126, in close
    await self.session.close()
AttributeError: 'NoneType' object has no attribute 'close'
xiandong79 commented 3 years ago

we need to increase the timeout config in for websocket