Re-key ib's 'unreportable trades' (tick 48) as

dark_vlm
Tyler Goodlet 2022-01-21 17:00:42 -05:00
parent 8fe2bd6614
commit 55cfe6082b
2 changed files with 18 additions and 6 deletions

View File

@ -1032,7 +1032,11 @@ async def get_client(
# https://interactivebrokers.github.io/tws-api/tick_types.html
tick_types = {
77: 'trade',
48: 'utrade',
# a "utrade" aka an off exchange "unreportable" (dark) vlm:
# https://interactivebrokers.github.io/tws-api/tick_types.html#rt_volume
48: 'dark_trade',
0: 'bsize',
1: 'bid',
2: 'ask',
@ -1046,13 +1050,17 @@ tick_types = {
def normalize(
ticker: Ticker,
calc_price: bool = False
) -> dict:
# convert named tuples to dicts so we send usable keys
new_ticks = []
for tick in ticker.ticks:
if tick and not isinstance(tick, dict):
td = tick._asdict()
td['type'] = tick_types.get(td['tickType'], 'n/a')
td['type'] = tick_types.get(
td['tickType'],
'n/a',
)
new_ticks.append(td)

View File

@ -25,14 +25,18 @@ import numpy as np
def iterticks(
quote: dict,
types: Tuple[str] = ('trade', 'utrade'),
types: Tuple[str] = ('trade', 'dark_trade'),
) -> AsyncIterator:
"""Iterate through ticks delivered per quote cycle.
"""
'''
Iterate through ticks delivered per quote cycle.
'''
# print(f"{quote}\n\n")
ticks = quote.get('ticks', ())
if ticks:
for tick in ticks:
# print(f"{quote['symbol']}: {tick}")
if tick.get('type') in types:
ttype = tick.get('type')
if ttype in types:
yield tick