From b7b7abbc1f43ae998c417145bb38596ac84ffedf Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 12 Feb 2018 14:03:31 -0500 Subject: [PATCH] Only push new quotes to the queue at 5 per sec --- piker/brokers/questrade.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index f956cc11..bb5eb741 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -300,8 +300,8 @@ async def serve_forever(tasks) -> None: async def poll_tickers( client: Client, tickers: [str], q: trio.Queue, - rate: int = 3, - cache: bool = False, # only deliver "new" changes to the queue + rate: int = 5, # 200ms delay between quotes + time_cached: bool = True, # only deliver "new" quotes to the queue ) -> None: """Stream quotes for a sequence of tickers at the given ``rate`` per second. @@ -323,12 +323,13 @@ async def poll_tickers( if quote['delay'] > 0: log.warning(f"Delayed quote:\n{quote}") - if cache: # if cache is enabled then only deliver "new" changes + if time_cached: # if cache is enabled then only deliver "new" changes symbol = quote['symbol'] last = _cache.setdefault(symbol, {}) - new = set(quote.items()) - set(last.items()) - if new: - log.debug(f"New quote {symbol} data:\n{new}") + timekey = 'lastTradeTime' + if quote[timekey] != last.get(timekey): + log.info( + f"New quote {quote['symbol']} @ {quote[timekey]}") _cache[symbol] = quote payload.append(quote) else: