Tweak accounts schema to be per-provider
parent
c9eb0b5afb
commit
87bca9aae1
|
@ -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']
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue