mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Add MAXIMUM_BUCKETS_AMOUNT constant to BfxWebsocketClient class.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user