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()
quotes = await get_quotes(tickers)
postquote_start = time.time()
payload = []
payload = {}
for symbol, quote in quotes.items():
# 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:
log.warning(f"Delayed quote:\n{quote}")
if diff_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.info(
f"New quote {quote['symbol']}:\n{new}")
_cache[symbol] = quote
payload.append(quote)
payload[symbol] = quote
else:
payload.append(quote)
payload[symbol] = quote
if payload:
q.put_nowait(payload)