Allow packing pps by a different key set

lifo_pps_ib
Tyler Goodlet 2022-06-16 15:27:26 -04:00
parent 5147cd7be0
commit ecdc747ced
1 changed files with 6 additions and 1 deletions

View File

@ -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