From 0d2cddec9a26949462e4100afab73b960aa399af Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 8 Sep 2021 14:01:54 -0400 Subject: [PATCH] Return accounts in `bidict` --- piker/clearing/_allocate.py | 2 +- piker/config.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index 33e2c635..7549b3c2 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -129,7 +129,7 @@ class Allocator(BaseModel): return self.units_limit def account_name(self) -> str: - return self.accounts.inverse[self.account] + return self.accounts.inverse[self.account] def next_order_info( self, diff --git a/piker/config.py b/piker/config.py index e979a354..60575e2e 100644 --- a/piker/config.py +++ b/piker/config.py @@ -22,6 +22,7 @@ from os.path import dirname import shutil from typing import Optional +from bidict import bidict import toml import click @@ -104,10 +105,13 @@ def write( return toml.dump(config, cf) -def load_accounts() -> dict[str, Optional[str]]: +def load_accounts( + provider: Optional[str] = None + +) -> bidict[str, Optional[str]]: # our default paper engine entry - accounts: dict[str, Optional[str]] = {'paper': None} + accounts = bidict({'paper': None}) conf, path = load() section = conf.get('accounts') @@ -116,7 +120,11 @@ def load_accounts() -> dict[str, Optional[str]]: else: for brokername, account_labels in section.items(): - for name, value in account_labels.items(): - accounts[f'{brokername}.{name}'] = value + if ( + provider is None or + provider and brokername == provider + ): + for name, value in account_labels.items(): + accounts[f'{brokername}.{name}'] = value return accounts