Add more hooks to active management
This commit is contained in:
@@ -6,6 +6,7 @@ from mixins.restrictions import RestrictedFormMixin
|
||||
|
||||
from .models import ( # AssetRestriction,
|
||||
Account,
|
||||
ActiveManagementPolicy,
|
||||
AssetGroup,
|
||||
AssetRule,
|
||||
Hook,
|
||||
@@ -132,6 +133,7 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
"trend_signals",
|
||||
"signal_trading_enabled",
|
||||
"active_management_enabled",
|
||||
"active_management_policy",
|
||||
"enabled",
|
||||
)
|
||||
|
||||
@@ -148,6 +150,7 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
"trend_signals": "Callbacks received to these signals will limit the trading direction of the given symbol to the callback direction until further notice.",
|
||||
"signal_trading_enabled": "Whether the strategy will place trades based on signals.",
|
||||
"active_management_enabled": "Whether the strategy will amend/remove trades on the account that violate the rules.",
|
||||
"active_management_policy": "The policy to use for active management.",
|
||||
"enabled": "Whether the strategy is enabled.",
|
||||
}
|
||||
|
||||
@@ -174,9 +177,9 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
super(StrategyForm, self).clean()
|
||||
entry_signals = self.cleaned_data.get("entry_signals")
|
||||
exit_signals = self.cleaned_data.get("exit_signals")
|
||||
cleaned_data = super(StrategyForm, self).clean()
|
||||
entry_signals = cleaned_data.get("entry_signals")
|
||||
exit_signals = cleaned_data.get("exit_signals")
|
||||
for entry in entry_signals.all():
|
||||
if entry in exit_signals.all():
|
||||
self._errors["entry_signals"] = self.error_class(
|
||||
@@ -213,6 +216,14 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
"You cannot have entry and exit signals that are the same direction. At least one must be opposing."
|
||||
]
|
||||
)
|
||||
if cleaned_data.get("active_management_enabled"):
|
||||
if not cleaned_data.get("active_management_policy"):
|
||||
self.add_error(
|
||||
"active_management_policy",
|
||||
"You must select an active management policy if active management is enabled.",
|
||||
)
|
||||
return
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class TradeForm(RestrictedFormMixin, ModelForm):
|
||||
@@ -381,3 +392,34 @@ class OrderSettingsForm(RestrictedFormMixin, ModelForm):
|
||||
"trailing_stop_loss_percent": "The trailing stop loss will be set at this percentage above/below the entry price. A trailing stop loss will follow the price as it moves in your favor.",
|
||||
"trade_size_percent": "Percentage of the account balance to use for each trade.",
|
||||
}
|
||||
|
||||
|
||||
class ActiveManagementPolicyForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = ActiveManagementPolicy
|
||||
fields = (
|
||||
"name",
|
||||
"when_trading_time_violated",
|
||||
"when_trends_violated",
|
||||
"when_position_size_violated",
|
||||
"when_protection_violated",
|
||||
"when_asset_groups_violated",
|
||||
"when_max_open_trades_violated",
|
||||
"when_max_open_trades_per_symbol_violated",
|
||||
"when_max_loss_violated",
|
||||
"when_max_risk_violated",
|
||||
"when_crossfilter_violated",
|
||||
)
|
||||
help_texts = {
|
||||
"name": "Name of the active management policy. Informational only.",
|
||||
"when_trading_time_violated": "The action to take when the trading time is violated.",
|
||||
"when_trends_violated": "The action to take a trade against the trend is discovered.",
|
||||
"when_position_size_violated": "The action to take when a trade exceeding the position size is discovered.",
|
||||
"when_protection_violated": "The action to take when a trade violating/lacking defined TP/SL/TSL is discovered.",
|
||||
"when_asset_groups_violated": "The action to take when a trade violating the asset group rules is discovered.",
|
||||
"when_max_open_trades_violated": "The action to take when a trade puts the account above the maximum open trades.",
|
||||
"when_max_open_trades_per_symbol_violated": "The action to take when a trade puts the account above the maximum open trades per symbol.",
|
||||
"when_max_loss_violated": "The action to take when a trade puts the account above the maximum loss.",
|
||||
"when_max_risk_violated": "The action to take when a trade exposes the account to more than the maximum risk.",
|
||||
"when_crossfilter_violated": "The action to take when a trade is deemed to conflict with another -- e.g. a buy and sell on the same asset.",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user