From 99783c1a5a2301509f0be1c98b9af2954b2fb181 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Thu, 20 Apr 2023 01:26:25 +0200 Subject: [PATCH] Allow wss_timeout=None to disable timeout on reconnection. --- bfxapi/client.py | 6 +++--- bfxapi/websocket/client/bfx_websocket_client.py | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bfxapi/client.py b/bfxapi/client.py index 8fe3f12..d4ab10b 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -1,4 +1,4 @@ -from typing import List, Optional +from typing import List, Literal, Optional from .rest import BfxRestInterface from .websocket import BfxWebsocketClient @@ -13,9 +13,9 @@ class Client: *, rest_host: str = REST_HOST, wss_host: str = WSS_HOST, - wss_timeout: float = 60 * 15, + wss_timeout: Optional[float] = 60 * 15, log_filename: Optional[str] = None, - log_level: str = "INFO" + log_level: Literal["ERROR", "WARNING", "INFO", "DEBUG"] = "INFO" ): credentials = None diff --git a/bfxapi/websocket/client/bfx_websocket_client.py b/bfxapi/websocket/client/bfx_websocket_client.py index 2c01fb8..5b73e11 100644 --- a/bfxapi/websocket/client/bfx_websocket_client.py +++ b/bfxapi/websocket/client/bfx_websocket_client.py @@ -129,7 +129,8 @@ class BfxWebsocketClient: reconnection = Reconnection(status=False, attempts=0, timestamp=None) - timer.cancel() + if isinstance(timer, asyncio.events.TimerHandle): + timer.cancel() self.websocket = websocket @@ -198,7 +199,10 @@ class BfxWebsocketClient: task.cancel() reconnection = Reconnection(status=True, attempts=1, timestamp=datetime.now()) - timer = asyncio.get_event_loop().call_later(self.wss_timeout, _on_wss_timeout) + + if self.wss_timeout is not None: + timer = asyncio.get_event_loop().call_later(self.wss_timeout, _on_wss_timeout) + delay = _Delay(backoff_factor=1.618) self.authentication = False