diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index 09922055..dde4c9c6 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -801,9 +801,7 @@ def norm_trade_records( records: list[pp.Transaction] = [] for tid, record in ledger.items(): - # date, time = record['dateTime'] - # cost = record['cost'] - # action = record['buySell'] + conid = record.get('conId') or record['conid'] comms = record.get('commission') or -1*record['ibCommission'] price = record.get('price') or record['tradePrice'] @@ -957,6 +955,18 @@ def trades_to_records( entry['date'] = str(dt) acctid = accounts[entry['acctNumber']] + if not tid: + # this is likely some kind of internal adjustment + # transaction, likely one of the following: + # - an expiry event that will show a "book trade" indicating + # some adjustment to cash balances: zeroing or itm settle. + # - a manual cash balance position adjustment likely done by + # the user from the accounts window in TWS where they can + # manually set the avg price and size: + # https://api.ibkr.com/lib/cstools/faq/web1/index.html#/tag/DTWS_ADJ_AVG_COST + log.warning(f'Skipping ID-less ledger entry:\n{pformat(entry)}') + continue + trades_by_account.setdefault( acctid, {} )[tid] = entry diff --git a/piker/pp.py b/piker/pp.py index d0809f88..68663f89 100644 --- a/piker/pp.py +++ b/piker/pp.py @@ -572,7 +572,6 @@ def load_pps_from_toml( acctid, ) if not pps: - breakpoint() log.warning( f'No trade history could be loaded for {brokername}:{acctid}' )