Implement check risk function

master
Mark Veidemanis 1 year ago
parent 46aaff43c0
commit e0ea4c86fa
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -44,3 +44,35 @@ def check_max_open_trades_per_symbol(risk_model, account_trades):
if count >= risk_model.max_open_trades_per_symbol:
return False
return True
def check_risk(risk_model, account, proposed_trade):
"""
Run the risk checks on the account and the proposed trade.
"""
# Check that the max loss is not exceeded
max_loss_check = check_max_loss(
risk_model, account.initial_balance, account.client.get_balance()
)
if not max_loss_check:
return {"allowed": False, "reason": "Maximum loss exceeded."}
# Check that the account max trades is not exceeded
account_trades = account.client.get_all_open_trades() # TODO
account_trades.append(proposed_trade) # TODO
max_open_trades_check = check_max_open_trades(risk_model, account_trades)
if not max_open_trades_check:
return {"allowed": False, "reason": "Maximum open trades exceeded."}
# Check that the max trades per symbol is not exceeded
max_open_trades_per_symbol_check = check_max_open_trades_per_symbol(
risk_model, account_trades
)
if not max_open_trades_per_symbol_check:
return {"allowed": False, "reason": "Maximum open trades per symbol exceeded."}
# Check that the max risk is not exceeded
max_risk_check = check_max_risk(risk_model, account_trades)
if not max_risk_check:
return {"allowed": False, "reason": "Maximum risk exceeded."}

Loading…
Cancel
Save