mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-23 08:44:25 +01:00
Add bfxapi/utils subpackage. Add bfxapi/utils/logger.py. Implement logger with log_level in BfxWebsocketClient.py.
This commit is contained in:
@@ -6,6 +6,8 @@ from .handlers import Channels, PublicChannelsHandler, AuthenticatedChannelsHand
|
||||
|
||||
from .errors import ConnectionNotOpen, WebsocketAuthenticationRequired, InvalidAuthenticationCredentials, EventNotSupported, OutdatedClientVersion
|
||||
|
||||
from ..utils.logger import CustomLogger
|
||||
|
||||
HEARTBEAT = "hb"
|
||||
|
||||
def _require_websocket_connection(function):
|
||||
@@ -36,7 +38,7 @@ class BfxWebsocketClient(object):
|
||||
*AuthenticatedChannelsHandler.EVENTS
|
||||
]
|
||||
|
||||
def __init__(self, host, API_KEY=None, API_SECRET=None):
|
||||
def __init__(self, host, log_level = "INFO", API_KEY=None, API_SECRET=None):
|
||||
self.host, self.chanIds, self.event_emitter = host, dict(), AsyncIOEventEmitter()
|
||||
|
||||
self.websocket, self.API_KEY, self.API_SECRET = None, API_KEY, API_SECRET
|
||||
@@ -48,6 +50,8 @@ class BfxWebsocketClient(object):
|
||||
"authenticated": AuthenticatedChannelsHandler(event_emitter=self.event_emitter)
|
||||
}
|
||||
|
||||
self.logger = CustomLogger("BfxWebsocketClient", logLevel=log_level)
|
||||
|
||||
async def connect(self):
|
||||
async for websocket in websockets.connect(self.host):
|
||||
self.websocket = websocket
|
||||
@@ -127,7 +131,7 @@ class BfxWebsocketClient(object):
|
||||
|
||||
def on(self, event):
|
||||
if event not in BfxWebsocketClient.EVENTS:
|
||||
raise EventNotSupported(f"Event <{event}> is not supported. To get a list of available events use BfxWebsocketClient.EVENTS.")
|
||||
raise EventNotSupported(f"Event <{event}> is not supported. To get a list of available events print BfxWebsocketClient.EVENTS")
|
||||
|
||||
def handler(function):
|
||||
self.event_emitter.on(event, function)
|
||||
@@ -136,7 +140,7 @@ class BfxWebsocketClient(object):
|
||||
|
||||
def once(self, event):
|
||||
if event not in BfxWebsocketClient.EVENTS:
|
||||
raise EventNotSupported(f"Event <{event}> is not supported. To get a list of available events use BfxWebsocketClient.EVENTS.")
|
||||
raise EventNotSupported(f"Event <{event}> is not supported. To get a list of available events print BfxWebsocketClient.EVENTS")
|
||||
|
||||
def handler(function):
|
||||
self.event_emitter.once(event, function)
|
||||
|
||||
Reference in New Issue
Block a user