Change `Flume.symbol` -> `.mkt: MktPair`

Might as well try and flip it over to the new type; make appropriate
dict serialization changes in `.to_msg()`. Alias back to `.symbol:
Symbol` with a property.
rekt_pps
Tyler Goodlet 2023-04-14 01:45:42 -04:00
parent b1e162ebb4
commit 611d86d988
1 changed files with 20 additions and 14 deletions

View File

@ -35,6 +35,9 @@ from ..accounting._mktinfo import (
MktPair, MktPair,
Symbol, Symbol,
) )
from ..log import (
get_logger,
)
from .types import Struct from .types import Struct
from ._sharedmem import ( from ._sharedmem import (
attach_shm_array, attach_shm_array,
@ -50,6 +53,8 @@ if TYPE_CHECKING:
# from pyqtgraph import PlotItem # from pyqtgraph import PlotItem
from .feed import Feed from .feed import Feed
log = get_logger(__name__)
# TODO: ideas for further abstractions as per # TODO: ideas for further abstractions as per
# https://github.com/pikers/piker/issues/216 and # https://github.com/pikers/piker/issues/216 and
@ -91,10 +96,18 @@ class Flume(Struct):
queuing properties. queuing properties.
''' '''
symbol: Symbol | MktPair mkt: MktPair | Symbol
first_quote: dict first_quote: dict
_rt_shm_token: _Token _rt_shm_token: _Token
@property
def symbol(self) -> MktPair | Symbol:
log.warning(
'`Flume.symbol` is deprecated!\n'
'Use `.mkt: MktPair` instead!'
)
return self.mkt
# optional since some data flows won't have a "downsampled" history # optional since some data flows won't have a "downsampled" history
# buffer/stream (eg. FSPs). # buffer/stream (eg. FSPs).
_hist_shm_token: _Token | None = None _hist_shm_token: _Token | None = None
@ -176,14 +189,7 @@ class Flume(Struct):
def to_msg(self) -> dict: def to_msg(self) -> dict:
msg = self.to_dict() msg = self.to_dict()
msg['mkt'] = self.mkt.to_dict()
# TODO: do we even need to convert to dict
# first now?
# TODO: drop the former.
msg['symbol'] = msg['symbol'].to_dict()
mktpair = msg.get('mktpair')
if mktpair:
msg['mktpair'] = mktpair.to_dict()
# can't serialize the stream or feed objects, it's expected # can't serialize the stream or feed objects, it's expected
# you'll have a ref to it since this msg should be rxed on # you'll have a ref to it since this msg should be rxed on
@ -203,10 +209,10 @@ class Flume(Struct):
`msgspec.Struct` form. `msgspec.Struct` form.
''' '''
sym_msg = msg.pop('symbol') mkt_msg = msg.pop('mkt')
if 'dst' in sym_msg: if 'dst' in mkt_msg:
mkt = MktPair.from_msg(sym_msg) mkt = MktPair.from_msg(mkt_msg)
else: else:
# XXX NOTE: ``msgspec`` can encode `Decimal` # XXX NOTE: ``msgspec`` can encode `Decimal`
@ -214,9 +220,9 @@ class Flume(Struct):
# we aren't spec-cing these msgs as structs, SO # we aren't spec-cing these msgs as structs, SO
# we have to ensure we do a struct type case (which `.copy()` # we have to ensure we do a struct type case (which `.copy()`
# does) to ensure we get the right type! # does) to ensure we get the right type!
mkt = Symbol(**sym_msg).copy() mkt = Symbol(**mkt_msg).copy()
return cls(symbol=mkt, **msg) return cls(mkt=mkt, **msg)
def get_index( def get_index(
self, self,