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

28
bfxapi/notification.py Normal file
View File

@@ -0,0 +1,28 @@
from typing import Dict, Optional, Any, TypedDict, cast
from .labeler import _Serializer
class Notification(TypedDict):
MTS: int
TYPE: str
MESSAGE_ID: Optional[int]
NOTIFY_INFO: Dict[str, Any]
CODE: Optional[int]
STATUS: str
TEXT: str
class _Notification(_Serializer):
__LABELS = [ "MTS", "TYPE", "MESSAGE_ID", "_PLACEHOLDER", "NOTIFY_INFO", "CODE", "STATUS", "TEXT" ]
def __init__(self, serializer: Optional[_Serializer] = None):
super().__init__("Notification", _Notification.__LABELS, IGNORE = [ "_PLACEHOLDER" ])
self.serializer = serializer
def parse(self, *values: Any) -> Notification:
notification = dict(self._serialize(*values))
if self.serializer != None:
notification["NOTIFY_INFO"] = dict(self.serializer._serialize(*notification["NOTIFY_INFO"]))
return cast(Notification, notification)