From b59ed74bc1651f5ea57ca6afbaa11f7bbea8851b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 11 Aug 2022 14:18:53 -0400 Subject: [PATCH] 'Only send `'closed'` on Filled events, lowercase all statues' --- piker/brokers/ib/broker.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index b7c121e7..da1b03c8 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -846,8 +846,12 @@ async def deliver_trade_events( # cancelling.. gawwwd if ib_status_key == 'cancelled': 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 + print(ib_status_key) elif ib_status_key == 'inactive': async def sched_cancel(): @@ -862,10 +866,16 @@ async def deliver_trade_events( 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 - if remaining == 0: + if ( + status_key == 'filled' + and remaining == 0 + ): status_key = 'closed' # skip duplicate filled updates - we get the deats @@ -1019,9 +1029,18 @@ async def deliver_trade_events( if err['reqid'] == -1: log.error(f'TWS external order error:\n{pformat(err)}') - # TODO: what schema for this msg if we're going to make it - # portable across all backends? - # msg = BrokerdError(**err) + # TODO: we don't want to relay data feed / lookup errors + # so we need some further filtering logic here.. + # 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':