From 0808c50ee839b30aabeec7f097198a2fe51f2cb0 Mon Sep 17 00:00:00 2001 From: songkl Date: Tue, 12 May 2026 00:02:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=B9=E5=86=B2=E6=89=8B=E6=95=B0?= =?UTF-8?q?=E4=BD=8E=E4=BA=8E=E6=9C=80=E5=B0=8F=E6=89=8B=E6=95=B0=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=B8=8B=E5=8D=95=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 0.01手 × 0.5(半仓对冲比例) = 0.005手 < 最小手数0.01 API拒绝下单, order_id=0 修复: execute_hedge 增加手数校验, 强制不低于volume_min --- core/risk/hedge.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/risk/hedge.py b/core/risk/hedge.py index 91c537e..3ba4528 100644 --- a/core/risk/hedge.py +++ b/core/risk/hedge.py @@ -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