Make payload a ticker dict
parent
6b38f25430
commit
823bd2ea29
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue