Describe all model fields

Mark Veidemanis 1 year ago
parent 06865d0aa9
commit d3694d1821
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -5,6 +5,8 @@ from django.forms import ModelForm
from .models import Account, Hook, Strategy, Trade, TradingTime, User
# flake8: noqa: E501
class RestrictedFormMixin:
"""
@ -14,7 +16,6 @@ class RestrictedFormMixin:
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")
super().__init__(*args, **kwargs)
print(self.fields)
for field in self.fields:
# Check it's not something like a CharField which has no queryset
if not hasattr(self.fields[field], "queryset"):
@ -69,6 +70,11 @@ class HookForm(RestrictedFormMixin, ModelForm):
"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
@ -82,6 +88,13 @@ class AccountForm(RestrictedFormMixin, ModelForm):
"api_secret",
"sandbox",
)
help_texts = {
"name": "Name of the account. Informational only.",
"exchange": "The exchange to use for this account.",
"api_key": "The API key or username for the account.",
"api_secret": "The API secret or password/token for the account.",
"sandbox": "Whether to use the sandbox/demo or not.",
}
# Restricted mixin for account and hooks
@ -105,6 +118,23 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
"trade_size_percent",
)
help_texts = {
"name": "Name of the strategy. Informational only.",
"description": "Description of the strategy. Informational only.",
"account": "The account to use for this strategy.",
"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.",
"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.",
"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.",
"price_slippage_percent": "The price slippage is the maximum percent the price can move against you before the trade is cancelled. Limit orders will be set at this percentage against your favour. Market orders will have a price bound set if this is supported.",
"callback_price_deviation_percent": "The callback price deviation is the maximum percent the price can change between receiving the callback and acting on it. This protects against rogue or delayed callbacks. Keep it low.",
"trade_size_percent": "Percentage of the account balance to use for each trade.",
}
hooks = forms.ModelMultipleChoiceField(
queryset=Hook.objects.all(), widget=forms.CheckboxSelectMultiple
)
@ -129,6 +159,18 @@ class TradeForm(RestrictedFormMixin, ModelForm):
"take_profit",
"direction",
)
help_texts = {
"account": "The account to use for this trade.",
"symbol": "The symbol to trade.",
"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.",
"amount": "The amount to trade in the quote currency (the second part of the symbol if applicable, otherwise your account base currency).",
"price": "The price to trade at. Sets this price as the trigger price for limit orders. Sets a price bound (if supported) for market orders.",
"stop_loss": "The stop loss price. This will be set at the specified price.",
"trailing_stop_loss": "The trailing stop loss price. This will be set at the specified price and will follow the price as it moves in your favor.",
"take_profit": "The take profit price. This will be set at the specified price.",
"direction": "The direction of the trade. This is used to determine if the trade is a buy or sell.",
}
class TradingTimeForm(RestrictedFormMixin, ModelForm):
@ -142,3 +184,11 @@ class TradingTimeForm(RestrictedFormMixin, ModelForm):
"end_day",
"end_time",
)
help_texts = {
"name": "Name of the trading time. Informational only.",
"description": "Description of the trading time. Informational only.",
"start_day": "The day of the week to start trading.",
"start_time": "The time of day to start trading.",
"end_day": "The day of the week to stop trading.",
"end_time": "The time of day to stop trading.",
}

Loading…
Cancel
Save