Make signals configurable
This commit is contained in:
@@ -3,7 +3,7 @@ from django.contrib.auth.forms import UserCreationForm
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.forms import ModelForm
|
||||
|
||||
from .models import Account, Hook, Strategy, Trade, TradingTime, User
|
||||
from .models import Account, Hook, Signal, Strategy, Trade, TradingTime, User
|
||||
|
||||
# flake8: noqa: E501
|
||||
|
||||
@@ -61,23 +61,36 @@ class CustomUserCreationForm(UserCreationForm):
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
# All string/multiple choice fields
|
||||
class HookForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = Hook
|
||||
fields = (
|
||||
"name",
|
||||
"hook",
|
||||
"direction",
|
||||
)
|
||||
help_texts = {
|
||||
"name": "Name of the hook. Informational only.",
|
||||
"hook": "The URL slug to use for the hook. Make it unique.",
|
||||
"direction": "The direction of the hook. This is used to determine if the hook is a buy or sell.",
|
||||
}
|
||||
|
||||
|
||||
# All string/multiple choice fields
|
||||
class SignalForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = Signal
|
||||
fields = (
|
||||
"name",
|
||||
"signal",
|
||||
"hook",
|
||||
"direction",
|
||||
)
|
||||
help_texts = {
|
||||
"name": "Name of the signal. Informational only.",
|
||||
"signal": "The name of the signal in Drakdoo. Copy it from there.",
|
||||
"hook": "The hook this signal belongs to.",
|
||||
"direction": "The direction of the signal. This is used to determine if the signal is a buy or sell.",
|
||||
}
|
||||
|
||||
|
||||
class AccountForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = Account
|
||||
@@ -97,7 +110,6 @@ class AccountForm(RestrictedFormMixin, ModelForm):
|
||||
}
|
||||
|
||||
|
||||
# Restricted mixin for account and hooks
|
||||
class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = Strategy
|
||||
@@ -108,7 +120,8 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
"trading_times",
|
||||
"order_type",
|
||||
"time_in_force",
|
||||
"hooks",
|
||||
"entry_signals",
|
||||
"exit_signals",
|
||||
"enabled",
|
||||
"take_profit_percent",
|
||||
"stop_loss_percent",
|
||||
@@ -125,7 +138,8 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
"trading_times": "When the strategy will place new trades.",
|
||||
"order_type": "Market: Buy/Sell at the current market price. Limit: Buy/Sell at a specified price. Limits protect you more against market slippage.",
|
||||
"time_in_force": "The time in force controls how the order is executed.",
|
||||
"hooks": "The hooks to attach to this strategy. Callbacks received to these hooks will trigger a trade.",
|
||||
"entry_signals": "The entry signals to attach to this strategy. Callbacks received to these signals will trigger a trade.",
|
||||
"exit_signals": "The exit signals to attach to this strategy. Callbacks received to these signals will close all trades for the symbol on the account.",
|
||||
"enabled": "Whether the strategy is enabled.",
|
||||
"take_profit_percent": "The take profit will be set at this percentage above/below the entry price.",
|
||||
"stop_loss_percent": "The stop loss will be set at this percentage above/below the entry price.",
|
||||
@@ -135,15 +149,23 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||
"trade_size_percent": "Percentage of the account balance to use for each trade.",
|
||||
}
|
||||
|
||||
hooks = forms.ModelMultipleChoiceField(
|
||||
queryset=Hook.objects.all(), widget=forms.CheckboxSelectMultiple
|
||||
entry_signals = forms.ModelMultipleChoiceField(
|
||||
queryset=Signal.objects.all(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
help_text=Meta.help_texts["entry_signals"],
|
||||
required=False,
|
||||
)
|
||||
exit_signals = forms.ModelMultipleChoiceField(
|
||||
queryset=Signal.objects.all(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
help_text=Meta.help_texts["exit_signals"],
|
||||
required=False,
|
||||
)
|
||||
trading_times = forms.ModelMultipleChoiceField(
|
||||
queryset=TradingTime.objects.all(), widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
|
||||
# Restricted mixin for account
|
||||
class TradeForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = Trade
|
||||
|
||||
Reference in New Issue
Block a user