From 4bcb7911617ef6a79bee988f86816721bad3f45f 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 e0917c85..051ad30e 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 @@ -951,6 +952,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 @@ -1138,8 +1145,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