Add support for event base_margin_info and symbol_margin_info.

This commit is contained in:
Davide Casale
2024-04-24 16:42:54 +02:00
parent 52f24ffe7d
commit a72a9475c0
5 changed files with 31 additions and 50 deletions

View File

@@ -1,38 +0,0 @@
# file GENERATED by distutils, do NOT edit
setup.py
bfxapi/__init__.py
bfxapi/_client.py
bfxapi/_version.py
bfxapi/exceptions.py
bfxapi/_utils/__init__.py
bfxapi/_utils/json_decoder.py
bfxapi/_utils/json_encoder.py
bfxapi/_utils/logging.py
bfxapi/rest/__init__.py
bfxapi/rest/_bfx_rest_interface.py
bfxapi/rest/exceptions.py
bfxapi/rest/_interface/__init__.py
bfxapi/rest/_interface/interface.py
bfxapi/rest/_interface/middleware.py
bfxapi/rest/_interfaces/__init__.py
bfxapi/rest/_interfaces/rest_auth_endpoints.py
bfxapi/rest/_interfaces/rest_merchant_endpoints.py
bfxapi/rest/_interfaces/rest_public_endpoints.py
bfxapi/types/__init__.py
bfxapi/types/dataclasses.py
bfxapi/types/labeler.py
bfxapi/types/notification.py
bfxapi/types/serializers.py
bfxapi/websocket/__init__.py
bfxapi/websocket/_connection.py
bfxapi/websocket/exceptions.py
bfxapi/websocket/subscriptions.py
bfxapi/websocket/_client/__init__.py
bfxapi/websocket/_client/bfx_websocket_bucket.py
bfxapi/websocket/_client/bfx_websocket_client.py
bfxapi/websocket/_client/bfx_websocket_inputs.py
bfxapi/websocket/_event_emitter/__init__.py
bfxapi/websocket/_event_emitter/bfx_event_emitter.py
bfxapi/websocket/_handlers/__init__.py
bfxapi/websocket/_handlers/auth_events_handler.py
bfxapi/websocket/_handlers/public_channels_handler.py

View File

@@ -248,7 +248,7 @@ class RestAuthEndpoints(Interface):
def get_base_margin_info(self) -> BaseMarginInfo:
return serializers.BaseMarginInfo.parse(
*(self._m.post("auth/r/info/margin/base")[1])
*self._m.post("auth/r/info/margin/base")
)
def get_symbol_margin_info(self, symbol: str) -> SymbolMarginInfo:

View File

@@ -745,7 +745,15 @@ SymbolMarginInfo = generate_labeler_serializer(
BaseMarginInfo = generate_labeler_serializer(
name="BaseMarginInfo",
klass=dataclasses.BaseMarginInfo,
labels=["user_pl", "user_swaps", "margin_balance", "margin_net", "margin_min"],
labels=[
"_PLACEHOLDER",
"user_pl",
"user_swaps",
"margin_balance",
"margin_net",
"margin_min",
],
flat=True,
)
PositionClaim = generate_labeler_serializer(

View File

@@ -64,6 +64,8 @@ _COMMON = [
"trade_execution",
"trade_execution_update",
"wallet_update",
"base_margin_info",
"symbol_margin_info",
"notification",
"on-req-notification",
"ou-req-notification",
@@ -105,7 +107,7 @@ class BfxEventEmitter(AsyncIOEventEmitter):
) -> Union[_Handler, Callable[[_Handler], _Handler]]:
if event not in BfxEventEmitter._EVENTS:
raise UnknownEventError(
f"Can't register to unknown event: <{event}> (to get a full"
f"Can't register to unknown event: <{event}> (to get a full "
"list of available events see https://docs.bitfinex.com/)."
)

View File

@@ -51,17 +51,26 @@ class AuthEventsHandler:
def handle(self, abbrevation: str, stream: Any) -> None:
if abbrevation == "n":
self.__notification(stream)
elif abbrevation == "miu":
if stream[0] == "base":
self.__event_emitter.emit(
"base_margin_info", serializers.BaseMarginInfo.parse(*stream)
)
elif stream[0] == "sym":
self.__event_emitter.emit(
"symbol_margin_info", serializers.SymbolMarginInfo.parse(*stream)
)
else:
for abbrevations, serializer in AuthEventsHandler.__SERIALIZERS.items():
if abbrevation in abbrevations:
event = AuthEventsHandler.__ABBREVIATIONS[abbrevation]
for abbrevations, serializer in AuthEventsHandler.__SERIALIZERS.items():
if abbrevation in abbrevations:
event = AuthEventsHandler.__ABBREVIATIONS[abbrevation]
if all(isinstance(sub_stream, list) for sub_stream in stream):
data = [serializer.parse(*sub_stream) for sub_stream in stream]
else:
data = serializer.parse(*stream)
if all(isinstance(sub_stream, list) for sub_stream in stream):
data = [serializer.parse(*sub_stream) for sub_stream in stream]
else:
data = serializer.parse(*stream)
self.__event_emitter.emit(event, data)
self.__event_emitter.emit(event, data)
def __notification(self, stream: Any) -> None:
event: str = "notification"