Allow disabling accounts

master
Mark Veidemanis 1 year ago
parent a18c150fe2
commit b31a2d1464
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -111,13 +111,22 @@ class SignalForm(RestrictedFormMixin, ModelForm):
class AccountForm(RestrictedFormMixin, ModelForm):
class Meta:
model = Account
fields = ("name", "exchange", "api_key", "api_secret", "sandbox", "risk_model")
fields = (
"name",
"exchange",
"api_key",
"api_secret",
"sandbox",
"enabled",
"risk_model",
)
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.",
"enabled": "Whether the account is enabled.",
"risk_model": "The risk model to use for this account.",
}

@ -0,0 +1,18 @@
# Generated by Django 4.1.4 on 2023-01-01 15:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0049_rename_riskmodel_account_risk_model'),
]
operations = [
migrations.AddField(
model_name='account',
name='enabled',
field=models.BooleanField(default=True),
),
]

@ -109,6 +109,7 @@ class Account(models.Model):
api_key = models.CharField(max_length=255)
api_secret = models.CharField(max_length=255)
sandbox = models.BooleanField(default=False)
enabled = models.BooleanField(default=True)
supported_symbols = models.JSONField(default=list)
instruments = models.JSONField(default=list)
currency = models.CharField(max_length=255, null=True, blank=True)

@ -286,6 +286,13 @@ def execute_strategy(callback, strategy, func):
log.debug("Not within trading time range")
return
# Don't touch the account if it's disabled.
# We still want to set trends, though.
if func in ("entry", "exit"):
if not strategy.account.enabled:
log.debug("Account is disabled, exiting")
return
# Instruments supported by the account
if not strategy.account.instruments:
strategy.account.update_info()

@ -53,7 +53,8 @@ class Positions(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
if account_id:
self.extra_context["account_id"] = account_id
items = []
accounts = Account.objects.filter(user=self.request.user)
# Only get enabled accounts for positions
accounts = Account.objects.filter(user=self.request.user, enabled=True)
for account in accounts:
try:
positions = account.client.get_all_positions()

@ -22,7 +22,8 @@ class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
def get_queryset(self, **kwargs):
items = []
accounts = Account.objects.filter(user=self.request.user)
# Only get enabled accounts
accounts = Account.objects.filter(user=self.request.user, enabled=True)
for account in accounts:
try:
details = account.client.get_account()

Loading…
Cancel
Save