From f4740da6a22589a4842220ad9bb8439023dc3f62 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 14 Sep 2021 13:10:39 -0400 Subject: [PATCH] Drop `.accounts` field from allocator --- piker/clearing/_allocate.py | 14 +------------- piker/ui/_position.py | 10 +++++----- piker/ui/order_mode.py | 4 +--- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index 94c7af12..f6c9eee1 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -86,14 +86,7 @@ class Allocator(BaseModel): underscore_attrs_are_private = False symbol: Symbol - accounts: bidict[str, Optional[str]] account: Optional[str] = 'paper' - - @validator('account', pre=False) - def set_account(cls, v, values): - if v: - return values['accounts'][v] - size_unit: SizeUnit = 'currency' _size_units: dict[str, Optional[str]] = _size_units @@ -128,9 +121,6 @@ class Allocator(BaseModel): else: return self.units_limit - def account_name(self) -> str: - return self.accounts.inverse[self.account] - def next_order_info( self, @@ -234,7 +224,7 @@ class Allocator(BaseModel): 'slots_used': slots_used, # update line LHS label with account name - 'account': self.account_name(), + 'account': self.account, } def slots_used( @@ -264,7 +254,6 @@ class Allocator(BaseModel): def mk_allocator( symbol: Symbol, - accounts: dict[str, str], startup_pp: Position, # default allocation settings @@ -293,7 +282,6 @@ def mk_allocator( alloc = Allocator( symbol=symbol, - accounts=accounts, **defaults, ) diff --git a/piker/ui/_position.py b/piker/ui/_position.py index 8632effd..12cb3dfb 100644 --- a/piker/ui/_position.py +++ b/piker/ui/_position.py @@ -185,11 +185,11 @@ class SettingsPane: f'Account `{account_name}` can not be set for {sym}' ) self.form.fields['account'].setCurrentText( - old_tracker.alloc.account_name()) + old_tracker.alloc.account) return self.order_mode.current_pp = tracker - assert tracker.alloc.account_name() == account_name + assert tracker.alloc.account == account_name self.form.fields['account'].setCurrentText(account_name) tracker.show() tracker.hide_info() @@ -278,7 +278,7 @@ class SettingsPane: # min(round(prop * slots), slots) min(used, slots) ) - self.update_account_icons({alloc.account_name(): pp.live_pp}) + self.update_account_icons({alloc.account: pp.live_pp}) def update_account_icons( self, @@ -332,7 +332,7 @@ class SettingsPane: ) log.info( - f'Starting pnl display for {tracker.alloc.account_name()}') + f'Starting pnl display for {tracker.alloc.account}') self.order_mode.nursery.start_soon( display_pnl, feed, @@ -654,7 +654,7 @@ class PositionTracker: 'fiat_size': round(price * size, ndigits=2), # TODO: per account lines on a single (or very related) symbol - 'account': self.alloc.account_name(), + 'account': self.alloc.account, }) line.show() diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index 7f169a22..f7b5a836 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -223,7 +223,7 @@ class OrderMode: order = self._staged_order = Order( action=action, price=price, - account=self.current_pp.alloc.account_name(), + account=self.current_pp.alloc.account, size=0, symbol=symbol, brokers=symbol.brokers, @@ -600,7 +600,6 @@ async def open_order_mode( # allocator alloc = mk_allocator( symbol=symbol, - accounts=accounts, account=account_name, # if this startup size is greater the allocator limit, @@ -640,7 +639,6 @@ async def open_order_mode( # allocator alloc = mk_allocator( symbol=symbol, - accounts=accounts, account=account_name, startup_pp=startup_pp, )