Use total time calc
parent
08aa996e27
commit
29ddfe017c
|
@ -55,9 +55,12 @@ async def poll_tickers(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Stream quotes for a sequence of tickers at the given ``rate``
|
"""Stream quotes for a sequence of tickers at the given ``rate``
|
||||||
per second.
|
per second.
|
||||||
|
|
||||||
|
A broker-client ``quoter`` async context manager must be provided which
|
||||||
|
returns an async quote function.
|
||||||
"""
|
"""
|
||||||
sleeptime = round(1. / rate, 3)
|
sleeptime = round(1. / rate, 3)
|
||||||
_cache = {}
|
_cache = {} # ticker to quote caching
|
||||||
|
|
||||||
async with quoter(client, tickers) as get_quotes:
|
async with quoter(client, tickers) as get_quotes:
|
||||||
while True: # use an event here to trigger exit?
|
while True: # use an event here to trigger exit?
|
||||||
|
@ -66,8 +69,9 @@ async def poll_tickers(
|
||||||
postquote_start = time.time()
|
postquote_start = time.time()
|
||||||
payload = []
|
payload = []
|
||||||
for symbol, quote in quotes.items():
|
for symbol, quote in quotes.items():
|
||||||
# TODO: uhh wtf?
|
# FIXME: None is returned if a symbol can't be found.
|
||||||
if not quote:
|
# Consider filtering out such symbols before starting poll loop
|
||||||
|
if quote is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if quote.get('delay', 0) > 0:
|
if quote.get('delay', 0) > 0:
|
||||||
|
@ -92,8 +96,8 @@ async def poll_tickers(
|
||||||
req_time = round(postquote_start - prequote_start, 3)
|
req_time = round(postquote_start - prequote_start, 3)
|
||||||
proc_time = round(time.time() - postquote_start, 3)
|
proc_time = round(time.time() - postquote_start, 3)
|
||||||
tot = req_time + proc_time
|
tot = req_time + proc_time
|
||||||
log.debug(f"Request + processing took {req_time + proc_time}")
|
log.debug(f"Request + processing took {tot}")
|
||||||
delay = sleeptime - (req_time + proc_time)
|
delay = sleeptime - tot
|
||||||
if delay <= 0:
|
if delay <= 0:
|
||||||
log.warn(
|
log.warn(
|
||||||
f"Took {req_time} (request) + {proc_time} (processing) = {tot}"
|
f"Took {req_time} (request) + {proc_time} (processing) = {tot}"
|
||||||
|
|
Loading…
Reference in New Issue