From 09d34f735521c0292e2c08f7bb39409dccebfd34 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 7 Sep 2021 09:21:55 -0400 Subject: [PATCH] Make `accounts` field public, add an account name method --- piker/clearing/_allocate.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index b052e38d..33e2c635 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -83,17 +83,16 @@ class Allocator(BaseModel): # required to get the account validator lookup working? extra = 'allow' - # underscore_attrs_are_private = False + underscore_attrs_are_private = False symbol: Symbol - + accounts: bidict[str, Optional[str]] account: Optional[str] = 'paper' - _accounts: bidict[str, Optional[str]] - @validator('account', pre=True) + @validator('account', pre=False) def set_account(cls, v, values): if v: - return values['_accounts'][v] + return values['accounts'][v] size_unit: SizeUnit = 'currency' _size_units: dict[str, Optional[str]] = _size_units @@ -129,6 +128,9 @@ class Allocator(BaseModel): else: return self.units_limit + def account_name(self) -> str: + return self.accounts.inverse[self.account] + def next_order_info( self, @@ -280,7 +282,7 @@ def mk_allocator( alloc = Allocator( symbol=symbol, - _accounts=accounts, + accounts=accounts, **defaults, )