From 95f4b2aa02829b84f0c2896fde0ad897b50285e9 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 22 Oct 2021 12:58:12 -0400 Subject: [PATCH] Expect accounts as tuple, don't start rt pnl on no live pp --- piker/clearing/_ems.py | 4 ++-- piker/ui/_position.py | 5 ++++- piker/ui/order_mode.py | 11 ++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index 8ff2b0e2..c35e2e5f 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -269,7 +269,7 @@ class TradesRelay: positions: dict[str, dict[str, BrokerdPosition]] # allowed account names - accounts: set[str] + accounts: tuple[str] # count of connected ems clients for this ``brokerd`` consumers: int = 0 @@ -449,7 +449,7 @@ async def open_brokerd_trades_dialogue( relay = TradesRelay( brokerd_dialogue=brokerd_trades_stream, positions=pps, - accounts=set(accounts), + accounts=accounts, consumers=1, ) diff --git a/piker/ui/_position.py b/piker/ui/_position.py index 1936c1ca..e057154e 100644 --- a/piker/ui/_position.py +++ b/piker/ui/_position.py @@ -54,6 +54,7 @@ async def update_pnl_from_feed( feed: Feed, order_mode: OrderMode, # noqa + tracker: PositionTracker, ) -> None: '''Real-time display the current pp's PnL in the appropriate label. @@ -76,7 +77,8 @@ async def update_pnl_from_feed( types = ('bid', 'last', 'last', 'utrade') else: - raise RuntimeError('No pp?!?!') + log.info(f'No position (yet) for {tracker.alloc.account}@{key}') + return # real-time update pnl on the status pane try: @@ -343,6 +345,7 @@ class SettingsPane: update_pnl_from_feed, feed, mode, + tracker, ) # immediately display in status label diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index 594f0826..432c4801 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -620,8 +620,8 @@ async def open_order_mode( # alloc? pp_tracker.update_from_pp() + # on existing position, show pp tracking graphics if pp_tracker.startup_pp.size != 0: - # if no position, don't show pp tracking graphics pp_tracker.show() pp_tracker.hide_info() @@ -805,12 +805,13 @@ async def process_trades_and_update_ui( tracker = mode.trackers[msg['account']] tracker.live_pp.update_from_msg(msg) - tracker.update_from_pp() - # update order pane widgets + tracker.update_from_pp() mode.pane.update_status_ui(tracker) - # display pnl - mode.pane.display_pnl(tracker) + + if tracker.live_pp.size: + # display pnl + mode.pane.display_pnl(tracker) # short circuit to next msg to avoid # unnecessary msg content lookups