diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index af6af5e8..0705fc21 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -1291,13 +1291,23 @@ async def deliver_trade_events( case 'error': # NOTE: see impl deats in # `Client.inline_errors()::push_err()` - err: dict = item + err: dict|str = item - # never relay errors for non-broker related issues + # std case, never relay errors for non-order-control + # related issues. # https://interactivebrokers.github.io/tws-api/message_codes.html - code: int = err['error_code'] - reason: str = err['reason'] - reqid: str = str(err['reqid']) + if isinstance(err, dict): + code: int = err['error_code'] + reason: str = err['reason'] + reqid: str = str(err['reqid']) + + # XXX, sometimes you'll get just a `str` of the form, + # '[code 104] connection failed' or something.. + elif isinstance(err, str): + code_part, _, reason = err.rpartition(']') + if code_part: + _, _, code = code_part.partition('[code') + reqid: str = '' # "Warning:" msg codes, # https://interactivebrokers.github.io/tws-api/message_codes.html#warning_codes