Add pause/resume logic in class BfxWebSocketClient.

This commit is contained in:
Davide Casale
2023-10-13 17:03:36 +02:00
parent 122d692684
commit 374b632c6c
2 changed files with 26 additions and 22 deletions

View File

@@ -78,7 +78,9 @@ class BfxWebSocketClient(Connection):
super().__init__(host)
self.__credentials, self.__timeout, self.__logger = \
credentials, timeout, logger
credentials, \
timeout, \
logger
self.__buckets: Dict[BfxWebSocketBucket, Optional[Task]] = { }
@@ -99,15 +101,16 @@ class BfxWebSocketClient(Connection):
stack_trace = traceback.format_exception( \
type(exception), exception, exception.__traceback__)
self.__logger.critical( \
header + "\n" + str().join(stack_trace)[:-1])
self.__logger.critical(header + "\n" + \
str().join(stack_trace)[:-1])
@property
def inputs(self) -> BfxWebSocketInputs:
return self.__inputs
def run(self) -> None:
return asyncio.run(self.start())
return asyncio.get_event_loop() \
.run_until_complete(self.start())
#pylint: disable-next=too-many-branches
async def start(self) -> None:

View File

@@ -9,9 +9,9 @@ from pyee.asyncio import AsyncIOEventEmitter
from bfxapi.websocket.exceptions import UnknownEventError
_ONCE_PER_CONNECTION = [
"open", "authenticated", "disconnected",
"order_snapshot", "position_snapshot", "funding_offer_snapshot",
"funding_credit_snapshot", "funding_loan_snapshot", "wallet_snapshot"
"open", "authenticated", "order_snapshot",
"position_snapshot", "funding_offer_snapshot", "funding_credit_snapshot",
"funding_loan_snapshot", "wallet_snapshot"
]
_ONCE_PER_SUBSCRIPTION = [
@@ -21,25 +21,26 @@ _ONCE_PER_SUBSCRIPTION = [
]
_COMMON = [
"error", "wss-error", "t_ticker_update",
"f_ticker_update", "t_trade_execution", "t_trade_execution_update",
"f_trade_execution", "f_trade_execution_update", "t_book_update",
"f_book_update", "t_raw_book_update", "f_raw_book_update",
"candles_update", "derivatives_status_update", "liquidation_feed_update",
"order_new", "order_update", "order_cancel",
"position_new", "position_update", "position_close",
"funding_offer_new", "funding_offer_update", "funding_offer_cancel",
"funding_credit_new", "funding_credit_update", "funding_credit_close",
"funding_loan_new", "funding_loan_update", "funding_loan_close",
"trade_execution", "trade_execution_update", "wallet_update",
"notification", "on-req-notification", "ou-req-notification",
"oc-req-notification", "fon-req-notification", "foc-req-notification"
"error", "wss-error", "disconnected",
"t_ticker_update", "f_ticker_update", "t_trade_execution",
"t_trade_execution_update", "f_trade_execution", "f_trade_execution_update",
"t_book_update", "f_book_update", "t_raw_book_update",
"f_raw_book_update", "candles_update", "derivatives_status_update",
"liquidation_feed_update", "order_new", "order_update",
"order_cancel", "position_new", "position_update",
"position_close", "funding_offer_new", "funding_offer_update",
"funding_offer_cancel", "funding_credit_new", "funding_credit_update",
"funding_credit_close", "funding_loan_new", "funding_loan_update",
"funding_loan_close", "trade_execution", "trade_execution_update",
"wallet_update", "notification", "on-req-notification",
"ou-req-notification", "oc-req-notification", "fon-req-notification",
"foc-req-notification"
]
class BfxEventEmitter(AsyncIOEventEmitter):
_EVENTS = _ONCE_PER_CONNECTION + \
_ONCE_PER_SUBSCRIPTION + \
_COMMON
_ONCE_PER_SUBSCRIPTION + \
_COMMON
def __init__(self, loop: Optional[AbstractEventLoop] = None) -> None:
super().__init__(loop)