From 4e9ff6546547902a1395cce43c2c0b7bbb2e1424 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 7 Jul 2022 19:15:01 -0400 Subject: [PATCH] Finally solve the last-price-is-`nan` issue.. Not sure why I put this off for so long but the check is in now such that if the market isn't open or no rt quote comes in from the first query, we just pull from the last shm history 'close' value. Includes another fix to avoid raising when a double remove on the client side stream from the registry sometimes happens. --- piker/clearing/_ems.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index befcda0e..b35e6640 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -20,6 +20,7 @@ In da suit parlances: "Execution management systems" """ from contextlib import asynccontextmanager from dataclasses import dataclass, field +from math import isnan from pprint import pformat import time from typing import AsyncIterator, Callable @@ -959,6 +960,12 @@ async def process_client_order_cmds( # like every other shitty tina platform that makes # the user choose the predicate operator. last = dark_book.lasts[fqsn] + + # sometimes the real-time feed hasn't come up + # so just pull from the latest history. + if isnan(last): + last = feed.shm.array[-1]['close'] + pred = mk_check(trigger_price, last, action) spread_slap: float = 5 @@ -1146,8 +1153,14 @@ async def _emsd_main( ) finally: - # remove client from "registry" - _router.clients.remove(ems_client_order_stream) + # try to remove client from "registry" + try: + _router.clients.remove(ems_client_order_stream) + except KeyError: + log.warning( + f'Stream {ems_client_order_stream._ctx.chan.uid}' + ' was already dropped?' + ) dialogues = _router.dialogues