diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index 94adb39e..8d3fa183 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -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 diff --git a/piker/data/_normalize.py b/piker/data/_normalize.py index 9f73858d..e1120278 100644 --- a/piker/data/_normalize.py +++ b/piker/data/_normalize.py @@ -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