Make payload a ticker dict

kivy_mainline_and_py3.8
Tyler Goodlet 2018-03-29 13:00:48 -04:00
parent 6b38f25430
commit 823bd2ea29
1 changed files with 3 additions and 7 deletions

View File

@ -66,28 +66,24 @@ async def poll_tickers(
prequote_start = time.time() prequote_start = time.time()
quotes = await get_quotes(tickers) quotes = await get_quotes(tickers)
postquote_start = time.time() postquote_start = time.time()
payload = [] payload = {}
for symbol, quote in quotes.items(): for symbol, quote in quotes.items():
# FIXME: None is returned if a symbol can't be found. # FIXME: None is returned if a symbol can't be found.
# Consider filtering out such symbols before starting poll loop # Consider filtering out such symbols before starting poll loop
if quote is None: if quote is None:
continue continue
if quote.get('delay', 0) > 0:
log.warning(f"Delayed quote:\n{quote}")
if diff_cached: if diff_cached:
# if cache is enabled then only deliver "new" changes # if cache is enabled then only deliver "new" changes
symbol = quote['symbol']
last = _cache.setdefault(symbol, {}) last = _cache.setdefault(symbol, {})
new = set(quote.items()) - set(last.items()) new = set(quote.items()) - set(last.items())
if new: if new:
log.info( log.info(
f"New quote {quote['symbol']}:\n{new}") f"New quote {quote['symbol']}:\n{new}")
_cache[symbol] = quote _cache[symbol] = quote
payload.append(quote) payload[symbol] = quote
else: else:
payload.append(quote) payload[symbol] = quote
if payload: if payload:
q.put_nowait(payload) q.put_nowait(payload)