Return object form from `update_pps_conf()`

lifo_pps_ib
Tyler Goodlet 2022-06-15 11:55:26 -04:00
parent cbcbb2b243
commit 7b2e8f1ba5
1 changed files with 20 additions and 23 deletions

View File

@ -333,19 +333,16 @@ def get_pps(
brokername: str, brokername: str,
acctids: Optional[set[str]] = set(), acctids: Optional[set[str]] = set(),
) -> dict[str, Any]: ) -> dict[str, dict[str, Position]]:
''' '''
Read out broker-specific position entries from Read out broker-specific position entries from
incremental update file: ``pps.toml``. incremental update file: ``pps.toml``.
''' '''
conf, path = config.load('pps') conf, path = config.load('pps')
brokersection = conf.setdefault(brokername, {})
all_active = {} all_active = {}
# try to load any ledgers if no section found # try to load any ledgers if no section found
if not brokersection:
bconf, path = config.load('brokers') bconf, path = config.load('brokers')
accounts = bconf[brokername]['accounts'] accounts = bconf[brokername]['accounts']
for account in accounts: for account in accounts:
@ -360,13 +357,9 @@ def get_pps(
continue continue
active = update_pps_conf(brokername, account) active = update_pps_conf(brokername, account)
all_active.update(active) all_active.setdefault(account, {}).update(active)
# reload pps after ledger updates return all_active
conf, path = config.load('pps')
brokersection = conf.setdefault(brokername, {})
return brokersection
def update_pps_conf( def update_pps_conf(
@ -432,6 +425,9 @@ def update_pps_conf(
brokerless_key = fqsn.rstrip(f'.{brokername}') brokerless_key = fqsn.rstrip(f'.{brokername}')
pp_entries[brokerless_key] = pp_dict pp_entries[brokerless_key] = pp_dict
for fqsn in closed:
pp_objs.pop(fqsn, None)
conf[brokername][acctid] = pp_entries conf[brokername][acctid] = pp_entries
config.write( config.write(
conf, conf,
@ -441,7 +437,8 @@ def update_pps_conf(
# encoder=config.toml.Encoder(preserve=True), # encoder=config.toml.Encoder(preserve=True),
) )
return active # deliver object form of all pps in table to caller
return pp_objs
if __name__ == '__main__': if __name__ == '__main__':