Write tests for asset filter
parent
ce0b75ae2d
commit
313c7f79d0
@ -0,0 +1,28 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from core.trading.assetfilter import get_allowed
|
||||
from core.models import AssetGroup, User
|
||||
|
||||
class AssetfilterTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_user(
|
||||
username="testuser",
|
||||
email="test@example.com",
|
||||
)
|
||||
self.group = AssetGroup.objects.create(
|
||||
user=self.user,
|
||||
name="Group1",
|
||||
description="Test group",
|
||||
)
|
||||
|
||||
|
||||
def test_get_allowed(self):
|
||||
"""
|
||||
Test that the asset filter works.
|
||||
"""
|
||||
self.group.allowed = {"EUR_USD": True, "EUR_GBP": False}
|
||||
self.assertTrue(get_allowed(self.group, "EUR_USD", "buy"))
|
||||
self.assertFalse(get_allowed(self.group, "EUR_GBP", "sell"))
|
||||
|
||||
# Default true
|
||||
self.assertTrue(get_allowed(self.group, "nonexistent", "sell"))
|
@ -1,7 +1,14 @@
|
||||
def get_allowed(strategy, symbol, direction):
|
||||
def get_allowed(group, symbol, direction):
|
||||
"""
|
||||
Determine whether the trade is allowed according to the Asset Groups
|
||||
linked to the strategy.
|
||||
"""
|
||||
# TODO: figure out what to do with direction
|
||||
|
||||
# asset_group = strategy.
|
||||
allowed = group.allowed
|
||||
if not isinstance(allowed, dict):
|
||||
return False
|
||||
if symbol not in allowed:
|
||||
return True
|
||||
|
||||
return allowed[symbol]
|
||||
|
Loading…
Reference in New Issue