Drop `"<broker>.<account>.."` from pps.toml entries

Add special blocks to handle removing the broker account levels from
both writing and reading routines.
pre_overruns_ctxcancelled
Tyler Goodlet 2023-04-04 14:29:25 -04:00
parent 1408ba80aa
commit adb11fb778
1 changed files with 30 additions and 5 deletions

View File

@ -504,6 +504,8 @@ class PpTable(Struct):
trans: dict[str, Transaction], trans: dict[str, Transaction],
cost_scalar: float = 2, cost_scalar: float = 2,
mkt: MktPair | None = None,
) -> dict[str, Position]: ) -> dict[str, Position]:
pps = self.pps pps = self.pps
@ -521,7 +523,7 @@ class PpTable(Struct):
# template the mkt-info presuming a legacy market ticks # template the mkt-info presuming a legacy market ticks
# if no info exists in the transactions.. # if no info exists in the transactions..
mkt: MktPair | Symbol = t.sys mkt: MktPair | Symbol | None = mkt or t.sys
if not mkt: if not mkt:
mkt = MktPair.from_fqme( mkt = MktPair.from_fqme(
fqme, fqme,
@ -671,7 +673,20 @@ class PpTable(Struct):
f'Updating positions in ``{self.conf_path}``:\n' f'Updating positions in ``{self.conf_path}``:\n'
f'n{pformat(pp_entries)}' f'n{pformat(pp_entries)}'
) )
self.conf[self.brokername][self.acctid] = pp_entries
if self.brokername in self.conf:
log.warning(
f'Rewriting {self.conf_path} keys to drop <broker.acct>!'
)
# legacy key schema including <brokername.account>, so
# rewrite all entries to drop those tables since we now
# put that in the filename!
accounts = self.conf.pop(self.brokername)
assert len(accounts) == 1
entries = accounts.pop(self.acctid)
self.conf.update(entries)
self.conf.update(pp_entries)
elif ( elif (
self.brokername in self.conf and self.brokername in self.conf and
@ -758,8 +773,18 @@ def open_pps(
conf, conf_path = config.load( conf, conf_path = config.load(
f'pps.{brokername}.{acctid}', f'pps.{brokername}.{acctid}',
) )
brokersection = conf.setdefault(brokername, {})
pps = brokersection.setdefault(acctid, {}) if brokername in conf:
log.warning(
f'Rewriting {conf_path} keys to drop <broker.acct>!'
)
# legacy key schema including <brokername.account>, so
# rewrite all entries to drop those tables since we now
# put that in the filename!
accounts = conf.pop(brokername)
for acctid in accounts.copy():
entries = accounts.pop(acctid)
conf.update(entries)
# TODO: ideally we can pass in an existing # TODO: ideally we can pass in an existing
# pps state to this right? such that we # pps state to this right? such that we
@ -782,7 +807,7 @@ def open_pps(
# unmarshal/load ``pps.toml`` config entries into object form # unmarshal/load ``pps.toml`` config entries into object form
# and update `PpTable` obj entries. # and update `PpTable` obj entries.
for fqme, entry in pps.items(): for fqme, entry in conf.items():
# atype = entry.get('asset_type', '<unknown>') # atype = entry.get('asset_type', '<unknown>')