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 # https://interactivebrokers.github.io/tws-api/tick_types.html
tick_types = { tick_types = {
77: 'trade', 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', 0: 'bsize',
1: 'bid', 1: 'bid',
2: 'ask', 2: 'ask',
@ -1046,13 +1050,17 @@ tick_types = {
def normalize( def normalize(
ticker: Ticker, ticker: Ticker,
calc_price: bool = False calc_price: bool = False
) -> dict: ) -> dict:
# convert named tuples to dicts so we send usable keys # convert named tuples to dicts so we send usable keys
new_ticks = [] new_ticks = []
for tick in ticker.ticks: for tick in ticker.ticks:
if tick and not isinstance(tick, dict): if tick and not isinstance(tick, dict):
td = tick._asdict() 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) new_ticks.append(td)

View File

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