'Only send `'closed'` on Filled events, lowercase all statues'

dict_differ
Tyler Goodlet 2022-08-11 14:18:53 -04:00
parent 9782107153
commit 66f7dd9020
1 changed files with 25 additions and 6 deletions

View File

@ -828,8 +828,12 @@ async def deliver_trade_events(
# cancelling.. gawwwd # cancelling.. gawwwd
if ib_status_key == 'cancelled': if ib_status_key == 'cancelled':
last_log = trade.log[-1] last_log = trade.log[-1]
if last_log.message: if (
last_log.message
and 'Error' not in last_log.message
):
ib_status_key = trade.log[-2].status ib_status_key = trade.log[-2].status
print(ib_status_key)
elif ib_status_key == 'inactive': elif ib_status_key == 'inactive':
async def sched_cancel(): async def sched_cancel():
@ -844,10 +848,16 @@ async def deliver_trade_events(
nurse.start_soon(sched_cancel) nurse.start_soon(sched_cancel)
status_key = _statuses.get(ib_status_key) or ib_status_key status_key = (
_statuses.get(ib_status_key)
or ib_status_key.lower()
)
remaining = status.remaining remaining = status.remaining
if remaining == 0: if (
status_key == 'filled'
and remaining == 0
):
status_key = 'closed' status_key = 'closed'
# skip duplicate filled updates - we get the deats # skip duplicate filled updates - we get the deats
@ -1001,9 +1011,18 @@ async def deliver_trade_events(
if err['reqid'] == -1: if err['reqid'] == -1:
log.error(f'TWS external order error:\n{pformat(err)}') log.error(f'TWS external order error:\n{pformat(err)}')
# TODO: what schema for this msg if we're going to make it # TODO: we don't want to relay data feed / lookup errors
# portable across all backends? # so we need some further filtering logic here..
# msg = BrokerdError(**err) # for most cases the 'status' block above should take
# care of this.
# await ems_stream.send(BrokerdStatus(
# status='error',
# reqid=err['reqid'],
# reason=err['reason'],
# time_ns=time.time_ns(),
# account=accounts_def.inverse[trade.order.account],
# broker_details={'name': 'ib'},
# ))
case 'position': case 'position':