From cbcbb2b24350ea522ecfcc2c48e8f1a737b7ac18 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 15 Jun 2022 09:56:14 -0400 Subject: [PATCH] Filter pps loading to client-active accounts set --- piker/brokers/ib/broker.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index 8f3ec44c..aa3fa07c 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -380,6 +380,7 @@ async def trades_dialogue( accounts.add(account) cids2pps = {} + used_accounts = set() # process pp value reported from ib's system. we only use these # to cross-check sizing since average pricing on their end uses @@ -390,7 +391,8 @@ async def trades_dialogue( for pos in client.positions(): cid, msg = pack_position(pos) - msg.account = accounts_def.inverse[msg.account] + acctid = msg.account = accounts_def.inverse[msg.account] + used_accounts.add(acctid) cids2pps[cid] = msg assert msg.account in accounts, ( f'Position for unknown account: {msg.account}') @@ -404,12 +406,14 @@ async def trades_dialogue( # load all positions from `pps.toml`, cross check with ib's # positions data, and relay re-formatted pps as msgs to the ems. - for acctid, by_fqsn in pp.get_pps('ib').items(): + for acctid, by_fqsn in pp.get_pps( + 'ib', acctids=used_accounts, + ).items(): for fqsn, posdict in by_fqsn.items(): ibppmsg = cids2pps[posdict['bsuid']] msg = BrokerdPosition( broker='ib', - # account=acctid + '.ib', + # XXX: ok so this is annoying, we're relaying # an account name with the backend suffix prefixed # but when reading accounts from ledgers we don't @@ -451,6 +455,10 @@ async def trades_dialogue( all_positions.append(msg.dict()) + if not all_positions and cids2pps: + raise RuntimeError( + 'Positions report by ib but not found in `pps.toml` !?') + # log.info(f'Loaded {len(trades)} from this session') # TODO: write trades to local ``trades.toml`` # - use above per-session trades data and write to local file