From 2063b9d8bb6d93e5070918bd33c5dcd4eea45c3b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 20 Jun 2022 11:26:32 -0400 Subject: [PATCH] Drop ledger entries that have no transaction id --- piker/brokers/ib/broker.py | 16 +++++++++++++--- piker/pp.py | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) 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}' )