Passthrough all **kwargs `Struct.to_dict()`

Since for symcache-ing we don't want to write non-member fields we need
to allow passing the appropriate flag; i hate frickin inheritance XD
account_tests
Tyler Goodlet 2023-07-14 20:29:05 -04:00
parent b9fec091ca
commit 69314e9fca
1 changed files with 13 additions and 7 deletions

View File

@ -132,8 +132,11 @@ class Asset(Struct, frozen=True):
# `None` is not toml-compat so drop info
# if no extra data added..
def to_dict(self) -> dict:
dct = super().to_dict()
def to_dict(
self,
**kwargs,
) -> dict:
dct = super().to_dict(**kwargs)
if (info := dct.pop('info', None)):
dct['info'] = info
@ -145,7 +148,7 @@ class Asset(Struct, frozen=True):
cls,
msg: dict[str, Any],
) -> Asset:
return Asset(
return cls(
tx_tick=Decimal(str(msg.pop('tx_tick'))),
info=msg.pop('info', None),
**msg,
@ -318,10 +321,13 @@ class MktPair(Struct, frozen=True):
def __str__(self) -> str:
return self.fqme
def to_dict(self) -> dict:
d = super().to_dict()
d['src'] = self.src.to_dict()
d['dst'] = self.dst.to_dict()
def to_dict(
self,
**kwargs,
) -> dict:
d = super().to_dict(**kwargs)
d['src'] = self.src.to_dict(**kwargs)
d['dst'] = self.dst.to_dict(**kwargs)
d['price_tick'] = str(self.price_tick)
d['size_tick'] = str(self.size_tick)