Drop `.accounts` field from allocator
parent
4afafce297
commit
f4740da6a2
|
@ -86,14 +86,7 @@ class Allocator(BaseModel):
|
||||||
underscore_attrs_are_private = False
|
underscore_attrs_are_private = False
|
||||||
|
|
||||||
symbol: Symbol
|
symbol: Symbol
|
||||||
accounts: bidict[str, Optional[str]]
|
|
||||||
account: Optional[str] = 'paper'
|
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_unit: SizeUnit = 'currency'
|
||||||
_size_units: dict[str, Optional[str]] = _size_units
|
_size_units: dict[str, Optional[str]] = _size_units
|
||||||
|
|
||||||
|
@ -128,9 +121,6 @@ class Allocator(BaseModel):
|
||||||
else:
|
else:
|
||||||
return self.units_limit
|
return self.units_limit
|
||||||
|
|
||||||
def account_name(self) -> str:
|
|
||||||
return self.accounts.inverse[self.account]
|
|
||||||
|
|
||||||
def next_order_info(
|
def next_order_info(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
|
@ -234,7 +224,7 @@ class Allocator(BaseModel):
|
||||||
'slots_used': slots_used,
|
'slots_used': slots_used,
|
||||||
|
|
||||||
# update line LHS label with account name
|
# update line LHS label with account name
|
||||||
'account': self.account_name(),
|
'account': self.account,
|
||||||
}
|
}
|
||||||
|
|
||||||
def slots_used(
|
def slots_used(
|
||||||
|
@ -264,7 +254,6 @@ class Allocator(BaseModel):
|
||||||
def mk_allocator(
|
def mk_allocator(
|
||||||
|
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
accounts: dict[str, str],
|
|
||||||
startup_pp: Position,
|
startup_pp: Position,
|
||||||
|
|
||||||
# default allocation settings
|
# default allocation settings
|
||||||
|
@ -293,7 +282,6 @@ def mk_allocator(
|
||||||
|
|
||||||
alloc = Allocator(
|
alloc = Allocator(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
accounts=accounts,
|
|
||||||
**defaults,
|
**defaults,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -185,11 +185,11 @@ class SettingsPane:
|
||||||
f'Account `{account_name}` can not be set for {sym}'
|
f'Account `{account_name}` can not be set for {sym}'
|
||||||
)
|
)
|
||||||
self.form.fields['account'].setCurrentText(
|
self.form.fields['account'].setCurrentText(
|
||||||
old_tracker.alloc.account_name())
|
old_tracker.alloc.account)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.order_mode.current_pp = tracker
|
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)
|
self.form.fields['account'].setCurrentText(account_name)
|
||||||
tracker.show()
|
tracker.show()
|
||||||
tracker.hide_info()
|
tracker.hide_info()
|
||||||
|
@ -278,7 +278,7 @@ class SettingsPane:
|
||||||
# min(round(prop * slots), slots)
|
# min(round(prop * slots), slots)
|
||||||
min(used, 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(
|
def update_account_icons(
|
||||||
self,
|
self,
|
||||||
|
@ -332,7 +332,7 @@ class SettingsPane:
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
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(
|
self.order_mode.nursery.start_soon(
|
||||||
display_pnl,
|
display_pnl,
|
||||||
feed,
|
feed,
|
||||||
|
@ -654,7 +654,7 @@ class PositionTracker:
|
||||||
'fiat_size': round(price * size, ndigits=2),
|
'fiat_size': round(price * size, ndigits=2),
|
||||||
|
|
||||||
# TODO: per account lines on a single (or very related) symbol
|
# TODO: per account lines on a single (or very related) symbol
|
||||||
'account': self.alloc.account_name(),
|
'account': self.alloc.account,
|
||||||
})
|
})
|
||||||
line.show()
|
line.show()
|
||||||
|
|
||||||
|
|
|
@ -223,7 +223,7 @@ class OrderMode:
|
||||||
order = self._staged_order = Order(
|
order = self._staged_order = Order(
|
||||||
action=action,
|
action=action,
|
||||||
price=price,
|
price=price,
|
||||||
account=self.current_pp.alloc.account_name(),
|
account=self.current_pp.alloc.account,
|
||||||
size=0,
|
size=0,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
brokers=symbol.brokers,
|
brokers=symbol.brokers,
|
||||||
|
@ -600,7 +600,6 @@ async def open_order_mode(
|
||||||
# allocator
|
# allocator
|
||||||
alloc = mk_allocator(
|
alloc = mk_allocator(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
accounts=accounts,
|
|
||||||
account=account_name,
|
account=account_name,
|
||||||
|
|
||||||
# if this startup size is greater the allocator limit,
|
# if this startup size is greater the allocator limit,
|
||||||
|
@ -640,7 +639,6 @@ async def open_order_mode(
|
||||||
# allocator
|
# allocator
|
||||||
alloc = mk_allocator(
|
alloc = mk_allocator(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
accounts=accounts,
|
|
||||||
account=account_name,
|
account=account_name,
|
||||||
startup_pp=startup_pp,
|
startup_pp=startup_pp,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue