|
|
|
@ -5,6 +5,7 @@ from core.exchanges import GenericAPIError, common
|
|
|
|
|
from core.lib.notify import sendmsg
|
|
|
|
|
from core.models import Account, Strategy, Trade
|
|
|
|
|
from core.trading.crossfilter import crossfilter
|
|
|
|
|
from core.trading.risk import check_risk
|
|
|
|
|
from core.util import logs
|
|
|
|
|
|
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
@ -488,6 +489,19 @@ 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 not allowed["allowed"]:
|
|
|
|
|
new_trade.status = "rejected"
|
|
|
|
|
new_trade.information = allowed["reason"]
|
|
|
|
|
new_trade.save()
|
|
|
|
|
sendmsg(
|
|
|
|
|
user,
|
|
|
|
|
f"Trade rejected due to risk model: {allowed['reason']}",
|
|
|
|
|
title="Trade rejected",
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Run the crossfilter to ensure we don't trade the same pair in opposite directions
|
|
|
|
|
filtered = crossfilter(account, symbol, direction, func)
|
|
|
|
|
|
|
|
|
|