Implement checking direction with assetfilter

This commit is contained in:
2023-02-13 17:47:47 +00:00
parent dcfb963be6
commit 0321aff9d5
4 changed files with 97 additions and 20 deletions

View File

@@ -16,16 +16,55 @@ class AssetfilterTestCase(TestCase):
description="Test group",
)
def test_get_allowed(self):
def test_get_allowed_negative(self):
"""
Test that the asset filter works.
Test that the asset filter works on negative aggregations.
"""
self.group.allowed = {"EUR_USD": True, "EUR_GBP": False}
self.assertTrue(assetfilter.get_allowed(self.group, "EUR_USD", "buy"))
self.assertFalse(assetfilter.get_allowed(self.group, "EUR_GBP", "sell"))
# We have negative news about EUR
self.group.allowed = {"EUR": False}
self.group.save()
# Default true
self.assertTrue(assetfilter.get_allowed(self.group, "nonexistent", "sell"))
# This means that:
# * base == EUR: long is not allowed, short is allowed
# * quote == EUR: long is allowed, short is not allowed
# We are betting on it going down, so we short base, and long quote.
# Test that short on base of EUR is allowed
self.assertTrue(assetfilter.get_allowed(self.group, "EUR", "USD", "short"))
# Test that long on quote of EUR is allowed
self.assertTrue(assetfilter.get_allowed(self.group, "USD", "EUR", "long"))
# Test that long on base of EUR is not allowed
self.assertFalse(assetfilter.get_allowed(self.group, "EUR", "USD", "long"))
# Test that short on quote of EUR is not allowed
self.assertFalse(assetfilter.get_allowed(self.group, "USD", "EUR", "short"))
def test_get_allowed_positive(self):
"""
Test that the asset filter works on positive aggregations.
"""
# We have positive news about EUR
self.group.allowed = {"EUR": True}
self.group.save()
# This means that:
# * base == EUR: long is allowed, short is not allowed
# * quote == EUR: long is not allowed, short is allowed
# We are betting on it going up, so we long base, and short quote.
# Test that long on base of EUR is allowed
self.assertTrue(assetfilter.get_allowed(self.group, "EUR", "USD", "long"))
# Test that short on quote of EUR is allowed
self.assertTrue(assetfilter.get_allowed(self.group, "USD", "EUR", "short"))
# Test that short on base of EUR is not allowed
self.assertFalse(assetfilter.get_allowed(self.group, "EUR", "USD", "short"))
# Test that long on quote of EUR is not allowed
self.assertFalse(assetfilter.get_allowed(self.group, "USD", "EUR", "long"))
def test_check_asset_aggregation(self):
"""