Optionally load `MktPair` in `Flume`s
parent
2cc80d53ca
commit
452cd7db8a
|
@ -22,7 +22,7 @@ real-time data processing data-structures.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from decimal import Decimal
|
# from decimal import Decimal
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
)
|
)
|
||||||
|
@ -193,19 +193,30 @@ class Flume(Struct):
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_msg(cls, msg: dict) -> dict:
|
def from_msg(
|
||||||
|
cls,
|
||||||
|
msg: dict,
|
||||||
|
|
||||||
# XXX NOTE: ``msgspec`` can encode `Decimal`
|
) -> dict:
|
||||||
# but it doesn't decide to it by default since
|
'''
|
||||||
# we aren't spec-cing these msgs as structs...
|
Load from an IPC msg presumably in either `dict` or
|
||||||
symbol = Symbol(**msg.pop('symbol'))
|
`msgspec.Struct` form.
|
||||||
symbol.tick_size = Decimal(symbol.tick_size)
|
|
||||||
symbol.lot_tick_size = Decimal(symbol.lot_tick_size)
|
|
||||||
|
|
||||||
return cls(
|
'''
|
||||||
symbol=symbol,
|
sym_msg = msg.pop('symbol')
|
||||||
**msg,
|
|
||||||
)
|
if 'dst' in sym_msg:
|
||||||
|
mkt = MktPair.from_msg(sym_msg)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# 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, SO
|
||||||
|
# we have to ensure we do a struct type case (which `.copy()`
|
||||||
|
# does) to ensure we get the right type!
|
||||||
|
mkt = Symbol(**sym_msg).copy()
|
||||||
|
|
||||||
|
return cls(symbol=mkt, **msg)
|
||||||
|
|
||||||
def get_index(
|
def get_index(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Reference in New Issue