Add and implement notification.py in root package (bfxapi).

This commit is contained in:
Davide Casale
2022-12-22 18:24:56 +01:00
parent d5ace49555
commit 4f63f4068e
5 changed files with 41 additions and 33 deletions

View File

@@ -1,5 +1,7 @@
import time, hmac, hashlib, json, requests
from decimal import Decimal
from datetime import datetime
from http import HTTPStatus
from typing import List, Union, Literal, Optional, Any, cast
@@ -10,6 +12,8 @@ from .typings import *
from .enums import OrderType, Config, Precision, Sort
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
from .. utils.integers import Int16, Int32, Int45, Int64
from .. utils.encoder import JSONEncoder
class BfxRestInterface(object):
@@ -254,7 +258,7 @@ class _RestAuthenticatedEndpoints(_Requests):
"flags": flags, "tif": tif, "meta": meta
}
return serializers.Notification.parse(*self._POST("auth/w/order/submit", data=data))
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/submit", data=data))
def update_order(self, id: Union[Int64, int], amount: Optional[Union[Decimal, str]] = None, price: Optional[Union[Decimal, str]] = None,
cid: Optional[Union[Int45, int]] = None, cid_date: Optional[str] = None, gid: Optional[Union[Int32, int]] = None,
@@ -267,7 +271,7 @@ class _RestAuthenticatedEndpoints(_Requests):
"price_aux_limit": price_aux_limit, "price_trailing": price_trailing, "tif": tif
}
return serializers.Notification.parse(*self._POST("auth/w/order/update", data=data))
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/update", data=data))
def cancel_order(self, id: Union[Int64, int]) -> Notification:
return serializers.Notification.parse(*self._POST("auth/w/order/cancel", data={ "id": id }))
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/cancel", data={ "id": id }))

View File

@@ -2,6 +2,8 @@ from . import typings
from .. labeler import _Serializer
from .. notification import _Notification
#region Serializers definition for Rest Public Endpoints
PlatformStatus = _Serializer[typings.PlatformStatus]("PlatformStatus", labels=[
@@ -232,19 +234,4 @@ Order = _Serializer[typings.Order]("Order", labels=[
"META"
])
#endregion
#region Serializers definition for Notifications channel
Notification = _Serializer[typings.Notification]("Notification", labels=[
"MTS",
"TYPE",
"MESSAGE_ID",
"_PLACEHOLDER",
"NOTIFY_INFO",
"CODE",
"STATUS",
"TEXT"
])
#endregion

View File

@@ -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 Rest Public Endpoints
@@ -167,17 +169,4 @@ class Order(TypedDict):
ROUTING: str
META: JSON
#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