Explicitly decode tick sizes as decimal for symbol loading in `Flume`

rekt_pps
Tyler Goodlet 2023-03-20 21:25:42 -04:00
parent 335e8d10d4
commit 7a8e615fa6
1 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,7 @@ real-time data processing data-structures.
"""
from __future__ import annotations
from decimal import Decimal
from typing import (
TYPE_CHECKING,
)
@ -172,7 +173,11 @@ class Flume(Struct):
# TODO: get native msgspec decoding for these workinn
def to_msg(self) -> dict:
msg = self.to_dict()
# TODO: do we even need to convert to dict
# first now?
msg['symbol'] = msg['symbol'].to_dict()
# can't serialize the stream or feed objects, it's expected
@ -184,7 +189,14 @@ class Flume(Struct):
@classmethod
def from_msg(cls, msg: dict) -> dict:
# XXX NOTE: ``msgspec`` can encode `Decimal`
# but it doesn't decide to it by default since
# we aren't spec-cing these msgs as structs...
symbol = Symbol(**msg.pop('symbol'))
symbol.tick_size = Decimal(symbol.tick_size)
symbol.lot_tick_size = Decimal(symbol.lot_tick_size)
return cls(
symbol=symbol,
**msg,