From ecdc747cede569c5588f6af71fc7b35bff398f4f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 16 Jun 2022 15:27:26 -0400 Subject: [PATCH] Allow packing pps by a different key set --- piker/pp.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/piker/pp.py b/piker/pp.py index a6f61f56..9dfa4eb1 100644 --- a/piker/pp.py +++ b/piker/pp.py @@ -332,6 +332,7 @@ def load_pps_from_ledger( def get_pps( brokername: str, acctids: Optional[set[str]] = set(), + key_by: Optional[str] = None, ) -> dict[str, dict[str, Position]]: ''' @@ -356,7 +357,7 @@ def get_pps( ): continue - active = update_pps_conf(brokername, account) + active = update_pps_conf(brokername, account, key_by=key_by) all_active.setdefault(account, {}).update(active) return all_active @@ -366,6 +367,7 @@ def update_pps_conf( brokername: str, acctid: str, trade_records: Optional[list[Transaction]] = None, + key_by: Optional[str] = None, ) -> dict[str, Position]: @@ -437,6 +439,9 @@ def update_pps_conf( # encoder=config.toml.Encoder(preserve=True), ) + if key_by: + pps_objs = {getattr(pp, key_by): pp for pp in pps_objs} + # deliver object form of all pps in table to caller return pp_objs