mirror of
https://github.com/silencesdg/mt5_python_ea_suite.git
synced 2026-07-29 03:37:43 +00:00
fix: 对冲手数低于最小手数导致下单失败
问题: 0.01手 × 0.5(半仓对冲比例) = 0.005手 < 最小手数0.01
API拒绝下单, order_id=0
修复: execute_hedge 增加手数校验, 强制不低于volume_min
This commit is contained in:
@@ -107,6 +107,17 @@ class HedgeManager:
|
||||
ratio = self.signal_hedge_ratio if hedge_type == "signal" else self.drawdown_hedge_ratio
|
||||
hedge_volume = position["quantity"] * ratio
|
||||
|
||||
# ★ 手数校验:不能低于最小手数
|
||||
symbol_info = self._pm.data_provider.get_symbol_info(self._pm.symbol)
|
||||
if symbol_info:
|
||||
vol_min = symbol_info.get("volume_min", 0.01) if isinstance(symbol_info, dict) else getattr(symbol_info, "volume_min", 0.01)
|
||||
vol_step = symbol_info.get("volume_step", 0.01) if isinstance(symbol_info, dict) else getattr(symbol_info, "volume_step", 0.01)
|
||||
hedge_volume = max(vol_min, round(hedge_volume / vol_step) * vol_step)
|
||||
else:
|
||||
hedge_volume = max(0.01, hedge_volume)
|
||||
|
||||
logger.info(f"🔒 准备对冲: {opposite} {hedge_volume:.2f}手 | 原因: {reason}")
|
||||
|
||||
# 调取开仓
|
||||
result = self._pm.data_provider.send_order(
|
||||
self._pm.symbol, opposite, hedge_volume
|
||||
|
||||
Reference in New Issue
Block a user