mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Implement bfxapi/notifications.py in websocket subpackage.
This commit is contained in:
@@ -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))
|
||||
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))
|
||||
@@ -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=[
|
||||
@@ -293,18 +295,3 @@ BalanceInfo = _Serializer[typings.BalanceInfo]("BalanceInfo", labels=[
|
||||
])
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serializers definition for Notifications channel
|
||||
|
||||
Notification = _Serializer[typings.Notification]("Notification", labels=[
|
||||
"MTS",
|
||||
"TYPE",
|
||||
"MESSAGE_ID",
|
||||
"_PLACEHOLDER",
|
||||
"NOTIFY_INFO",
|
||||
"CODE",
|
||||
"STATUS",
|
||||
"TEXT"
|
||||
])
|
||||
|
||||
#endregion
|
||||
@@ -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
|
||||
@@ -273,16 +275,3 @@ class BalanceInfo(TypedDict):
|
||||
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
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user