Return accounts in `bidict`

fsp_feeds
Tyler Goodlet 2021-09-08 14:01:54 -04:00
parent 063788499a
commit 0d2cddec9a
2 changed files with 13 additions and 5 deletions

View File

@ -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,

View File

@ -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