mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
Emit on_disconnection event on connection close in BfxWebsocketClient.
This commit is contained in:
@@ -56,7 +56,7 @@ class BfxWebsocketClient:
|
||||
MAXIMUM_CONNECTIONS_AMOUNT = 20
|
||||
|
||||
EVENTS = [
|
||||
"open", "subscribed", "authenticated", "wss-error",
|
||||
"open", "subscribed", "authenticated", "disconnection", "wss-error",
|
||||
*PublicChannelsHandler.EVENTS,
|
||||
*AuthenticatedChannelsHandler.EVENTS
|
||||
]
|
||||
@@ -68,10 +68,10 @@ class BfxWebsocketClient:
|
||||
|
||||
self.event_emitter = AsyncIOEventEmitter()
|
||||
|
||||
self.inputs = BfxWebsocketInputs(handle_websocket_input=self.__handle_websocket_input)
|
||||
|
||||
self.handler = AuthenticatedChannelsHandler(event_emitter=self.event_emitter)
|
||||
|
||||
self.inputs = BfxWebsocketInputs(handle_websocket_input=self.__handle_websocket_input)
|
||||
|
||||
if log_filename is None:
|
||||
self.logger = ColorLogger("BfxWebsocketClient", level=log_level)
|
||||
else: self.logger = FileLogger("BfxWebsocketClient", level=log_level, filename=log_filename)
|
||||
@@ -178,7 +178,8 @@ class BfxWebsocketClient:
|
||||
try:
|
||||
await _connection()
|
||||
except (websockets.exceptions.ConnectionClosedError, socket.gaierror) as error:
|
||||
if isinstance(error, websockets.exceptions.ConnectionClosedError) and error.code in (1006, 1012):
|
||||
if isinstance(error, websockets.exceptions.ConnectionClosedError):
|
||||
if error.code in (1006, 1012):
|
||||
if error.code == 1006:
|
||||
self.logger.error("Connection lost: no close frame received " \
|
||||
"or sent (1006). Attempting to reconnect...")
|
||||
@@ -202,6 +203,9 @@ class BfxWebsocketClient:
|
||||
else: raise error
|
||||
|
||||
if not reconnection.status:
|
||||
self.event_emitter.emit("disconnection",
|
||||
self.websocket.close_code, self.websocket.close_reason)
|
||||
|
||||
break
|
||||
|
||||
async def __authenticate(self, api_key, api_secret, filters=None):
|
||||
|
||||
Reference in New Issue
Block a user