From 8118a57b9a6d1daf8f2ea4371e35094c5a41125e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 31 Jan 2022 23:50:56 -0500 Subject: [PATCH] Guard against no time field in some provider quotes --- piker/data/_normalize.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/piker/data/_normalize.py b/piker/data/_normalize.py index 45eed1be..677468ad 100644 --- a/piker/data/_normalize.py +++ b/piker/data/_normalize.py @@ -24,7 +24,10 @@ from typing import AsyncIterator def iterticks( quote: dict, - types: tuple[str] = ('trade', 'dark_trade'), + types: tuple[str] = ( + 'trade', + 'dark_trade', + ), deduplicate_darks: bool = False, ) -> AsyncIterator: @@ -47,17 +50,20 @@ def iterticks( if deduplicate_darks: for tick in ticks: ttype = tick.get('type') - sig = ( - tick['time'], - tick['price'], - tick['size'] - ) - if ttype == 'dark_trade': - darks[sig] = tick + time = tick.get('time', None) + if time: + sig = ( + time, + tick['price'], + tick['size'] + ) - elif ttype == 'trade': - trades[sig] = tick + if ttype == 'dark_trade': + darks[sig] = tick + + elif ttype == 'trade': + trades[sig] = tick # filter duplicates for sig, tick in trades.items():