From 29ddfe017c0d48b2a3816012e1d7ac3905897b55 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 23 Mar 2018 16:15:56 -0400 Subject: [PATCH] Use total time calc --- piker/brokers/core.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/piker/brokers/core.py b/piker/brokers/core.py index 8e52fe1b..6d9c7dbd 100644 --- a/piker/brokers/core.py +++ b/piker/brokers/core.py @@ -55,9 +55,12 @@ async def poll_tickers( ) -> None: """Stream quotes for a sequence of tickers at the given ``rate`` per second. + + A broker-client ``quoter`` async context manager must be provided which + returns an async quote function. """ sleeptime = round(1. / rate, 3) - _cache = {} + _cache = {} # ticker to quote caching async with quoter(client, tickers) as get_quotes: while True: # use an event here to trigger exit? @@ -66,8 +69,9 @@ async def poll_tickers( postquote_start = time.time() payload = [] for symbol, quote in quotes.items(): - # TODO: uhh wtf? - if not quote: + # FIXME: None is returned if a symbol can't be found. + # Consider filtering out such symbols before starting poll loop + if quote is None: continue if quote.get('delay', 0) > 0: @@ -92,8 +96,8 @@ async def poll_tickers( req_time = round(postquote_start - prequote_start, 3) proc_time = round(time.time() - postquote_start, 3) tot = req_time + proc_time - log.debug(f"Request + processing took {req_time + proc_time}") - delay = sleeptime - (req_time + proc_time) + log.debug(f"Request + processing took {tot}") + delay = sleeptime - tot if delay <= 0: log.warn( f"Took {req_time} (request) + {proc_time} (processing) = {tot}"