Adjust initial balance in live tests

This commit is contained in:
Mark Veidemanis 2023-02-20 07:20:37 +00:00
parent 8bb5c2c91b
commit a840be3834
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 10 additions and 10 deletions

View File

@ -103,7 +103,7 @@ If you have done this, please see the following line for more information:
exchange=exchange, exchange=exchange,
api_key=api_key, api_key=api_key,
api_secret=api_secret, api_secret=api_secret,
initial_balance=100, initial_balance=100000,
) )
def setUp(self): def setUp(self):

View File

@ -135,24 +135,24 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
) )
return complex_trade return complex_trade
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100) @patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100000)
def test_check_risk_max_risk_pass(self, mock_balance): def test_check_risk_max_risk_pass(self, mock_balance):
# SL of 19% on a 10 trade on a 100 account is 1.8 loss # SL of 19% on a 10000 trade on a 100000 account is 1.8 loss
# Should be comfortably under 2% risk # Should be comfortably under 2% risk
trade = self.create_complex_trade("buy", 10, "EUR_USD", 1, 18) trade = self.create_complex_trade("buy", 10000, "EUR_USD", 1, 18)
allowed = risk.check_risk(self.risk_model, self.account, trade) allowed = risk.check_risk(self.risk_model, self.account, trade)
self.assertTrue(allowed["allowed"]) self.assertTrue(allowed["allowed"])
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100) @patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100000)
def test_check_risk_max_risk_fail(self, mock_balance): def test_check_risk_max_risk_fail(self, mock_balance):
# SL of 21% on a 10 trade on a 100 account is 2.2 loss # SL of 21% on a 10000 trade on a 100000 account is 2.2 loss
# Should be over 2% risk # Should be over 2% risk
trade = self.create_complex_trade("buy", 10, "EUR_USD", 1, 22) trade = self.create_complex_trade("buy", 10000, "EUR_USD", 1, 22)
allowed = risk.check_risk(self.risk_model, self.account, trade) allowed = risk.check_risk(self.risk_model, self.account, trade)
self.assertFalse(allowed["allowed"]) self.assertFalse(allowed["allowed"])
self.assertEqual(allowed["reason"], "Maximum risk exceeded.") self.assertEqual(allowed["reason"], "Maximum risk exceeded.")
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=94) @patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=94000)
# We have lost 6% of our account # We have lost 6% of our account
def test_check_risk_max_loss_fail(self, mock_balance): def test_check_risk_max_loss_fail(self, mock_balance):
# Doesn't matter, shouldn't get as far as the trade # Doesn't matter, shouldn't get as far as the trade
@ -161,7 +161,7 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
self.assertFalse(allowed["allowed"]) self.assertFalse(allowed["allowed"])
self.assertEqual(allowed["reason"], "Maximum loss exceeded.") self.assertEqual(allowed["reason"], "Maximum loss exceeded.")
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100) @patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100000)
def test_check_risk_max_open_trades_fail(self, mock_balance): def test_check_risk_max_open_trades_fail(self, mock_balance):
# The maximum open trades is 3. Let's open 2 trades # The maximum open trades is 3. Let's open 2 trades
# This would not be allowed by the risk model but we're doing it # This would not be allowed by the risk model but we're doing it
@ -184,7 +184,7 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
self.close_trade(trade1) self.close_trade(trade1)
self.close_trade(trade2) self.close_trade(trade2)
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100) @patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100000)
def test_check_risk_max_open_trades_per_symbol_fail(self, mock_balance): def test_check_risk_max_open_trades_per_symbol_fail(self, mock_balance):
trade1 = self.create_complex_trade("buy", 1, "EUR_USD", 1, 1) trade1 = self.create_complex_trade("buy", 1, "EUR_USD", 1, 1)
self.open_trade(trade1) self.open_trade(trade1)