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] [ib]
host = "127.0.0.1" host = "127.0.0.1"
[ib.accounts] ports.gw = 4002
margin = "" ports.tws = 7497
registered = "" ports.order = ["gw", "tws",]
paper = ""
[ib.ports] accounts.margin = "X0000000"
gw = 4002 accounts.ira = "X0000000"
tws = 7497 accounts.paper = "XX0000000"
order = [ "gw", "tws",]
# 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( def load_accounts(
provider: Optional[str] = None provider: Optional[str] = None
) -> bidict[str, Optional[str]]: ) -> bidict[str, Optional[str]]:
@ -114,17 +115,20 @@ def load_accounts(
accounts = bidict({'paper': None}) accounts = bidict({'paper': None})
conf, path = load() conf, path = load()
section = conf.get('accounts')
if section is None:
log.warning('No accounts config found?')
else: for provider_name, section in conf.items():
for brokername, account_labels in section.items(): accounts_section = section.get('accounts')
if ( if (
provider is None or provider is None or
provider and brokername == provider provider and provider_name == provider
): ):
for name, value in account_labels.items(): if accounts_section is None:
accounts[f'{brokername}.{name}'] = value 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 return accounts