diff --git a/bfxapi/websocket/handlers.py b/bfxapi/websocket/handlers.py index 9edd986..83c1408 100644 --- a/bfxapi/websocket/handlers.py +++ b/bfxapi/websocket/handlers.py @@ -146,7 +146,13 @@ class AuthenticatedChannelsHandler(object): ("bu",): serializers.BalanceInfo } - EVENTS = [ "notification", *list(__abbreviations.values()) ] + EVENTS = [ + "notification", + "on-req-notification", "ou-req-notification", "oc-req-notification", + "oc_multi-notification", + "fon-req-notification", "foc-req-notification", + *list(__abbreviations.values()) + ] def __init__(self, event_emitter, strict = False): self.event_emitter, self.strict = event_emitter, strict @@ -168,4 +174,13 @@ class AuthenticatedChannelsHandler(object): raise BfxWebsocketException(f"Event of type <{type}> not found in self.__handlers.") def __notification(self, stream): - return self.event_emitter.emit("notification", serializers.Notification.parse(*stream)) \ No newline at end of file + if stream[1] == "on-req" or stream[1] == "ou-req" or stream[1] == "oc-req": + return self.event_emitter.emit(f"{stream[1]}-notification", serializers._Notification(serializer=serializers.Order).parse(*stream)) + + if stream[1] == "oc_multi-req": + return self.event_emitter.emit(f"{stream[1]}-notification", serializers._Notification(serializer=serializers.Order, iterate=True).parse(*stream)) + + if stream[1] == "fon-req" or stream[1] == "foc-req": + return self.event_emitter.emit(f"{stream[1]}-notification", serializers._Notification(serializer=serializers.FundingOffer).parse(*stream)) + + return self.event_emitter.emit("notification", serializers._Notification(serializer=None).parse(*stream)) \ No newline at end of file diff --git a/bfxapi/websocket/serializers.py b/bfxapi/websocket/serializers.py index 00f43d2..a9dd805 100644 --- a/bfxapi/websocket/serializers.py +++ b/bfxapi/websocket/serializers.py @@ -2,6 +2,8 @@ from . import typings from .. labeler import _Serializer +from .. notification import _Notification + #region Serializers definition for Websocket Public Channels TradingPairTicker = _Serializer[typings.TradingPairTicker]("TradingPairTicker", labels=[ @@ -292,19 +294,4 @@ BalanceInfo = _Serializer[typings.BalanceInfo]("BalanceInfo", labels=[ "AUM_NET", ]) -#endregion - -#region Serializers definition for Notifications channel - -Notification = _Serializer[typings.Notification]("Notification", labels=[ - "MTS", - "TYPE", - "MESSAGE_ID", - "_PLACEHOLDER", - "NOTIFY_INFO", - "CODE", - "STATUS", - "TEXT" -]) - #endregion \ No newline at end of file diff --git a/bfxapi/websocket/typings.py b/bfxapi/websocket/typings.py index 3488cd4..ced6aaa 100644 --- a/bfxapi/websocket/typings.py +++ b/bfxapi/websocket/typings.py @@ -1,5 +1,7 @@ from typing import Type, Tuple, List, Dict, TypedDict, Union, Optional, Any +from .. notification import Notification + JSON = Union[Dict[str, "JSON"], List["JSON"], bool, int, float, str, Type[None]] #region Type hinting for subscription objects @@ -272,17 +274,4 @@ class BalanceInfo(TypedDict): AUM: float AUM_NET: float -#endregion - -#region Type hinting for Notifications channel - -class Notification(TypedDict): - MTS: int - TYPE: str - MESSAGE_ID: int - NOTIFY_INFO: JSON - CODE: int - STATUS: str - TEXT: str - #endregion \ No newline at end of file diff --git a/examples/websocket/create_order.py b/examples/websocket/create_order.py index 92ede22..b3146e9 100644 --- a/examples/websocket/create_order.py +++ b/examples/websocket/create_order.py @@ -4,7 +4,7 @@ import os from bfxapi.client import Client, Constants from bfxapi.websocket.enums import Error, OrderType -from bfxapi.websocket.typings import Order +from bfxapi.websocket.typings import Notification, Order bfx = Client( WSS_HOST=Constants.WSS_HOST, @@ -29,8 +29,8 @@ async def on_authenticated(event): print("The order has been sent.") -@bfx.wss.on("notification") -async def on_notification(notification): +@bfx.wss.on("on-req-notification") +async def on_notification(notification: Notification): print(f"Notification: {notification}.") @bfx.wss.on("order_new")