Support both input msg-sequence types
The legacy version was a `dict` of `dicts` vs. now we want to be handed a `list[FeedInit]`; process both in a factored way. Drop `FeedInit.bs_mktid` since it's already defined on `.mkt.bs_mktid` and we don't really need it top level.rekt_pps
parent
b4f2f49001
commit
765b8f8e5c
|
@ -48,8 +48,6 @@ class FeedInit(Struct, frozen=True):
|
||||||
from each backend broker/data provider.
|
from each backend broker/data provider.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# backend specific, market endpoint id
|
|
||||||
bs_mktid: str
|
|
||||||
mkt_info: MktPair
|
mkt_info: MktPair
|
||||||
shm_write_opts: dict[str, Any] | None = None
|
shm_write_opts: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
@ -70,13 +68,21 @@ def validate_backend(
|
||||||
that haven't been implemented by this backend yet.
|
that haven't been implemented by this backend yet.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
inits: list[
|
||||||
|
FeedInit | dict[str, Any]
|
||||||
|
] = init_msgs
|
||||||
|
|
||||||
|
# convert to list if from old dict-style
|
||||||
if isinstance(init_msgs, dict):
|
if isinstance(init_msgs, dict):
|
||||||
for i, (sym_str, msg) in enumerate(init_msgs.items()):
|
inits = list(init_msgs.values())
|
||||||
init: FeedInit | dict[str, Any] = msg
|
|
||||||
|
init: FeedInit | dict[str, Any]
|
||||||
|
for i, init in enumerate(inits):
|
||||||
|
|
||||||
# XXX: eventually this WILL NOT necessarily be true.
|
# XXX: eventually this WILL NOT necessarily be true.
|
||||||
if i > 0:
|
if i > 0:
|
||||||
assert not len(init_msgs) == 1
|
assert not len(init_msgs) == 1
|
||||||
|
if isinstance(init_msgs, dict):
|
||||||
keys: set = set(init_msgs.keys()) - set(syms)
|
keys: set = set(init_msgs.keys()) - set(syms)
|
||||||
raise FeedInitializationError(
|
raise FeedInitializationError(
|
||||||
'TOO MANY INIT MSGS!\n'
|
'TOO MANY INIT MSGS!\n'
|
||||||
|
@ -84,6 +90,11 @@ def validate_backend(
|
||||||
'ALL MSGS:\n'
|
'ALL MSGS:\n'
|
||||||
f'{pformat(init_msgs)}\n'
|
f'{pformat(init_msgs)}\n'
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
raise FeedInitializationError(
|
||||||
|
'TOO MANY INIT MSGS!\n'
|
||||||
|
f'{pformat(init_msgs)}\n'
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: once all backends are updated we can remove this branching.
|
# TODO: once all backends are updated we can remove this branching.
|
||||||
rx_msg: bool = False
|
rx_msg: bool = False
|
||||||
|
@ -104,7 +115,6 @@ def validate_backend(
|
||||||
rx_msg = True
|
rx_msg = True
|
||||||
|
|
||||||
# verify feed init state / schema
|
# verify feed init state / schema
|
||||||
bs_mktid: str # backend specific (unique) market id
|
|
||||||
bs_fqme: str # backend specific fqme
|
bs_fqme: str # backend specific fqme
|
||||||
mkt: MktPair
|
mkt: MktPair
|
||||||
|
|
||||||
|
@ -157,14 +167,15 @@ def validate_backend(
|
||||||
)
|
)
|
||||||
|
|
||||||
case FeedInit(
|
case FeedInit(
|
||||||
# bs_mktid=bs_mktid,
|
|
||||||
mkt_info=MktPair(dst=Asset()) as mkt,
|
mkt_info=MktPair(dst=Asset()) as mkt,
|
||||||
shm_write_opts=dict(),
|
shm_write_opts=dict(shm_opts),
|
||||||
) as init:
|
) as init:
|
||||||
|
name: str = mod.name
|
||||||
log.info(
|
log.info(
|
||||||
f'NICE JOB {mod.name} BACKEND!\n'
|
f'NICE JOB {name} BACKEND being fully up to API spec B)\n'
|
||||||
'You are fully up to API spec B):\n'
|
f"{name}'s `MktPair` info:\n"
|
||||||
f'{init.to_dict()}'
|
f'{pformat(mkt.to_dict())}\n'
|
||||||
|
f'shm conf: {pformat(shm_opts)}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
|
@ -172,15 +183,14 @@ def validate_backend(
|
||||||
|
|
||||||
# build a msg if we received a dict for input.
|
# build a msg if we received a dict for input.
|
||||||
if not rx_msg:
|
if not rx_msg:
|
||||||
|
assert bs_fqme in mkt.fqme
|
||||||
init = FeedInit(
|
init = FeedInit(
|
||||||
bs_mktid=mkt.bs_mktid,
|
|
||||||
mkt_info=mkt,
|
mkt_info=mkt,
|
||||||
shm_write_opts=init.get('shm_write_opts'),
|
shm_write_opts=init.get('shm_write_opts'),
|
||||||
)
|
)
|
||||||
|
|
||||||
# `MktPair` value audits
|
# `MktPair` value audits
|
||||||
mkt = init.mkt_info
|
mkt = init.mkt_info
|
||||||
assert bs_fqme in mkt.fqme
|
|
||||||
assert mkt.type_key
|
assert mkt.type_key
|
||||||
|
|
||||||
# `MktPair` wish list
|
# `MktPair` wish list
|
||||||
|
|
Loading…
Reference in New Issue