Add MAXIMUM_BUCKETS_AMOUNT constant to BfxWebsocketClient class.

This commit is contained in:
Davide Casale
2022-11-30 17:55:10 +01:00
parent 509223ae9b
commit 48f1745f10
2 changed files with 7 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ class Constants(str, Enum):
PUB_WSS_HOST = "wss://api-pub.bitfinex.com/ws/2"
class Client(object):
def __init__(self, WSS_HOST: str = Constants.WSS_HOST, API_KEY: str = None, API_SECRET: str = None, log_level: str = "ERROR"):
def __init__(self, WSS_HOST: str = Constants.WSS_HOST, API_KEY: str = None, API_SECRET: str = None, log_level: str = "WARNING"):
self.wss = BfxWebsocketClient(
host=WSS_HOST,
API_KEY=API_KEY,

View File

@@ -24,13 +24,15 @@ def _require_websocket_connection(function):
class BfxWebsocketClient(object):
VERSION = 2
MAXIMUM_BUCKETS_AMOUNT = 20
EVENTS = [
"open", "subscribed", "authenticated", "wss-error",
*PublicChannelsHandler.EVENTS,
*AuthenticatedChannelsHandler.EVENTS
]
def __init__(self, host, buckets=5, log_level = "ERROR", API_KEY=None, API_SECRET=None, filter=None):
def __init__(self, host, buckets=5, log_level = "WARNING", API_KEY=None, API_SECRET=None, filter=None):
self.host, self.websocket, self.event_emitter = host, None, AsyncIOEventEmitter()
self.event_emitter.add_listener("error",
@@ -47,6 +49,9 @@ class BfxWebsocketClient(object):
self.logger = CustomLogger("BfxWebsocketClient", logLevel=log_level)
if buckets > BfxWebsocketClient.MAXIMUM_BUCKETS_AMOUNT:
self.logger.warning(f"It is not safe to use more than {BfxWebsocketClient.MAXIMUM_BUCKETS_AMOUNT} buckets from the same connection ({buckets} in use), the server could momentarily block the client with <429 Too Many Requests>.")
def run(self):
return asyncio.run(self.start())