Move risk model to strategy
This commit is contained in:
@@ -181,9 +181,12 @@ def get_price_bound(direction, strategy, price, current_price):
|
||||
"""
|
||||
|
||||
# Convert the callback price deviation to a ratio
|
||||
callback_price_deviation_as_ratio = D(
|
||||
strategy.callback_price_deviation_percent
|
||||
) / D(100)
|
||||
if strategy.risk_model is not None:
|
||||
callback_price_deviation_as_ratio = D(
|
||||
strategy.risk_model.callback_price_deviation_percent
|
||||
) / D(100)
|
||||
else:
|
||||
callback_price_deviation_as_ratio = D(0.5) / D(100)
|
||||
log.debug(f"Callback price deviation as ratio: {callback_price_deviation_as_ratio}")
|
||||
|
||||
maximum_price_deviation = D(current_price) * D(callback_price_deviation_as_ratio)
|
||||
@@ -197,7 +200,11 @@ def get_price_bound(direction, strategy, price, current_price):
|
||||
return None
|
||||
|
||||
# Convert the maximum price slippage to a ratio
|
||||
price_slippage_as_ratio = D(strategy.price_slippage_percent) / D(100)
|
||||
if strategy.risk_model is not None:
|
||||
price_slippage_as_ratio = D(strategy.risk_model.price_slippage_percent) / D(100)
|
||||
else:
|
||||
# Pretty liberal default
|
||||
price_slippage_as_ratio = D(2.5) / D(100)
|
||||
log.debug(f"Maximum price slippage as ratio: {price_slippage_as_ratio}")
|
||||
|
||||
# Calculate the price bound by multiplying with the price
|
||||
@@ -453,8 +460,8 @@ def execute_strategy(callback, strategy, func):
|
||||
)
|
||||
new_trade.save()
|
||||
|
||||
if account.risk_model is not None:
|
||||
allowed = check_risk(account.risk_model, account, new_trade)
|
||||
if strategy.risk_model is not None:
|
||||
allowed = check_risk(strategy.risk_model, account, new_trade)
|
||||
if not allowed["allowed"]:
|
||||
new_trade.status = "rejected"
|
||||
new_trade.information = allowed["reason"]
|
||||
|
||||
Reference in New Issue
Block a user