Add more hooks to active management

This commit is contained in:
2023-02-17 07:20:15 +00:00
parent dd3b3521d9
commit 1dbb3fcf79
17 changed files with 716 additions and 47 deletions

View File

@@ -1,7 +1,17 @@
from datetime import time
from os import getenv
from unittest.mock import Mock, patch
from core.models import Account, User
from core.models import (
Account,
Hook,
OrderSettings,
RiskModel,
Signal,
Strategy,
TradingTime,
User,
)
# Create patch mixin to mock out the Elastic client
@@ -31,6 +41,21 @@ class ElasticMock:
cls.patcher.stop()
class SymbolPriceMock:
@classmethod
def setUpClass(cls):
super(SymbolPriceMock, cls).setUpClass()
cls.patcher = patch("core.exchanges.common.get_symbol_price")
patcher = cls.patcher.start()
patcher.return_value = 1
@classmethod
def tearDownClass(cls):
super(SymbolPriceMock, cls).tearDownClass()
cls.patcher.stop()
class LiveBase:
@classmethod
def tearDownClass(cls):
@@ -92,3 +117,40 @@ If you have done this, please see the following line for more information:
def setUp(self):
if self.fail:
self.skipTest("Live tests aborted")
class StrategyMixin:
def setUp(self):
super().setUp()
self.time_8 = time(8, 0, 0)
self.time_16 = time(16, 0, 0)
self.order_settings = OrderSettings.objects.create(
user=self.user, name="Default"
)
self.trading_time_now = TradingTime.objects.create(
user=self.user,
name="Test Trading Time",
start_day=1, # Monday
start_time=self.time_8,
end_day=1, # Monday
end_time=self.time_16,
)
self.risk_model = RiskModel.objects.create(
user=self.user,
name="Test Risk Model",
max_loss_percent=50,
max_risk_percent=10,
max_open_trades=10,
max_open_trades_per_symbol=5,
)
self.strategy = Strategy.objects.create(
user=self.user,
name="Test Strategy",
account=self.account,
order_settings=self.order_settings,
risk_model=self.risk_model,
active_management_enabled=True,
)
self.strategy.trading_times.set([self.trading_time_now])
self.strategy.save()