Tag TWS trade events

basic_orders
Tyler Goodlet 2021-03-01 12:01:48 -05:00
parent a1691cf1c5
commit 72c4a4366b
1 changed files with 14 additions and 9 deletions

View File

@ -908,7 +908,6 @@ async def stream_quotes(
# TODO: support multiple subscriptions # TODO: support multiple subscriptions
sym = symbols[0] sym = symbols[0]
async with trio.open_nursery() as n:
contract, first_ticker, details = await _trio_run_client_method( contract, first_ticker, details = await _trio_run_client_method(
method='get_quote', method='get_quote',
symbol=sym, symbol=sym,
@ -986,7 +985,6 @@ async def stream_quotes(
# for "traditional" assets, volume is normally discreet, not a float # for "traditional" assets, volume is normally discreet, not a float
syminfo['lot_tick_size'] = 0.0 syminfo['lot_tick_size'] = 0.0
# TODO: for loop through all symbols passed in # TODO: for loop through all symbols passed in
init_msgs = { init_msgs = {
# pass back token, and bool, signalling if we're the writer # pass back token, and bool, signalling if we're the writer
@ -1202,7 +1200,8 @@ async def stream_trades(
# supposedly IB server fill time # supposedly IB server fill time
'broker_time': execu.time, # converted to float by us 'broker_time': execu.time, # converted to float by us
'time': fill.time, # ns from main TCP handler by us inside ``ib_insync`` override # ns from main TCP handler by us inside ``ib_insync`` override
'time': fill.time,
'time_ns': time.time_ns(), # cuz why not 'time_ns': time.time_ns(), # cuz why not
'action': action_map[execu.side], 'action': action_map[execu.side],
'size': execu.shares, 'size': execu.shares,
@ -1223,4 +1222,10 @@ async def stream_trades(
# don't forward, it's pointless.. # don't forward, it's pointless..
continue continue
if msg['reqid'] < -1:
# it's a trade event generated by TWS usage.
log.warning(f"TWS triggered trade:\n{pformat(msg)}")
msg['reqid'] = 'tws-' + msg['reqid']
yield {'local_trades': (event_name, msg)} yield {'local_trades': (event_name, msg)}