Tweak accounts schema to be per-provider

fsp_feeds
Tyler Goodlet 2021-09-09 10:37:20 -04:00
parent c9eb0b5afb
commit 87bca9aae1
2 changed files with 25 additions and 19 deletions

View File

@ -14,12 +14,14 @@ private_key = ""
[ib]
host = "127.0.0.1"
[ib.accounts]
margin = ""
registered = ""
paper = ""
ports.gw = 4002
ports.tws = 7497
ports.order = ["gw", "tws",]
[ib.ports]
gw = 4002
tws = 7497
order = [ "gw", "tws",]
accounts.margin = "X0000000"
accounts.ira = "X0000000"
accounts.paper = "XX0000000"
# the order in which accounts will be selected (if found through
# `brokerd`) when a new symbol is loaded
accounts_order = ['paper', 'margin', 'ira']

View File

@ -106,6 +106,7 @@ def write(
def load_accounts(
provider: Optional[str] = None
) -> bidict[str, Optional[str]]:
@ -114,17 +115,20 @@ def load_accounts(
accounts = bidict({'paper': None})
conf, path = load()
section = conf.get('accounts')
if section is None:
log.warning('No accounts config found?')
else:
for brokername, account_labels in section.items():
for provider_name, section in conf.items():
accounts_section = section.get('accounts')
if (
provider is None or
provider and brokername == provider
provider and provider_name == provider
):
for name, value in account_labels.items():
accounts[f'{brokername}.{name}'] = value
if accounts_section is None:
log.warning(f'No accounts named for {provider_name}?')
continue
else:
for label, value in accounts_section.items():
accounts[
f'{provider_name}.{label}'
] = value
return accounts