From 8cd56cb6d390427c855873a55f58878077703e48 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 6 Oct 2022 08:18:35 -0400 Subject: [PATCH] Flip ems-side-client (`OrderBook`) to be a struct `@dataclass` is so 2 years ago ;) Also rename `.update()` -> `.send_update()` to be a bit more explicit about actually sending an update msg. --- piker/clearing/_client.py | 12 ++++-------- piker/clearing/_ems.py | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/piker/clearing/_client.py b/piker/clearing/_client.py index 11eb9b69..03fb62d3 100644 --- a/piker/clearing/_client.py +++ b/piker/clearing/_client.py @@ -19,15 +19,14 @@ Orders and execution client API. """ from contextlib import asynccontextmanager as acm -from typing import Dict from pprint import pformat -from dataclasses import dataclass, field import trio import tractor from tractor.trionics import broadcast_receiver from ..log import get_logger +from ..data.types import Struct from ._ems import _emsd_main from .._daemon import maybe_open_emsd from ._messages import Order, Cancel @@ -37,8 +36,7 @@ from ..brokers import get_brokermod log = get_logger(__name__) -@dataclass -class OrderBook: +class OrderBook(Struct): '''EMS-client-side order book ctl and tracking. A style similar to "model-view" is used here where this api is @@ -53,9 +51,7 @@ class OrderBook: # mem channels used to relay order requests to the EMS daemon _to_ems: trio.abc.SendChannel _from_order_book: trio.abc.ReceiveChannel - - _sent_orders: Dict[str, Order] = field(default_factory=dict) - _ready_to_receive: trio.Event = trio.Event() + _sent_orders: dict[str, Order] = {} def send( self, @@ -66,7 +62,7 @@ class OrderBook: self._to_ems.send_nowait(msg) return msg - def update( + def send_update( self, uuid: str, diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index 49f2a115..17b63730 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -679,6 +679,8 @@ async def translate_and_relay_brokerd_events( # fan-out-relay position msgs immediately by # broadcasting updates on all client streams + # TODO: this should be subscription based for privacy + # eventually! await router.client_broadcast('all', pos_msg) continue