|
|
|
@ -64,8 +64,6 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
|
|
|
|
|
closed = self.account.client.close_trade(self.trade.order_id)
|
|
|
|
|
|
|
|
|
|
# Check the feedback from closing the trade
|
|
|
|
|
print("CLOSED", closed)
|
|
|
|
|
print("TRADE AMOUNT", trade.amount)
|
|
|
|
|
self.assertEqual(closed["type"], "MARKET_ORDER")
|
|
|
|
|
self.assertEqual(closed["symbol"], trade.symbol)
|
|
|
|
|
self.assertEqual(closed["units"], str(0 - int(trade.amount)))
|
|
|
|
@ -151,7 +149,6 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
|
|
|
|
|
# Should be over 2% risk
|
|
|
|
|
trade = self.create_complex_trade("buy", 10, "EUR_USD", 1, 22)
|
|
|
|
|
allowed = risk.check_risk(self.risk_model, self.account, trade)
|
|
|
|
|
print("ALLOWED", allowed)
|
|
|
|
|
self.assertFalse(allowed["allowed"])
|
|
|
|
|
self.assertEqual(allowed["reason"], "Maximum risk exceeded.")
|
|
|
|
|
|
|
|
|
@ -167,6 +164,11 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
|
|
|
|
|
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100)
|
|
|
|
|
def test_check_risk_max_open_trades_fail(self, mock_balance):
|
|
|
|
|
# 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
|
|
|
|
|
# manually
|
|
|
|
|
# Don't be confused by the next test. The max open trades check
|
|
|
|
|
# fails before the symbol one is run, but yes, they would both
|
|
|
|
|
# fail.
|
|
|
|
|
trade1 = self.create_complex_trade("buy", 1, "EUR_USD", 1, 1)
|
|
|
|
|
self.open_trade(trade1)
|
|
|
|
|
|
|
|
|
@ -184,7 +186,16 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
|
|
|
|
|
|
|
|
|
|
@patch("core.exchanges.oanda.OANDAExchange.get_balance", return_value=100)
|
|
|
|
|
def test_check_risk_max_open_trades_per_symbol_fail(self, mock_balance):
|
|
|
|
|
pass
|
|
|
|
|
trade1 = self.create_complex_trade("buy", 1, "EUR_USD", 1, 1)
|
|
|
|
|
self.open_trade(trade1)
|
|
|
|
|
|
|
|
|
|
trade2 = self.create_complex_trade("buy", 1, "EUR_USD", 1, 1)
|
|
|
|
|
|
|
|
|
|
allowed = risk.check_risk(self.risk_model, self.account, trade2)
|
|
|
|
|
self.assertFalse(allowed["allowed"])
|
|
|
|
|
self.assertEqual(allowed["reason"], "Maximum open trades per symbol exceeded.")
|
|
|
|
|
|
|
|
|
|
self.close_trade(trade1)
|
|
|
|
|
|
|
|
|
|
def test_convert_trades(self):
|
|
|
|
|
"""
|
|
|
|
|