Finish implementing active management hooks

This commit is contained in:
2023-02-18 11:54:30 +00:00
parent 3e35214e82
commit 466b17400f
9 changed files with 271 additions and 123 deletions

View File

@@ -26,6 +26,7 @@ def check_max_risk(risk_model, account_balance_usd, account_trades):
# Calculate the max risk of the account in USD
max_risk_usd = account_balance_usd * (max_risk_percent / D(100))
total_risk = 0
for trade in account_trades:
max_tmp = []
# Need to calculate the max risk in base account currency
@@ -36,7 +37,8 @@ def check_max_risk(risk_model, account_balance_usd, account_trades):
if "trailing_stop_loss_usd" in trade:
max_tmp.append(trade["trailing_stop_loss_usd"])
if max_tmp:
total_risk += max(max_tmp)
max_risk = max(max_tmp)
total_risk += max_risk
allowed = total_risk < max_risk_usd
return allowed
@@ -59,7 +61,6 @@ def check_max_open_trades_per_symbol(risk_model, account_trades, return_symbols=
if symbol not in symbol_map:
symbol_map[symbol] = 0
symbol_map[symbol] += 1
print("Symbol map: ", symbol_map)
violating_symbols = []
for symbol, count in symbol_map.items():
if count >= risk_model.max_open_trades_per_symbol: