From 87bca9aae1c3e48777a43971a21b85318a4928cf Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 9 Sep 2021 10:37:20 -0400 Subject: [PATCH] Tweak accounts schema to be per-provider --- config/brokers.toml | 18 ++++++++++-------- piker/config.py | 26 +++++++++++++++----------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/config/brokers.toml b/config/brokers.toml index e14fdf20..7d288648 100644 --- a/config/brokers.toml +++ b/config/brokers.toml @@ -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'] diff --git a/piker/config.py b/piker/config.py index 60575e2e..2d1a948b 100644 --- a/piker/config.py +++ b/piker/config.py @@ -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(): - if ( - provider is None or - provider and brokername == provider - ): - for name, value in account_labels.items(): - accounts[f'{brokername}.{name}'] = value + for provider_name, section in conf.items(): + accounts_section = section.get('accounts') + if ( + provider is None or + provider and provider_name == provider + ): + 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