Begin protection checks
This commit is contained in:
parent
314d4022ea
commit
ba8eb69309
|
@ -175,7 +175,59 @@ class ActiveManagementMixinTestCase(StrategyMixin):
|
||||||
self.close_trade(complex_trade)
|
self.close_trade(complex_trade)
|
||||||
|
|
||||||
def test_ams_protection_violated(self):
|
def test_ams_protection_violated(self):
|
||||||
pass
|
self.active_management_policy.when_protection_violated = "close"
|
||||||
|
self.active_management_policy.save()
|
||||||
|
# Don't violate position size check
|
||||||
|
trade_size = market.get_trade_size_in_base(
|
||||||
|
"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()
|
||||||
|
self.assertEqual(len(self.ams.actions["close"]), 1)
|
||||||
|
expected = {
|
||||||
|
"close": [
|
||||||
|
{
|
||||||
|
"id": complex_trade.id,
|
||||||
|
"check": "protection",
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
del self.ams.checks["close"][0]["extra"]
|
||||||
|
|
||||||
|
self.assertEqual(self.ams.checks, expected)
|
||||||
|
|
||||||
|
def test_ams_protection_violated_adjust(self):
|
||||||
|
# Don't violate position size check
|
||||||
|
trade_size = market.get_trade_size_in_base(
|
||||||
|
"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)
|
||||||
|
|
||||||
def test_ams_asset_groups_violated(self):
|
def test_ams_asset_groups_violated(self):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue