|
|
|
@ -182,8 +182,6 @@ class ActiveManagementMixinTestCase(StrategyMixin):
|
|
|
|
|
"buy", self.account, self.strategy, self.account.client.get_balance(), "EUR"
|
|
|
|
|
)
|
|
|
|
|
trade_size = round(trade_size, 0)
|
|
|
|
|
print("TRADE SIZE", trade_size)
|
|
|
|
|
print("TYPE", type(trade_size))
|
|
|
|
|
complex_trade = self.create_complex_trade("buy", trade_size, "EUR_USD", 5, 5)
|
|
|
|
|
self.open_trade(complex_trade)
|
|
|
|
|
|
|
|
|
@ -192,16 +190,20 @@ class ActiveManagementMixinTestCase(StrategyMixin):
|
|
|
|
|
expected = {
|
|
|
|
|
"close": [
|
|
|
|
|
{
|
|
|
|
|
"id": complex_trade.id,
|
|
|
|
|
"id": complex_trade.order_id,
|
|
|
|
|
"check": "protection",
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
del self.ams.checks["close"][0]["extra"]
|
|
|
|
|
del self.ams.actions["close"][0]["extra"]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.ams.actions, expected)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.ams.checks, expected)
|
|
|
|
|
self.ams.execute_actions()
|
|
|
|
|
|
|
|
|
|
trades = self.account.client.get_all_open_trades()
|
|
|
|
|
self.assertEqual(len(trades), 0)
|
|
|
|
|
|
|
|
|
|
def test_ams_protection_violated_adjust(self):
|
|
|
|
|
# Don't violate position size check
|
|
|
|
@ -209,25 +211,24 @@ class ActiveManagementMixinTestCase(StrategyMixin):
|
|
|
|
|
"buy", self.account, self.strategy, self.account.client.get_balance(), "EUR"
|
|
|
|
|
)
|
|
|
|
|
trade_size = round(trade_size, 0)
|
|
|
|
|
print("TRADE SIZE", trade_size)
|
|
|
|
|
print("TYPE", type(trade_size))
|
|
|
|
|
complex_trade = self.create_complex_trade("buy", trade_size, "EUR_USD", 5, 5)
|
|
|
|
|
self.open_trade(complex_trade)
|
|
|
|
|
|
|
|
|
|
self.ams.run_checks()
|
|
|
|
|
expected = {
|
|
|
|
|
"adjust": [
|
|
|
|
|
{
|
|
|
|
|
"id": "21381",
|
|
|
|
|
"check": "protection",
|
|
|
|
|
"extra": {
|
|
|
|
|
"stop_loss_price": D("1.05812"),
|
|
|
|
|
"take_profit_price": D("1.08484"),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
print("CHECKS", self.ams.actions)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(len(self.ams.actions["adjust"]), 1)
|
|
|
|
|
expected_tp = self.ams.actions["adjust"][0]["extra"]["take_profit_price"]
|
|
|
|
|
expected_sl = self.ams.actions["adjust"][0]["extra"]["stop_loss_price"]
|
|
|
|
|
self.assertEqual(len(self.ams.actions["adjust"]), 1)
|
|
|
|
|
|
|
|
|
|
self.ams.execute_actions()
|
|
|
|
|
|
|
|
|
|
trades = self.account.client.get_all_open_trades()
|
|
|
|
|
self.assertEqual(len(trades), 1)
|
|
|
|
|
self.assertEqual(D(trades[0]["takeProfitOrder"]["price"]), expected_tp)
|
|
|
|
|
self.assertEqual(D(trades[0]["stopLossOrder"]["price"]), expected_sl)
|
|
|
|
|
|
|
|
|
|
self.close_trade(complex_trade)
|
|
|
|
|
|
|
|
|
|
def test_ams_asset_groups_violated(self):
|
|
|
|
|
pass
|
|
|
|
|