mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
Fix bug in BfxWebsocketClient::close (bfxapi.websocket.client.bfx_websocket_client).
This commit is contained in:
@@ -61,7 +61,7 @@ class BfxWebsocketBucket:
|
||||
|
||||
try:
|
||||
await _connection()
|
||||
except websockets.ConnectionClosedError as error:
|
||||
except websockets.exceptions.ConnectionClosedError as error:
|
||||
if error.code in (1006, 1012):
|
||||
self.on_open_event.clear()
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ class BfxWebsocketClient:
|
||||
rcvd = websockets.frames.Close(code=1012,
|
||||
reason="Stop/Restart Websocket Server (please reconnect).")
|
||||
|
||||
raise websockets.ConnectionClosedError(rcvd=rcvd, sent=None)
|
||||
raise websockets.exceptions.ConnectionClosedError(rcvd=rcvd, sent=None)
|
||||
elif message["event"] == "auth":
|
||||
if message["status"] != "OK":
|
||||
raise InvalidAuthenticationCredentials(
|
||||
@@ -177,8 +177,8 @@ class BfxWebsocketClient:
|
||||
|
||||
try:
|
||||
await _connection()
|
||||
except (websockets.ConnectionClosedError, socket.gaierror) as error:
|
||||
if isinstance(error, websockets.ConnectionClosedError) and error.code in (1006, 1012):
|
||||
except (websockets.exceptions.ConnectionClosedError, socket.gaierror) as error:
|
||||
if isinstance(error, websockets.exceptions.ConnectionClosedError) and error.code in (1006, 1012):
|
||||
if error.code == 1006:
|
||||
self.logger.error("Connection lost: no close frame received " \
|
||||
"or sent (1006). Attempting to reconnect...")
|
||||
@@ -235,12 +235,12 @@ class BfxWebsocketClient:
|
||||
await bucket.unsubscribe(chan_id=chan_id)
|
||||
|
||||
async def close(self, code=1000, reason=str()):
|
||||
if self.websocket is not None and self.websocket.open:
|
||||
await self.websocket.close(code=code, reason=reason)
|
||||
|
||||
for bucket in self.buckets:
|
||||
await bucket.close(code=code, reason=reason)
|
||||
|
||||
if self.websocket is not None and self.websocket.open:
|
||||
await self.websocket.close(code=code, reason=reason)
|
||||
|
||||
@_require_websocket_authentication
|
||||
async def notify(self, info, message_id=None, **kwargs):
|
||||
await self.websocket.send(json.dumps([ 0, "n", message_id, { "type": "ucm-test", "info": info, **kwargs } ]))
|
||||
|
||||
Reference in New Issue
Block a user