Add risk model and views

This commit is contained in:
Mark Veidemanis 2022-12-21 21:35:59 +00:00
parent 52ddef4c8f
commit 4e24ceac72
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 51 additions and 17 deletions

View File

@ -112,6 +112,9 @@ class Account(models.Model):
supported_symbols = models.JSONField(default=list)
instruments = models.JSONField(default=list)
currency = models.CharField(max_length=255, null=True, blank=True)
riskmodel = models.ForeignKey(
"core.RiskModel", on_delete=models.SET_NULL, null=True, blank=True
)
def __str__(self):
name = f"{self.name} ({self.exchange})"
@ -375,20 +378,11 @@ class NotificationSettings(models.Model):
return f"Notification settings for {self.user}"
# class Perms(models.Model):
# class Meta:
# permissions = (
# ("bypass_hashing", "Can bypass field hashing"), #
# ("bypass_blacklist", "Can bypass the blacklist"), #
# ("bypass_encryption", "Can bypass field encryption"), #
# ("bypass_obfuscation", "Can bypass field obfuscation"), #
# ("bypass_delay", "Can bypass data delay"), #
# ("bypass_randomisation", "Can bypass data randomisation"), #
# ("post_irc", "Can post to IRC"),
# ("post_discord", "Can post to Discord"),
# ("query_search", "Can search with query strings"), #
# ("use_insights", "Can use the Insights page"),
# ("index_int", "Can use the internal index"),
# ("index_meta", "Can use the meta index"),
# ("restricted_sources", "Can access restricted sources"),
# )
class RiskModel(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
# Maximum amount of money to have lost from the initial balance to stop trading
maximum_loss_ratio = models.FloatField(default=0.05)
# Maximum amount of money to risk on all open trades
maximum_risk_ratio = models.FloatField(default=0.05)

View File

@ -254,6 +254,9 @@
<a class="navbar-item" href="{% url 'tradingtimes' type='page' %}">
Trading Times
</a>
<a class="navbar-item" href="{% url 'risk' type='page' %}">
Risk Management
</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">

37
core/views/risk.py Normal file
View File

@ -0,0 +1,37 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from core.forms import RiskForm
from core.models import Risk
from core.util import logs
from core.views import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate
log = logs.get_logger(__name__)
class RiskList(LoginRequiredMixin, ObjectList):
list_template = "partials/signal-list.html"
model = Risk
page_title = "List of risk management strategies. Linked to accounts."
list_url_name = "risk"
list_url_args = ["type"]
submit_url_name = "risk_create"
class RiskCreate(LoginRequiredMixin, ObjectCreate):
model = Risk
form_class = RiskForm
submit_url_name = "risk_create"
class RiskUpdate(LoginRequiredMixin, ObjectUpdate):
model = Risk
form_class = RiskForm
submit_url_name = "risk_update"
class RiskDelete(LoginRequiredMixin, ObjectDelete):
model = Risk