Classify L1 tick types

bar_select
Tyler Goodlet 2020-11-03 16:22:04 -05:00
parent a5d5208cfa
commit 987c13c584
2 changed files with 25 additions and 7 deletions

View File

@ -285,7 +285,7 @@ class Client:
self,
symbol: str,
to_trio,
opts: Tuple[int] = ('375',), # '233', ),
opts: Tuple[int] = ('375', '233',),
# opts: Tuple[int] = ('459',),
) -> None:
"""Stream a ticker using the std L1 api.
@ -469,9 +469,27 @@ def normalize(
for tick in ticker.ticks:
td = tick._asdict()
if td['tickType'] in (48, 77):
if td['tickType'] in (77,):
td['type'] = 'trade'
if td['tickType'] in (48,):
td['type'] = 'utrade'
elif td['tickType'] in (0,):
td['type'] = 'bsize'
elif td['tickType'] in (1,):
td['type'] = 'bid'
elif td['tickType'] in (2,):
td['type'] = 'ask'
elif td['tickType'] in (3,):
td['type'] = 'asize'
elif td['tickType'] in (5,):
td['type'] = 'size'
new_ticks.append(td)
ticker.ticks = new_ticks
@ -643,7 +661,7 @@ async def stream_quotes(
# if we are the lone tick writer start writing
# the buffer with appropriate trade data
if not writer_already_exists:
for tick in iterticks(quote, type='trade'):
for tick in iterticks(quote, types=('trade', 'utrade',)):
last = tick['price']
# update last entry

View File

@ -1,14 +1,14 @@
"""
Stream format enforcement.
"""
from typing import AsyncIterator, Optional
from typing import AsyncIterator, Optional, Tuple
import numpy as np
def iterticks(
quote: dict,
type: str = 'trade',
types: Tuple[str] = ('trade', 'utrade'),
) -> AsyncIterator:
"""Iterate through ticks delivered per quote cycle.
"""
@ -16,6 +16,6 @@ def iterticks(
ticks = quote.get('ticks', ())
if ticks:
for tick in ticks:
# print(tick)
if tick.get('type') == type:
print(f"{quote['symbol']}: {tick}")
if tick.get('type') in types:
yield tick