This commit is contained in:
薇薇安 2026-02-03 16:21:07 +08:00
parent 78c2d7f1ae
commit 833f8096d7

View File

@ -841,8 +841,13 @@ class RiskManager:
final_stop_loss_amount = (final_stop_loss - entry_price) * quantity
final_stop_loss_pct_margin = (final_stop_loss_amount / margin * 100) if margin > 0 else 0
# 如果最终止损价对应的保证金百分比超过配置值,强制使用保证金止损
if final_stop_loss_pct_margin > (stop_loss_percent * 100):
# ⚠️ 优化如果使用的是ATR止损或技术止损允许突破配置的保证金百分比限制
# 因为仓位大小已经根据风险进行了调整所以即使单笔亏损比例大如80%保证金),总亏损金额仍受控
# 只有在使用默认保证金止损策略时,才强制执行限制
is_atr_or_tech = selected_method in ['ATR', '技术分析']
# 如果最终止损价对应的保证金百分比超过配置值且不是ATR/技术止损,则强制使用保证金止损
if final_stop_loss_pct_margin > (stop_loss_percent * 100) and not is_atr_or_tech:
logger.warning(
f"⚠️ 最终止损价({final_stop_loss:.4f}, 使用{selected_method})对应的保证金百分比({final_stop_loss_pct_margin:.2f}%) "
f"超过配置值({stop_loss_percent*100:.1f}%),强制使用保证金止损({stop_loss_price_margin:.4f})"
@ -850,6 +855,12 @@ class RiskManager:
final_stop_loss = stop_loss_price_margin
selected_method = '保证金(强制)'
final_stop_loss_pct_margin = stop_loss_percent * 100
elif final_stop_loss_pct_margin > (stop_loss_percent * 100) and is_atr_or_tech:
logger.info(
f" {selected_method}止损 ({final_stop_loss:.4f}) 超过保证金配置值 "
f"({final_stop_loss_pct_margin:.2f}% > {stop_loss_percent*100:.1f}%)"
f"但予以保留(风险已通过仓位控制)"
)
logger.info(
f"最终止损 ({side}): {final_stop_loss:.4f} (使用{selected_method}), "