Add more tests for risk checking

master
Mark Veidemanis 1 year ago
parent 483333bf28
commit 2dfaef324c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -274,3 +274,52 @@ class RiskModelTestCase(TestCase):
converted = convert_open_trades([trade, trade])
max_risk_check = risk.check_max_risk(self.risk_model, converted)
self.assertFalse(max_risk_check) # 10% risk is too much
def check_max_risk_market_data_fail_multiple_mixed(self):
"""
Check that we can not open a trade outside the max risk limit with market data
and multiple trades, mixing SL and TSL.
"""
trade = {
"id": "abd123",
"symbol": "EUR_USD",
"currentUnits": 100,
"side": "long",
"state": "open",
"price": 1.0, # initial
"unrealizedPL": 0, # price == initial
"stopLossOrder": {
"price": 0.95, # down by 5%, 5% risk
},
}
trade2 = trade.copy()
trade2["trailingStopLossOrder"] = {"price": 0.95}
del trade2["stopLossOrder"]
converted = convert_open_trades([trade, trade2])
max_risk_check = risk.check_max_risk(self.risk_model, converted)
self.assertFalse(max_risk_check) # 10% risk is too much
def check_max_risk_market_data_fail_multiple_mixed_both(self):
"""
Check that we can not open a trade outside the max risk limit with market data
and multiple trades, mixing SL and TSL, where both are set.
"""
trade = {
"id": "abd123",
"symbol": "EUR_USD",
"currentUnits": 100,
"side": "long",
"state": "open",
"price": 1.0, # initial
"unrealizedPL": 0, # price == initial
"stopLossOrder": {
"price": 0.95, # down by 5%, 5% risk
},
}
trade2 = trade.copy()
trade2["trailingStopLossOrder"] = {"price": 0.951}
converted = convert_open_trades([trade, trade2])
max_risk_check = risk.check_max_risk(self.risk_model, converted)
self.assertFalse(max_risk_check) # 10% risk is too much

Loading…
Cancel
Save