From b63ce088f2ae0173fac8f3df3564d7404dcb6a67 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 27 Oct 2021 12:58:41 -0400 Subject: [PATCH] Error out clearing task on first quote being nan --- piker/clearing/_ems.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index f802b8a3..5096597f 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 @@ -47,9 +48,11 @@ log = get_logger(__name__) # TODO: numba all of this def mk_check( + trigger_price: float, known_last: float, action: str, + ) -> Callable[[float, float], bool]: """Create a predicate for given ``exec_price`` based on last known price, ``known_last``. @@ -77,8 +80,7 @@ def mk_check( return check_lt - else: - return None + raise ValueError('trigger: {trigger_price}, last: {known_last}') @dataclass @@ -177,7 +179,15 @@ async def clear_dark_triggers( tuple(execs.items()) ): - if not pred or (ttype not in tf) or (not pred(price)): + if ( + not pred or + ttype not in tf or + not pred(price) + ): + log.debug( + f'skipping quote for {sym} ' + f'{pred}, {ttype} not in {tf}?, {pred(price)}' + ) # majority of iterations will be non-matches continue @@ -1005,7 +1015,8 @@ async def _emsd_main( first_quote = feed.first_quotes[symbol] book = _router.get_dark_book(broker) - book.lasts[(broker, symbol)] = first_quote['last'] + last = book.lasts[(broker, symbol)] = first_quote['last'] + assert not isnan(last) # ib is a cucker but we've fixed it in the backend # open a stream with the brokerd backend for order # flow dialogue