Create alloc instance in factory body, template out defaults loading
parent
214c622328
commit
d38a6bf032
|
@ -250,27 +250,45 @@ class Allocator(BaseModel):
|
||||||
|
|
||||||
def mk_allocator(
|
def mk_allocator(
|
||||||
|
|
||||||
alloc: Allocator,
|
symbol: Symbol,
|
||||||
|
accounts: dict[str, str],
|
||||||
startup_pp: Position,
|
startup_pp: Position,
|
||||||
|
|
||||||
) -> (float, Allocator):
|
# default allocation settings
|
||||||
|
defaults: dict[str, float] = {
|
||||||
|
'account': None, # select paper by default
|
||||||
|
'size_unit': _size_units['currency'],
|
||||||
|
'units_limit': 400,
|
||||||
|
'currency_limit': 5e3,
|
||||||
|
'slots': 4,
|
||||||
|
},
|
||||||
|
**kwargs,
|
||||||
|
|
||||||
asset_type = alloc.symbol.type_key
|
) -> Allocator:
|
||||||
|
|
||||||
|
if kwargs:
|
||||||
|
defaults.update(kwargs)
|
||||||
|
|
||||||
# load and retreive user settings for default allocations
|
# load and retreive user settings for default allocations
|
||||||
# ``config.toml``
|
# ``config.toml``
|
||||||
slots = 4
|
user_def = {
|
||||||
currency_limit = 5e3
|
'currency_limit': 5e3,
|
||||||
|
'slots': 4,
|
||||||
|
}
|
||||||
|
|
||||||
alloc.slots = slots
|
defaults.update(user_def)
|
||||||
alloc.currency_limit = currency_limit
|
|
||||||
|
|
||||||
# default entry sizing
|
alloc = Allocator(
|
||||||
if asset_type in ('stock', 'crypto', 'forex'):
|
symbol=symbol,
|
||||||
|
_accounts=accounts,
|
||||||
|
**defaults,
|
||||||
|
)
|
||||||
|
|
||||||
alloc.size_unit = '$ size'
|
asset_type = symbol.type_key
|
||||||
|
|
||||||
elif asset_type in ('future', 'option', 'futures_option'):
|
# specific configs by asset class / type
|
||||||
|
|
||||||
|
if asset_type in ('future', 'option', 'futures_option'):
|
||||||
|
|
||||||
# since it's harder to know how currency "applies" in this case
|
# since it's harder to know how currency "applies" in this case
|
||||||
# given leverage properties
|
# given leverage properties
|
||||||
|
@ -278,7 +296,7 @@ def mk_allocator(
|
||||||
|
|
||||||
# set units limit to slots size thus making make the next
|
# set units limit to slots size thus making make the next
|
||||||
# entry step 1.0
|
# entry step 1.0
|
||||||
alloc.units_limit = slots
|
alloc.units_limit = alloc.slots
|
||||||
|
|
||||||
# if the current position is already greater then the limit
|
# if the current position is already greater then the limit
|
||||||
# settings, increase the limit to the current position
|
# settings, increase the limit to the current position
|
||||||
|
@ -288,14 +306,10 @@ def mk_allocator(
|
||||||
if startup_size > alloc.currency_limit:
|
if startup_size > alloc.currency_limit:
|
||||||
alloc.currency_limit = round(startup_size, ndigits=2)
|
alloc.currency_limit = round(startup_size, ndigits=2)
|
||||||
|
|
||||||
limit_text = alloc.currency_limit
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
startup_size = startup_pp.size
|
startup_size = startup_pp.size
|
||||||
|
|
||||||
if startup_size > alloc.units_limit:
|
if startup_size > alloc.units_limit:
|
||||||
alloc.units_limit = startup_size
|
alloc.units_limit = startup_size
|
||||||
|
|
||||||
limit_text = alloc.units_limit
|
return alloc
|
||||||
|
|
||||||
return limit_text, alloc
|
|
||||||
|
|
Loading…
Reference in New Issue