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

View File

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