Guard against no time field in some provider quotes

windows_fixes_yo
Tyler Goodlet 2022-01-31 23:50:56 -05:00
parent 5952e7f538
commit 8118a57b9a
1 changed files with 16 additions and 10 deletions

View File

@ -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():