Drop `.accounts` field from allocator

chart_mod_breakup
Tyler Goodlet 2021-09-14 13:10:39 -04:00
parent 4afafce297
commit f4740da6a2
3 changed files with 7 additions and 21 deletions

View File

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

View File

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

View File

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