diff --git a/bfxapi/client.py b/bfxapi/client.py index 104388d..d019e90 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -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, diff --git a/bfxapi/websocket/BfxWebsocketClient.py b/bfxapi/websocket/BfxWebsocketClient.py index 0884c6f..e8bb4d0 100644 --- a/bfxapi/websocket/BfxWebsocketClient.py +++ b/bfxapi/websocket/BfxWebsocketClient.py @@ -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())