From b4424a77828e7f43daae04e4bd2c7e00b5183a72 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Feb 2023 07:20:12 +0000 Subject: [PATCH] Begin work on increasing position size --- core/models.py | 8 ++++++++ core/tests/trading/test_active_management.py | 9 +++++++++ core/tests/trading/test_live.py | 9 +++++++++ core/trading/risk.py | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/core/models.py b/core/models.py index 4062495..c534bd3 100644 --- a/core/models.py +++ b/core/models.py @@ -80,6 +80,14 @@ ADJUST_CLOSE_NOTIFY_CHOICES = ( ("adjust", "Adjust violating trades"), ) +ADJUST_WITH_DIRECTION_CHOICES = ( + ("none", "None"), + ("close", "Close violating trades"), + ("notify", "Notify only"), + ("adjust", "Increase and reduce"), + ("adjust_up", "Increase only"), + ("adjust_down", "Reduce only"), +) # class Plan(models.Model): # name = models.CharField(max_length=255, unique=True) diff --git a/core/tests/trading/test_active_management.py b/core/tests/trading/test_active_management.py index fa9b983..5a3fcd0 100644 --- a/core/tests/trading/test_active_management.py +++ b/core/tests/trading/test_active_management.py @@ -283,6 +283,15 @@ class ActiveManagementTestCase(StrategyMixin, SymbolPriceMock, TestCase): }, ) + def test_position_size_violated_increase_only(self): + pass + + def test_position_size_violated_decrease_only(self): + pass + + def test_position_size_violated_increase_decrease(self): + pass + def test_protection_violated(self): self.trades[0]["takeProfitOrder"] = {"price": "0.0001"} self.trades[0]["stopLossOrder"] = {"price": "0.0001"} diff --git a/core/tests/trading/test_live.py b/core/tests/trading/test_live.py index ff95047..5eb066e 100644 --- a/core/tests/trading/test_live.py +++ b/core/tests/trading/test_live.py @@ -203,6 +203,15 @@ class ActiveManagementLiveTestCase(ElasticMock, StrategyMixin, LiveBase, TestCas trades = self.account.client.get_all_open_trades() self.assertEqual(len(trades), 0) + def test_ams_position_size_violated_increase(self): + pass + + def test_ams_position_size_violated_decrease(self): + pass + + def test_ams_position_size_violated_increase_decrease(self): + pass + def test_ams_protection_violated(self): self.active_management_policy.when_protection_violated = "close" self.active_management_policy.save() diff --git a/core/trading/risk.py b/core/trading/risk.py index 3774fa4..61d50bc 100644 --- a/core/trading/risk.py +++ b/core/trading/risk.py @@ -44,6 +44,13 @@ def check_max_risk(risk_model, account_balance_usd, account_trades): return allowed +def check_max_trade_risk(risk_model, account_balance_usd, trade): + """ + Check that the trade is within the max trade risk percentage of the account size. + """ + pass + + def check_max_open_trades(risk_model, account_trades): """ Check that the number of trades in the account is within the max open trades limit.