Send the user a message when an asset restriction is hit

This commit is contained in:
Mark Veidemanis 2023-02-11 18:25:09 +00:00
parent 313c7f79d0
commit da9f32e882
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 15 additions and 9 deletions

View File

@ -1,7 +1,8 @@
from django.test import TestCase from django.test import TestCase
from core.trading.assetfilter import get_allowed
from core.models import AssetGroup, User from core.models import AssetGroup, User
from core.trading.assetfilter import get_allowed
class AssetfilterTestCase(TestCase): class AssetfilterTestCase(TestCase):
def setUp(self): def setUp(self):
@ -15,7 +16,6 @@ class AssetfilterTestCase(TestCase):
description="Test group", description="Test group",
) )
def test_get_allowed(self): def test_get_allowed(self):
""" """
Test that the asset filter works. Test that the asset filter works.
@ -25,4 +25,4 @@ class AssetfilterTestCase(TestCase):
self.assertFalse(get_allowed(self.group, "EUR_GBP", "sell")) self.assertFalse(get_allowed(self.group, "EUR_GBP", "sell"))
# Default true # Default true
self.assertTrue(get_allowed(self.group, "nonexistent", "sell")) self.assertTrue(get_allowed(self.group, "nonexistent", "sell"))

View File

@ -328,12 +328,18 @@ def execute_strategy(callback, strategy, func):
# Callback now verified # Callback now verified
# Check against the asset groups # Check against the asset groups
if func == "entry": if func == "entry" and strategy.assetgroup is not None:
if strategy.assetgroup is not None: allowed = assetfilter.get_allowed(strategy, symbol, direction)
allowed = assetfilter.get_allowed(strategy, symbol, direction) if not allowed:
if not allowed: log.debug(
log.debug(f"Asset trading not allowed for {strategy}: {symbol}") f"Denied trading {symbol} due to asset filter {strategy.assetgroup}"
return )
sendmsg(
user,
f"Denied trading {symbol} due to asset filter {strategy.assetgroup}",
title="Asset filter denied",
)
return
if func == "exit": if func == "exit":
check_exit = crossfilter(account, symbol, direction, func) check_exit = crossfilter(account, symbol, direction, func)