mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
Add new event liquidation_feed_update to PublicChannelsHandler (and improve overall type hinting).
This commit is contained in:
@@ -129,7 +129,7 @@ class Liquidation(_Type):
|
||||
base_price: float
|
||||
is_match: int
|
||||
is_market_sold: int
|
||||
price_acquired: float
|
||||
liquidation_price: float
|
||||
|
||||
@dataclass
|
||||
class Leaderboard(_Type):
|
||||
|
||||
@@ -230,7 +230,7 @@ Liquidation = generate_labeler_serializer(
|
||||
"is_match",
|
||||
"is_market_sold",
|
||||
"_PLACEHOLDER",
|
||||
"price_acquired"
|
||||
"liquidation_price"
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pylint: disable-next=wildcard-import,unused-wildcard-import
|
||||
from ..enums import *
|
||||
from bfxapi.enums import *
|
||||
|
||||
class Channel(str, Enum):
|
||||
TICKER = "ticker"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from typing import TYPE_CHECKING, \
|
||||
Union, Dict, Tuple, Any
|
||||
Dict, Tuple, Any
|
||||
|
||||
from bfxapi.types import serializers
|
||||
|
||||
@@ -71,14 +71,16 @@ class AuthEventsHandler:
|
||||
break
|
||||
|
||||
def __notification(self, stream: Any) -> None:
|
||||
_Types = Union[None, "Order", "FundingOffer"]
|
||||
event: str = "notification"
|
||||
|
||||
event, serializer = "notification", _Notification[_Types](serializer=None)
|
||||
serializer: _Notification = _Notification[None](serializer=None)
|
||||
|
||||
if stream[1] == "on-req" or stream[1] == "ou-req" or stream[1] == "oc-req":
|
||||
event, serializer = f"{stream[1]}-notification", _Notification[_Types](serializer=serializers.Order)
|
||||
event, serializer = f"{stream[1]}-notification", \
|
||||
_Notification["Order"](serializer=serializers.Order)
|
||||
|
||||
if stream[1] == "fon-req" or stream[1] == "foc-req":
|
||||
event, serializer = f"{stream[1]}-notification", _Notification[_Types](serializer=serializers.FundingOffer)
|
||||
event, serializer = f"{stream[1]}-notification", \
|
||||
_Notification["FundingOffer"](serializer=serializers.FundingOffer)
|
||||
|
||||
self.__event_emitter.emit(event, serializer.parse(*stream))
|
||||
|
||||
@@ -24,7 +24,8 @@ class PublicChannelsHandler:
|
||||
"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"
|
||||
"f_raw_book_update", "candles_update", "derivatives_status_update",
|
||||
"liquidation_feed_update"
|
||||
]
|
||||
|
||||
def __init__(self,
|
||||
@@ -97,7 +98,7 @@ class PublicChannelsHandler:
|
||||
for sub_stream in stream[0] ])
|
||||
|
||||
def __book_channel_handler(self, subscription: "Book", stream: List[Any]) -> None:
|
||||
t_or_f = subscription["symbol"][0]
|
||||
symbol = subscription["symbol"]
|
||||
|
||||
is_raw_book = subscription["prec"] == "R0"
|
||||
|
||||
@@ -106,17 +107,17 @@ class PublicChannelsHandler:
|
||||
or serializers.TradingPairBook,
|
||||
"f": is_raw_book and serializers.FundingCurrencyRawBook \
|
||||
or serializers.FundingCurrencyBook
|
||||
}[t_or_f]
|
||||
}[symbol[0]]
|
||||
|
||||
if all(isinstance(sub_stream, list) for sub_stream in stream[0]):
|
||||
event = t_or_f + "_" + \
|
||||
event = symbol[0] + "_" + \
|
||||
(is_raw_book and "raw_book" or "book") + "_snapshot"
|
||||
|
||||
return self.__emit(event, subscription, \
|
||||
[ serializer.parse(*sub_stream) \
|
||||
for sub_stream in stream[0] ])
|
||||
|
||||
event = t_or_f + "_" + \
|
||||
event = symbol[0] + "_" + \
|
||||
(is_raw_book and "raw_book" or "book") + "_update"
|
||||
|
||||
return self.__emit(event, subscription, \
|
||||
@@ -135,3 +136,7 @@ class PublicChannelsHandler:
|
||||
if subscription["key"].startswith("deriv:"):
|
||||
return self.__emit("derivatives_status_update", subscription, \
|
||||
serializers.DerivativesStatus.parse(*stream[0]))
|
||||
|
||||
if subscription["key"].startswith("liq:"):
|
||||
return self.__emit("liquidation_feed_update", subscription, \
|
||||
serializers.Liquidation.parse(*stream[0][0]))
|
||||
|
||||
Reference in New Issue
Block a user