Add signals trading enabled

This commit is contained in:
Mark Veidemanis 2023-02-15 20:02:38 +00:00
parent 5c090433a3
commit 3854bdcc7d
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 38 additions and 3 deletions

View File

@ -130,6 +130,8 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
"entry_signals",
"exit_signals",
"trend_signals",
"signal_trading_enabled",
"active_management_enabled",
"enabled",
)
@ -144,6 +146,8 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
"entry_signals": "Callbacks received to these signals will trigger a trade.",
"exit_signals": "Callbacks received to these signals will close all trades for the symbol on the account.",
"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.",
"enabled": "Whether the strategy is enabled.",
}

View File

@ -0,0 +1,23 @@
# Generated by Django 4.1.6 on 2023-02-15 19:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0069_remove_strategy_order_type_and_more'),
]
operations = [
migrations.AddField(
model_name='strategy',
name='active_management_enabled',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='strategy',
name='signal_trading_enabled',
field=models.BooleanField(default=False),
),
]

View File

@ -379,6 +379,8 @@ class Strategy(models.Model):
Signal, related_name="trend_strategies", blank=True
)
enabled = models.BooleanField(default=False)
signal_trading_enabled = models.BooleanField(default=False)
active_management_enabled = models.BooleanField(default=False)
trends = models.JSONField(null=True, blank=True)
asset_group = models.ForeignKey(

View File

@ -517,7 +517,9 @@ def process_callback(callback):
# Scan for trend
log.debug("Scanning for trend strategies...")
strategies = Strategy.objects.filter(trend_signals=callback.signal, enabled=True)
strategies = Strategy.objects.filter(
trend_signals=callback.signal, signal_trading_enabled=True, enabled=True
)
log.debug(f"Matched strategies: {strategies}")
for strategy in strategies:
log.debug(f"Executing strategy {strategy}")
@ -528,7 +530,9 @@ def process_callback(callback):
# Scan for entry
log.debug("Scanning for entry strategies...")
strategies = Strategy.objects.filter(entry_signals=callback.signal, enabled=True)
strategies = Strategy.objects.filter(
entry_signals=callback.signal, signal_trading_enabled=True, enabled=True
)
log.debug(f"Matched strategies: {strategies}")
for strategy in strategies:
log.debug(f"Executing strategy {strategy}")
@ -539,7 +543,9 @@ def process_callback(callback):
# Scan for exit
log.debug("Scanning for exit strategies...")
strategies = Strategy.objects.filter(exit_signals=callback.signal, enabled=True)
strategies = Strategy.objects.filter(
exit_signals=callback.signal, signal_trading_enabled=True, enabled=True
)
log.debug(f"Matched strategies: {strategies}")
for strategy in strategies:
log.debug(f"Executing strategy {strategy}")