From 7d27bfa2fad7dce65bd82503d5a95f3a41d174f6 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 23 Nov 2026 10:24:59 +0800
Subject: [PATCH] fix(gateApi): 忽略Gate配置反序列化未知属性

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |  591 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 530 insertions(+), 61 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
index b28f8f0..6d8228f 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -166,6 +166,10 @@
     private volatile int lastLongStopLossGridId = Integer.MAX_VALUE;
     /** 最近触发止损的空头网格ID */
     private volatile int lastShortStopLossGridId = Integer.MAX_VALUE;
+    /** 止损追单所在网格(多仓):价格驱动接管仲裁用,无追单 = Integer.MIN_VALUE */
+    private volatile int longSlReentryGridId = Integer.MIN_VALUE;
+    /** 止损追单所在网格(空仓):价格驱动接管仲裁用,无追单 = Integer.MIN_VALUE */
+    private volatile int shortSlReentryGridId = Integer.MIN_VALUE;
     /** 自定义止损模式激活标记:true=尚未发生第一次止损触发,第一次触发后置 false(触发未触发侧重挂默认) */
     private final AtomicBoolean dualStopLossModeActive = new AtomicBoolean(false);
 
@@ -177,6 +181,22 @@
     private final Map<String, Integer> tpReplenishLongOrderMap = new ConcurrentHashMap<>();
     /** 仓位止盈补仓:空仓止盈→空仓开仓单ID → 张数(成交后按原空仓止损位重挂全持仓止损) */
     private final Map<String, Integer> tpReplenishShortOrderMap = new ConcurrentHashMap<>();
+    /** 原始仓位减仓:当前多头递减追单数量(价格驱动移动时保持) */
+    private volatile int currentLongChaseQty = 0;
+    /** 原始仓位减仓:当前空头递减追单数量(价格驱动移动时保持) */
+    private volatile int currentShortChaseQty = 0;
+    /** 原始仓位减仓:多头补仓单 orderId → 张数(补仓单挂在空头第一止损位) */
+    private final Map<String, Integer> reduceReplenishLongOrderMap = new ConcurrentHashMap<>();
+    /** 原始仓位减仓:空头补仓单 orderId → 张数(补仓单挂在多头第一止损位) */
+    private final Map<String, Integer> reduceReplenishShortOrderMap = new ConcurrentHashMap<>();
+    /** 多头止损事件待处理标记:仓位已归零、autoorders finished 尚未到达时置位,阻止价格驱动抢先挂单 */
+    private volatile boolean longStopLossPending = false;
+    /** 空头止损事件待处理标记:同上 */
+    private volatile boolean shortStopLossPending = false;
+    /** 多头止损待处理置位时间戳(0=未置位),用于兜底超时复位 */
+    private volatile long longStopLossPendingSince = 0L;
+    /** 空头止损待处理置位时间戳(0=未置位),用于兜底超时复位 */
+    private volatile long shortStopLossPendingSince = 0L;
 
     private volatile BigDecimal lastKlinePrice;
     private volatile BigDecimal markPrice = BigDecimal.ZERO;
@@ -445,6 +465,14 @@
         dualStopLossModeActive.set(false);
         tpReplenishLongOrderMap.clear();
         tpReplenishShortOrderMap.clear();
+        currentLongChaseQty = 0;
+        currentShortChaseQty = 0;
+        longStopLossPending = false;
+        shortStopLossPending = false;
+        longStopLossPendingSince = 0L;
+        shortStopLossPendingSince = 0L;
+        reduceReplenishLongOrderMap.clear();
+        reduceReplenishShortOrderMap.clear();
         shortPriceQueue.clear();
         longPriceQueue.clear();
         totalShortPriceQueue.clear();
@@ -551,7 +579,7 @@
         }
 
         // 异步检查盈亏,避免 REST 调用阻塞 WS 心跳导致 Socket closed
-        executor.submitTask(this::checkProfitAndReset);
+        executor.submitMaintenanceTask(this::checkProfitAndReset);
 
         // 持仓主动对账(节流):WS 持仓推送可能因断线盲区/推送延迟而失真,
         // 导致本地持仓状态与交易所不一致、价格驱动重入迟迟不触发。
@@ -559,13 +587,17 @@
         if ((state == StrategyState.ACTIVE || state == StrategyState.OPENING)
                 && System.currentTimeMillis() - lastPositionSyncTime >= POSITION_SYNC_INTERVAL_MS) {
             lastPositionSyncTime = System.currentTimeMillis();
-            executor.submitTask(this::syncPositionsFromExchange);
+            executor.submitMaintenanceTask(this::syncPositionsFromExchange);
         }
+
+        // 止损事件兜底:置位超时仍未收到 finished(事件丢失且对账补触发未生效),解除拦截让价格驱动接管
+        releaseExpiredStopLossPending();
 
         if (state == StrategyState.ACTIVE &&
                 config.isPriceDriveEnabled() &&
                 longActive == false &&
-                    longPositionSize.compareTo(BigDecimal.ZERO) == 0){
+                    longPositionSize.compareTo(BigDecimal.ZERO) == 0 &&
+                    !longStopLossPending){
             processLongGrid(closePrice);
         }
 
@@ -573,8 +605,31 @@
         if (state == StrategyState.ACTIVE &&
                 config.isPriceDriveEnabled() &&
                 shortActive == false &&
-                        shortPositionSize.compareTo(BigDecimal.ZERO) == 0){
+                        shortPositionSize.compareTo(BigDecimal.ZERO) == 0 &&
+                        !shortStopLossPending){
             processShortGrid(closePrice);
+        }
+    }
+
+    /** 止损事件兜底超时:置位超过该时长仍未收到 autoorders finished,自动解除价格驱动拦截 */
+    private static final long STOP_LOSS_PENDING_TIMEOUT_MS = 30_000L;
+
+    /**
+     * 止损事件兜底:pending 置位超过 {@link #STOP_LOSS_PENDING_TIMEOUT_MS} 仍无 autoorders finished,
+     * 说明止损事件已丢失且对账补触发未生效(如无 trade_id 的幽灵单),主动解除拦截,
+     * 让价格驱动接管重挂,避免永久停摆。每次 onKline 进入价格驱动判定前调用。
+     */
+    private void releaseExpiredStopLossPending() {
+        long now = System.currentTimeMillis();
+        if (longStopLossPending && now - longStopLossPendingSince >= STOP_LOSS_PENDING_TIMEOUT_MS) {
+            longStopLossPending = false;
+            longStopLossPendingSince = 0L;
+            log.warn("[Gate] 多头止损事件{}秒未达, 兜底解除价格驱动拦截", STOP_LOSS_PENDING_TIMEOUT_MS / 1000);
+        }
+        if (shortStopLossPending && now - shortStopLossPendingSince >= STOP_LOSS_PENDING_TIMEOUT_MS) {
+            shortStopLossPending = false;
+            shortStopLossPendingSince = 0L;
+            log.warn("[Gate] 空头止损事件{}秒未达, 兜底解除价格驱动拦截", STOP_LOSS_PENDING_TIMEOUT_MS / 1000);
         }
     }
 
@@ -721,24 +776,32 @@
                     longActive = true;
                     longPositionSize = size;
                     longEntryPrice = entryPrice;
+                    longStopLossPending = false;
+                    longStopLossPendingSince = 0L;
                 } else {
 
                     log.info("[Gate-0]多仓: {}", longBaseEntryPrice);
                     longActive = false;
                     longPositionSize = BigDecimal.ZERO;
                     longEntryPrice = BigDecimal.ZERO;
+                    longStopLossPendingSince = System.currentTimeMillis();
+                    longStopLossPending = true;
                 }
             } else if (Position.ModeEnum.DUAL_SHORT == mode) {
                 if (hasPosition) {
                     shortActive = true;
                     shortPositionSize = size.abs();
                     shortEntryPrice = entryPrice;
+                    shortStopLossPending = false;
+                    shortStopLossPendingSince = 0L;
                 } else {
 
                     log.info("[Gate-0]空仓: {}", shortBaseEntryPrice);
                     shortActive = false;
                     shortPositionSize = BigDecimal.ZERO;
                     shortEntryPrice = BigDecimal.ZERO;
+                    shortStopLossPendingSince = System.currentTimeMillis();
+                    shortStopLossPending = true;
                 }
             }
         }
@@ -860,12 +923,19 @@
                     handleReplenishShortAddFilled(shortGridElement, orderId, replenishQty);
                     return;
                 }
+                // 原始仓位减仓:空头补仓单成交 → 在空头现有止损位追加该数量止损
+                Integer reduceReplenishQty = reduceReplenishShortOrderMap.remove(orderId);
+                if (reduceReplenishQty != null) {
+                    handleReduceReplenishShortFilled(shortGridElement, orderId, reduceReplenishQty);
+                    return;
+                }
                 // 加仓执行计数:含加仓量的开仓单真正成交时才 +1(挂单后被取消的不计入)
                 if (pendingAddEntryOrderIds.remove(orderId)) {
                     accumulatedShortAddCount++;
                 }
                 int filledQty = Integer.parseInt(shortGridElement.getShortTraderParam().getQuantity());
                 shortEntryTraderIdParam(shortGridElement, orderId, false);
+                shortSlReentryGridId = Integer.MIN_VALUE;   // 追单已成交,仲裁登记失效
 
                 // 埋点: ENTRY_FILLED — 空仓加仓成交
                 emitStats("ENTRY_FILLED", mapOf(
@@ -899,6 +969,10 @@
                 }
                 // [Gate] 基础仓位止盈挂单:与超额止盈并行,独立于止盈模式
                 placeBaseTakeProfit(posSize, false, shortGridElement.getId());
+                // 原始仓位减仓:追单成交后,在多头第一止损位挂空头补仓单(数量 = 原始仓位 - 当前仓位)
+                if (config.getOriginalPositionReduce() > 0) {
+                    placeReduceReplenish(false, posSize);
+                }
                 log.info("[Gate] 空单成交 {}张, 当前持仓:{}张", filledQty, posSize);
 
 
@@ -921,12 +995,19 @@
                     handleReplenishLongAddFilled(longGridElement, orderId, replenishQty);
                     return;
                 }
+                // 原始仓位减仓:多头补仓单成交 → 在多头现有止损位追加该数量止损
+                Integer reduceReplenishQty = reduceReplenishLongOrderMap.remove(orderId);
+                if (reduceReplenishQty != null) {
+                    handleReduceReplenishLongFilled(longGridElement, orderId, reduceReplenishQty);
+                    return;
+                }
                 // 加仓执行计数:含加仓量的开仓单真正成交时才 +1(挂单后被取消的不计入)
                 if (pendingAddEntryOrderIds.remove(orderId)) {
                     accumulatedLongAddCount++;
                 }
                 int filledQty = Integer.parseInt(longGridElement.getLongTraderParam().getQuantity());
                 longEntryTraderIdParam(longGridElement, orderId, false);
+                longSlReentryGridId = Integer.MIN_VALUE;   // 追单已成交,仲裁登记失效
 
                 // 埋点: ENTRY_FILLED — 多仓加仓成交
                 emitStats("ENTRY_FILLED", mapOf(
@@ -960,6 +1041,10 @@
                 }
                 // [Gate] 基础仓位止盈挂单:与超额止盈并行,独立于止盈模式
                 placeBaseTakeProfit(posSize, true, longGridElement.getId());
+                // 原始仓位减仓:追单成交后,在空头第一止损位挂多头补仓单(数量 = 原始仓位 - 当前仓位)
+                if (config.getOriginalPositionReduce() > 0) {
+                    placeReduceReplenish(true, posSize);
+                }
                 log.info("[Gate] 多单成交 {}张, 当前持仓:{}张", filledQty, posSize);
 
             }
@@ -1573,12 +1658,28 @@
             return;
         }
         int removed = 0;
+        boolean longSlCompensated = false;   // 每个方向每轮对账最多补触发一次
+        boolean shortSlCompensated = false;
         for (GridElement e : config.getGridElements()) {
             for (String id : new ArrayList<>(e.getLongStopLossOrderIds())) {
-                if (!openIds.contains(id)) { e.removeLongStopLossOrderId(id); removed++; }
+                if (!openIds.contains(id)) {
+                    if (!longSlCompensated) {
+                        longSlCompensated = true;
+                        compensateMissedStopLoss(true, e, id);
+                    }
+                    e.removeLongStopLossOrderId(id);
+                    removed++;
+                }
             }
             for (String id : new ArrayList<>(e.getShortStopLossOrderIds())) {
-                if (!openIds.contains(id)) { e.removeShortStopLossOrderId(id); removed++; }
+                if (!openIds.contains(id)) {
+                    if (!shortSlCompensated) {
+                        shortSlCompensated = true;
+                        compensateMissedStopLoss(false, e, id);
+                    }
+                    e.removeShortStopLossOrderId(id);
+                    removed++;
+                }
             }
             for (String id : new ArrayList<>(e.getLongTakeProfitOrderIds())) {
                 if (!openIds.contains(id)) { e.removeLongTakeProfitOrderId(id); removed++; }
@@ -1607,6 +1708,39 @@
         if (removed > 0) {
             GridElement.refreshIndices();
             log.warn("[Gate] 条件单对账: 移除 {} 个本地失效订单(交易所已不存在)", removed);
+        }
+    }
+
+    /**
+     * 止损成交补触发:对账发现止损单在交易所已消失时,REST 查该单详情。
+     * 若确已成交(trade_id &gt; 0),说明止损触发的 finished 推送被 positions/对账竞态吞掉
+     * (finished 晚于对账到达,本地索引已被清空),补执行止损触发逻辑:
+     * 累加止损次数、取消该方向开仓单、按止损格∓1 追单、延展止损。
+     * <p>追单量由 calculateEntryQuantity 的双重硬上限兜底(≤ 止损张数、≤ maxPerSide − REST持仓),
+     * 补触发不会造成重复追单/超仓。无成交记录(REQUEST_TIMEOUT 等)时仅清理 + WARN。</p>
+     */
+    private void compensateMissedStopLoss(boolean isLong, GridElement gridElement, String orderId) {
+        if (state == StrategyState.STOPPED) {
+            return;
+        }
+        try {
+            FuturesPriceTriggeredOrder detail = futuresApi.getPriceTriggeredOrder(config.getContract(), Long.parseLong(orderId));
+            Long tradeId = detail != null ? detail.getTradeId() : null;
+            if (detail == null || tradeId == null || tradeId <= 0) {
+                log.warn("[Gate] 条件单对账: {}止损单{}已消失但无成交记录(tradeId:{}), 仅清理不补触发",
+                        isLong ? "多仓" : "空仓", orderId, tradeId);
+                return;
+            }
+            log.warn("[Gate] 条件单对账: 检测到{}止损成交事件丢失, 补触发, gridId:{}, orderId:{}, tradeId:{}",
+                    isLong ? "多仓" : "空仓", gridElement.getId(), orderId, tradeId);
+            if (isLong) {
+                handleLongStopLossTriggered(gridElement, orderId);
+            } else {
+                handleShortStopLossTriggered(gridElement, orderId);
+            }
+        } catch (Exception e) {
+            log.warn("[Gate] 条件单对账: {}止损单{}补触发查询失败: {}",
+                    isLong ? "多仓" : "空仓", orderId, e.getMessage());
         }
     }
 
@@ -2426,6 +2560,27 @@
                 newEntryGrid = GridElement.findById(upId);
 
                 if (newEntryGrid != null) {
+                    // 止损追单接管(先撤后挂):价格继续下跌,目标格已低于追单格
+                    // (如追单在 grid-1、价格到 grid-3 → 目标格 grid-2)→ 撤掉落后追单,
+                    // 撤单成功后再挂新单,杜绝撤挂并发导致双单并存
+                    if (longSlReentryGridId != Integer.MIN_VALUE
+                            && newEntryGrid.getId() < longSlReentryGridId) {
+                        GridElement reentryElem = GridElement.findById(longSlReentryGridId);
+                        if (reentryElem != null && reentryElem.isHasLongOrder()) {
+                            final GridElement takeoverTarget = newEntryGrid;
+                            for (String oid : new ArrayList<>(reentryElem.getLongOrderIds())) {
+                                executor.cancelConditionalOrder(oid, o -> {
+                                    longEntryTraderIdParam(reentryElem, oid, false);
+                                    // 全部撤完后再挂新单(先撤后挂)
+                                    if (!reentryElem.hasLongOrderIds()) {
+                                        hangLongEntryWithVerify(takeoverTarget);
+                                    }
+                                });
+                            }
+                            return;   // 接管流程已启动,本轮不走常规挂单
+                        }
+                        longSlReentryGridId = Integer.MIN_VALUE;
+                    }
                     // 向下检查是否已有多单挂在更低价格网格,有则跳过(防止价格回升后重复挂单)
                     GridElement checkDownCursor = GridElement.findById(newEntryGrid.getDownId());
                     while (checkDownCursor != null) {
@@ -2482,14 +2637,100 @@
 
         // 阶段3:挂单
         BigDecimal triggerPrice = newEntryGrid.getGridPrice();
-        String size = calculateEntryQuantity(true, false, 0);
+        String size;
+        boolean hasAdd;
+        if (config.getOriginalPositionReduce() > 0) {
+            size = String.valueOf(currentLongChaseQty > 0 ? currentLongChaseQty : Integer.parseInt(config.getBaseQuantity()));
+            hasAdd = false;
+        } else {
+            size = calculateEntryQuantity(true, false, 0);
+            hasAdd = computeAddQty(true) > 0;
+        }
         log.info("[Gate] 多仓仓位归零 gridId:{}, 挂{}张多单",
                 newEntryGrid.getId(), size);
         newEntryGrid.getLongTraderParam().setQuantity(size);
-        // 含加仓量的单打标记:真正成交后才计入加仓执行次数
-        boolean hasAdd = computeAddQty(true) > 0;
         placeEntryOrderWithPreFlag(newEntryGrid, true, triggerPrice,
                 FuturesPriceTrigger.RuleEnum.NUMBER_1, size,
+                hasAdd ? pendingAddEntryOrderIds::add : null);
+    }
+
+    /**
+     * 接管挂单(多仓):撤掉落后止损追单成功后,REST 核实持仓为 0 再占坑挂多开仓单。
+     * 核实失败(追单实际已成交)则跳过,避免重复建仓。
+     */
+    private void hangLongEntryWithVerify(GridElement entryGrid) {
+        Position longPos = queryPosition(Position.ModeEnum.DUAL_LONG);
+        int realPos = longPos != null ? Math.abs(new BigDecimal(longPos.getSize()).intValue()) : 0;
+        if (realPos > 0) {
+            longActive = true;
+            longPositionSize = BigDecimal.valueOf(realPos);
+            if (longPos.getEntryPrice() != null) {
+                try {
+                    longEntryPrice = new BigDecimal(longPos.getEntryPrice());
+                } catch (NumberFormatException ignored) {
+                }
+            }
+            log.warn("[Gate] 接管挂单核实: 多仓实际持仓{}张>0, 跳过挂单(追单已成交)", realPos);
+            return;
+        }
+        BigDecimal triggerPrice = entryGrid.getGridPrice();
+        String size;
+        boolean hasAdd;
+        if (config.getOriginalPositionReduce() > 0) {
+            size = String.valueOf(currentLongChaseQty > 0 ? currentLongChaseQty : Integer.parseInt(config.getBaseQuantity()));
+            hasAdd = false;
+        } else {
+            size = calculateEntryQuantity(true, false, 0);
+            hasAdd = computeAddQty(true) > 0;
+        }
+        if (Integer.parseInt(size) <= 0) {
+            log.warn("[Gate] 接管挂单: 已达单边上限({}), 跳过", config.getMaxPositionPerSide());
+            return;
+        }
+        entryGrid.getLongTraderParam().setQuantity(size);
+        log.info("[Gate] 价格驱动接管: 多仓挂单 gridId:{}, {}张", entryGrid.getId(), size);
+        placeEntryOrderWithPreFlag(entryGrid, true, triggerPrice,
+                FuturesPriceTrigger.RuleEnum.NUMBER_1, size,
+                hasAdd ? pendingAddEntryOrderIds::add : null);
+    }
+
+    /**
+     * 接管挂单(空仓):撤掉落后止损追单成功后,REST 核实持仓为 0 再占坑挂空开仓单。
+     * 核实失败(追单实际已成交)则跳过,避免重复建仓。
+     */
+    private void hangShortEntryWithVerify(GridElement entryGrid) {
+        Position shortPos = queryPosition(Position.ModeEnum.DUAL_SHORT);
+        int realPos = shortPos != null ? Math.abs(new BigDecimal(shortPos.getSize()).intValue()) : 0;
+        if (realPos > 0) {
+            shortActive = true;
+            shortPositionSize = BigDecimal.valueOf(realPos);
+            if (shortPos.getEntryPrice() != null) {
+                try {
+                    shortEntryPrice = new BigDecimal(shortPos.getEntryPrice());
+                } catch (NumberFormatException ignored) {
+                }
+            }
+            log.warn("[Gate] 接管挂单核实: 空仓实际持仓{}张>0, 跳过挂单(追单已成交)", realPos);
+            return;
+        }
+        BigDecimal triggerPrice = entryGrid.getGridPrice();
+        String size;
+        boolean hasAdd;
+        if (config.getOriginalPositionReduce() > 0) {
+            size = String.valueOf(currentShortChaseQty > 0 ? currentShortChaseQty : Integer.parseInt(config.getBaseQuantity()));
+            hasAdd = false;
+        } else {
+            size = calculateEntryQuantity(false, false, 0);
+            hasAdd = computeAddQty(false) > 0;
+        }
+        if (Integer.parseInt(size) <= 0) {
+            log.warn("[Gate] 接管挂单: 已达单边上限({}), 跳过", config.getMaxPositionPerSide());
+            return;
+        }
+        entryGrid.getShortTraderParam().setQuantity(size);
+        log.info("[Gate] 价格驱动接管: 空仓挂单 gridId:{}, {}张", entryGrid.getId(), size);
+        placeEntryOrderWithPreFlag(entryGrid, false, triggerPrice,
+                FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size),
                 hasAdd ? pendingAddEntryOrderIds::add : null);
     }
 
@@ -2516,6 +2757,27 @@
                 newEntryGrid = GridElement.findById(downId);
 
                 if (newEntryGrid != null) {
+                    // 止损追单接管(先撤后挂):价格继续上涨,目标格已高于追单格
+                    // (如追单在 grid1、价格到 grid3 → 目标格 grid2)→ 撤掉落后追单,
+                    // 撤单成功后再挂新单,杜绝撤挂并发导致双单并存
+                    if (shortSlReentryGridId != Integer.MIN_VALUE
+                            && newEntryGrid.getId() > shortSlReentryGridId) {
+                        GridElement reentryElem = GridElement.findById(shortSlReentryGridId);
+                        if (reentryElem != null && reentryElem.isHasShortOrder()) {
+                            final GridElement takeoverTarget = newEntryGrid;
+                            for (String oid : new ArrayList<>(reentryElem.getShortOrderIds())) {
+                                executor.cancelConditionalOrder(oid, o -> {
+                                    shortEntryTraderIdParam(reentryElem, oid, false);
+                                    // 全部撤完后再挂新单(先撤后挂)
+                                    if (!reentryElem.hasShortOrderIds()) {
+                                        hangShortEntryWithVerify(takeoverTarget);
+                                    }
+                                });
+                            }
+                            return;   // 接管流程已启动,本轮不走常规挂单
+                        }
+                        shortSlReentryGridId = Integer.MIN_VALUE;
+                    }
                     // 向上检查是否已有空单挂在更高价格网格,有则跳过(防止价格回落后重复挂单)
                     GridElement checkUpCursor = GridElement.findById(newEntryGrid.getUpId());
                     while (checkUpCursor != null) {
@@ -2572,12 +2834,18 @@
 
         // 阶段3:挂单
         BigDecimal triggerPrice = newEntryGrid.getGridPrice();
-        String size = calculateEntryQuantity(false, false, 0);
+        String size;
+        boolean hasAdd;
+        if (config.getOriginalPositionReduce() > 0) {
+            size = String.valueOf(currentShortChaseQty > 0 ? currentShortChaseQty : Integer.parseInt(config.getBaseQuantity()));
+            hasAdd = false;
+        } else {
+            size = calculateEntryQuantity(false, false, 0);
+            hasAdd = computeAddQty(false) > 0;
+        }
         log.info("[Gate] 空仓仓位归零 gridId:{}, 挂{}张空单",
                 newEntryGrid.getId(), size);
         newEntryGrid.getShortTraderParam().setQuantity(size);
-        // 含加仓量的单打标记:真正成交后才计入加仓执行次数
-        boolean hasAdd = computeAddQty(false) > 0;
         placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
                 FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size),
                 hasAdd ? pendingAddEntryOrderIds::add : null);
@@ -2713,6 +2981,125 @@
         return String.valueOf(totalQty);
     }
 
+    // ========== 原始仓位减仓:递减追单 + 对手盘补仓 ==========
+
+    /**
+     * 计算原始仓位减仓模式下的递减追单数量。
+     * 每次止损(含首次)→ 追单 = 本次被平数量 - 步长;
+     * 若结果 < 步长 → 重置为原始仓位(最大仓位),形成循环。
+     */
+    private int computeReducedChaseQty(int stoppedQty) {
+        int baseQty = Integer.parseInt(config.getBaseQuantity());
+        int reduceStep = config.getOriginalPositionReduce();
+        int chase = stoppedQty - reduceStep;
+        if (chase < reduceStep) {
+            chase = baseQty;
+        }
+        return chase;
+    }
+
+    /**
+     * 原始仓位减仓:追单成交后,在对手盘第一止损位挂同方向补仓单。
+     * 补仓数量 = 原始仓位 - 当前仓位;补仓为条件单,成交后才追加止损。
+     */
+    private void placeReduceReplenish(boolean isLong, int currentPos) {
+        int baseQty = Integer.parseInt(config.getBaseQuantity());
+        int replenishQty = baseQty - currentPos;
+        // 追单成交后重算:先撤销本方向旧补仓单,再按新数量重挂
+        cancelReduceReplenish(isLong);
+        if (replenishQty <= 0) {
+            return;
+        }
+        GridElement opponentSl = isLong ? findFirstShortStopLossGrid() : findFirstLongStopLossGrid();
+        if (opponentSl == null) {
+            log.warn("[Gate] 原始仓位减仓: 未找到{}第一止损位, 跳过补仓", isLong ? "空头" : "多头");
+            return;
+        }
+        BigDecimal triggerPrice = opponentSl.getGridPrice();
+        FuturesPriceTrigger.RuleEnum rule = isLong
+                ? FuturesPriceTrigger.RuleEnum.NUMBER_1
+                : FuturesPriceTrigger.RuleEnum.NUMBER_2;
+        String size = isLong ? String.valueOf(replenishQty) : negate(String.valueOf(replenishQty));
+        executor.placeConditionalEntryOrder(triggerPrice, rule, size,
+                orderId -> {
+                    if (isLong) {
+                        reduceReplenishLongOrderMap.put(orderId, replenishQty);
+                        longEntryTraderIdParam(opponentSl, orderId, true);
+                    } else {
+                        reduceReplenishShortOrderMap.put(orderId, replenishQty);
+                        shortEntryTraderIdParam(opponentSl, orderId, true);
+                    }
+                    log.info("[Gate] 原始仓位减仓: {}补仓{}张已挂, 对手盘止损位 gridId:{}, orderId:{}",
+                            isLong ? "多头" : "空头", replenishQty, opponentSl.getId(), orderId);
+                },
+                () -> {
+                    if (isLong) {
+                        if (!opponentSl.hasLongOrderIds()) {
+                            opponentSl.setHasLongOrder(false);
+                        }
+                    } else {
+                        if (!opponentSl.hasShortOrderIds()) {
+                            opponentSl.setHasShortOrder(false);
+                        }
+                    }
+                    GridElement.refreshIndices();
+                    log.warn("[Gate] 原始仓位减仓: {}补仓挂单失败, 对手盘止损位 gridId:{}",
+                            isLong ? "多头" : "空头", opponentSl.getId());
+                }
+        );
+    }
+
+    /** 撤销本方向已挂未成交的补仓单。 */
+    private void cancelReduceReplenish(boolean isLong) {
+        Map<String, Integer> map = isLong ? reduceReplenishLongOrderMap : reduceReplenishShortOrderMap;
+        if (map.isEmpty()) {
+            return;
+        }
+        List<String> orderIds = new ArrayList<>(map.keySet());
+        map.clear();
+        for (String oid : orderIds) {
+            GridElement elem = isLong ? GridElement.findByLongOrderId(oid) : GridElement.findByShortOrderId(oid);
+            if (elem != null) {
+                if (isLong) {
+                    elem.removeLongOrderId(oid);
+                    elem.setHasLongOrder(elem.hasLongOrderIds());
+                } else {
+                    elem.removeShortOrderId(oid);
+                    elem.setHasShortOrder(elem.hasShortOrderIds());
+                }
+            }
+            executor.cancelConditionalOrder(oid, o -> {});
+        }
+        GridElement.refreshIndices();
+        log.info("[Gate] 原始仓位减仓: 已撤销{}补仓单{}张", isLong ? "多头" : "空头", orderIds.size());
+    }
+
+    /** 原始仓位减仓:多头补仓单成交后,在多头现有止损位追加该数量止损(不撤旧止损)。 */
+    private void handleReduceReplenishLongFilled(GridElement slElem, String orderId, int replenishQty) {
+        longEntryTraderIdParam(slElem, orderId, false);
+        GridElement longSl = findFirstLongStopLossGrid();
+        if (longSl == null) {
+            log.warn("[Gate] 原始仓位减仓: 多头补仓成交但未找到多头止损位, 跳过追加止损");
+            return;
+        }
+        placeStopLossOrders(longSl.getId(), 1, String.valueOf(replenishQty),
+                FuturesPriceTrigger.RuleEnum.NUMBER_2, ORDER_TYPE_CLOSE_LONG, true, null, null);
+        log.info("[Gate] 原始仓位减仓: 多头补仓{}张成交, 已在多头止损位 gridId:{} 追加止损", replenishQty, longSl.getId());
+    }
+
+    /** 原始仓位减仓:空头补仓单成交后,在空头现有止损位追加该数量止损(不撤旧止损)。 */
+    private void handleReduceReplenishShortFilled(GridElement slElem, String orderId, int replenishQty) {
+        shortEntryTraderIdParam(slElem, orderId, false);
+        GridElement shortSl = findFirstShortStopLossGrid();
+        if (shortSl == null) {
+            log.warn("[Gate] 原始仓位减仓: 空头补仓成交但未找到空头止损位, 跳过追加止损");
+            return;
+        }
+        placeStopLossOrders(shortSl.getId(), 1, String.valueOf(replenishQty),
+                FuturesPriceTrigger.RuleEnum.NUMBER_1, ORDER_TYPE_CLOSE_SHORT, false, null, null);
+        log.info("[Gate] 原始仓位减仓: 空头补仓{}张成交, 已在空头止损位 gridId:{} 追加止损", replenishQty, shortSl.getId());
+    }
+
     private void handleLongStopLossTriggered(GridElement gridElement, String orderId) {
         // 本网格全部止损单覆盖张数(含刚触发的这一单),用于追单时修正 REST 持仓的时序竞态
         int gridStopLossSize = gridElement.getLongStopLossTotalSize();
@@ -2726,6 +3113,8 @@
         }
 
         lastLongStopLossGridId = gridId;
+        longStopLossPending = false;
+        longStopLossPendingSince = 0L;
 
         accumulatedLongLossCount++;
         log.info("[Gate] 多仓止损触发 gridId:{}, 止损次数:{}{}, 开始追单",
@@ -2750,18 +3139,41 @@
         // 避免旧单与新追单重复建仓(与价格驱动的扫荡口径一致)
         cancelAllLongEntryOrders();
 
+        // 登记止损追单网格:价格驱动以此仲裁优先级(追单优先,价格越过追单格后价格驱动接管)
+        longSlReentryGridId = newEntryGrid.getId();
+
+        // 占坑前移:撤单后立即在追单目标网格预留"有单"标记(同步、无I/O),再执行 REST 数量计算
+        // (耗时数百ms)。价格驱动的挂单判定(本格有单/游标检查)会看到该标记并跳过本轮,
+        // 消除"撤旧挂新"窗口期被价格驱动抢先挂单导致的双单竞态。
+        newEntryGrid.setHasLongOrder(true);
+
         // 止损追单:同一网格可有多笔挂单,不判断 isHasLongOrder,直接挂单
         BigDecimal triggerPrice = newEntryGrid.getGridPrice();
-        String size = calculateEntryQuantity(true, true, gridStopLossSize);
-        log.info("[Gate] 多仓止损追单 有效次数:{}, 加仓执行:{}, 停止阈值:{}, 基础:{}张 → 实际:{}张, 模式:{}",
-                getEffectiveStopLossCount(true), getEffectiveAddCount(true), config.getAddPositionStopThreshold(),
-                config.getBaseQuantity(), size, config.getStopLossCountMode());
+        String size;
+        boolean hasAdd;
+        if (config.getOriginalPositionReduce() > 0) {
+            // 原始仓位减仓:每次止损(含首次)按 本次被平数量-步长 递减,<步长时重置为原始仓位
+            int chaseQty = computeReducedChaseQty(gridStopLossSize);
+            currentLongChaseQty = chaseQty;
+            size = String.valueOf(chaseQty);
+            hasAdd = false;
+            log.info("[Gate] 多仓原始仓位减仓追单 被平:{}张, 步长:{}, 追单:{}张",
+                    gridStopLossSize, config.getOriginalPositionReduce(), size);
+        } else {
+            size = calculateEntryQuantity(true, true, gridStopLossSize);
+            hasAdd = computeAddQty(true) > 0;
+            log.info("[Gate] 多仓止损追单 有效次数:{}, 加仓执行:{}, 停止阈值:{}, 基础:{}张 → 实际:{}张, 模式:{}",
+                    getEffectiveStopLossCount(true), getEffectiveAddCount(true), config.getAddPositionStopThreshold(),
+                    config.getBaseQuantity(), size, config.getStopLossCountMode());
+        }
         if (Integer.parseInt(size) <= 0) {
             log.warn("[Gate] 多仓止损追单 当前持仓已达单边上限({}), 跳过挂单", config.getMaxPositionPerSide());
+            // 清理占坑标记与追单登记(未挂单)
+            newEntryGrid.setHasLongOrder(newEntryGrid.hasLongOrderIds());
+            longSlReentryGridId = Integer.MIN_VALUE;
+            GridElement.refreshIndices();
         } else {
             newEntryGrid.getLongTraderParam().setQuantity(size);
-            // 含加仓量的单打标记:真正成交后才计入加仓执行次数(挂单后被取消的不算)
-            boolean hasAdd = computeAddQty(true) > 0;
             placeEntryOrderWithPreFlag(newEntryGrid, true, triggerPrice,
                     FuturesPriceTrigger.RuleEnum.NUMBER_1, size,
                     hasAdd ? pendingAddEntryOrderIds::add : null);
@@ -2788,6 +3200,8 @@
             return;
         }
         lastShortStopLossGridId = gridId;
+        shortStopLossPending = false;
+        shortStopLossPendingSince = 0L;
         accumulatedShortLossCount++;
         log.info("[Gate] 空仓止损触发 gridId:{}, 止损次数:{}{}, 开始追单",
                 gridId, accumulatedShortLossCount, sameGrid ? "(同网格)" : "");
@@ -2811,18 +3225,40 @@
         // 避免旧单与新追单重复建仓(与价格驱动的扫荡口径一致)
         cancelAllShortEntryOrders();
 
+        // 登记止损追单网格:价格驱动以此仲裁优先级(追单优先,价格越过追单格后价格驱动接管)
+        shortSlReentryGridId = newEntryGrid.getId();
+
+        // 占坑前移:撤单后立即在追单目标网格预留"有单"标记(同步、无I/O),再执行 REST 数量计算
+        // (耗时数百ms)。价格驱动的挂单判定(本格有单/游标检查)会看到该标记并跳过本轮,
+        // 消除"撤旧挂新"窗口期被价格驱动抢先挂单导致的双单竞态。
+        newEntryGrid.setHasShortOrder(true);
+
         // 止损追单:同一网格可有多笔挂单,不判断 isHasShortOrder,直接挂单
         BigDecimal triggerPrice = newEntryGrid.getGridPrice();
-        String size = calculateEntryQuantity(false, true, gridStopLossSize);
-        log.info("[Gate] 空仓止损追单 有效次数:{}, 加仓执行:{}, 停止阈值:{}, 基础:{}张 → 实际:{}张, 模式:{}",
-                getEffectiveStopLossCount(false), getEffectiveAddCount(false), config.getAddPositionStopThreshold(),
-                config.getBaseQuantity(), size, config.getStopLossCountMode());
+        String size;
+        boolean hasAdd;
+        if (config.getOriginalPositionReduce() > 0) {
+            int chaseQty = computeReducedChaseQty(gridStopLossSize);
+            currentShortChaseQty = chaseQty;
+            size = String.valueOf(chaseQty);
+            hasAdd = false;
+            log.info("[Gate] 空仓原始仓位减仓追单 被平:{}张, 步长:{}, 追单:{}张",
+                    gridStopLossSize, config.getOriginalPositionReduce(), size);
+        } else {
+            size = calculateEntryQuantity(false, true, gridStopLossSize);
+            hasAdd = computeAddQty(false) > 0;
+            log.info("[Gate] 空仓止损追单 有效次数:{}, 加仓执行:{}, 停止阈值:{}, 基础:{}张 → 实际:{}张, 模式:{}",
+                    getEffectiveStopLossCount(false), getEffectiveAddCount(false), config.getAddPositionStopThreshold(),
+                    config.getBaseQuantity(), size, config.getStopLossCountMode());
+        }
         if (Integer.parseInt(size) <= 0) {
             log.warn("[Gate] 空仓止损追单 当前持仓已达单边上限({}), 跳过挂单", config.getMaxPositionPerSide());
+            // 清理占坑标记与追单登记(未挂单)
+            newEntryGrid.setHasShortOrder(newEntryGrid.hasShortOrderIds());
+            shortSlReentryGridId = Integer.MIN_VALUE;
+            GridElement.refreshIndices();
         } else {
             newEntryGrid.getShortTraderParam().setQuantity(size);
-            // 含加仓量的单打标记:真正成交后才计入加仓执行次数(挂单后被取消的不算)
-            boolean hasAdd = computeAddQty(false) > 0;
             placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
                     FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size),
                     hasAdd ? pendingAddEntryOrderIds::add : null);
@@ -3070,8 +3506,11 @@
         }
 
         // 单位置全量止损:当前方向全部持仓挂一张止损单(入场格下方第2格,价格≤触发价平多)。
-        // 取 max 是为了在 REST 时序竞态导致 filledQty 偏小时,至少保住 baseQuantity 的基础仓位
-        int slSize = Math.max(filledQty, Integer.parseInt(config.getBaseQuantity()));
+        // 原始仓位减仓模式:止损必须严格等于实际持仓,否则下次止损的“被平数量”会被撑回 baseQuantity,
+        // 导致递减卡死(base-step 后不再继续递减);非减仓模式才用 max(filledQty, baseQuantity) 兜底。
+        int slSize = config.getOriginalPositionReduce() > 0
+                ? filledQty
+                : Math.max(filledQty, Integer.parseInt(config.getBaseQuantity()));
         AtomicInteger remainCount = new AtomicInteger(1);
         int sgId = gridId - 2;
         placeStopLossOrders(sgId, 1, String.valueOf(slSize), FuturesPriceTrigger.RuleEnum.NUMBER_2,
@@ -3094,8 +3533,10 @@
         }
 
         // 单位置全量止损:当前方向全部持仓挂一张止损单(入场格上方第2格,价格≥触发价平空)。
-        // 取 max 是为了在 REST 时序竞态导致 filledQty 偏小时,至少保住 baseQuantity 的基础仓位
-        int slSize = Math.max(filledQty, Integer.parseInt(config.getBaseQuantity()));
+        // 原始仓位减仓模式:止损必须严格等于实际持仓,避免递减卡死;非减仓模式才用 max 兜底。
+        int slSize = config.getOriginalPositionReduce() > 0
+                ? filledQty
+                : Math.max(filledQty, Integer.parseInt(config.getBaseQuantity()));
         AtomicInteger remainCount = new AtomicInteger(1);
         int sgId = gridId + 2;
         placeStopLossOrders(sgId, 1, String.valueOf(slSize), FuturesPriceTrigger.RuleEnum.NUMBER_1,
@@ -3355,7 +3796,7 @@
         if (wsClient != null) {
             wsClient.setOnAllSubscribedCallback(() -> {
                 if (state == StrategyState.ACTIVE || state == StrategyState.OPENING) {
-                    executor.submitTask(this::syncPositionsFromExchange);
+                    executor.submitMaintenanceTask(this::syncPositionsFromExchange);
                 }
             });
         }
@@ -3507,14 +3948,16 @@
      * 取消所有多仓入场单(条件开仓单),并清空 GridElement 的多仓挂单记录。
      */
     private void cancelAllLongEntryOrders() {
+        longSlReentryGridId = Integer.MIN_VALUE;
         for (GridElement e : config.getGridElements()) {
-            if (e.getId() == 0) {
-                continue; // 基底网格 0 是市价单成交,非条件开仓单
-            }
+            // 注意:不再跳过 grid 0——价格驱动/补仓/对向加仓会在 grid 0 挂条件开仓单,
+            // 若跳过会导致止损全扫撤不掉 grid 0 的条件单,与追单并存形成双仓位。
+            // 基底市价单不注册在 *OrderIds 里,遍历无副作用。
             for (String oid : new ArrayList<>(e.getLongOrderIds())) {
                 // 同步清理对向加仓/补仓/加仓标记登记表,避免残留失效记录
                 tpOppositeLongOrderGridMap.remove(oid);
                 tpReplenishLongOrderMap.remove(oid);
+                reduceReplenishLongOrderMap.remove(oid);
                 pendingAddEntryOrderIds.remove(oid);
                 executor.cancelConditionalOrder(oid, o -> {});
             }
@@ -3531,14 +3974,16 @@
      * 取消所有空仓入场单(条件开仓单),并清空 GridElement 的空仓挂单记录。
      */
     private void cancelAllShortEntryOrders() {
+        shortSlReentryGridId = Integer.MIN_VALUE;
         for (GridElement e : config.getGridElements()) {
-            if (e.getId() == 0) {
-                continue; // 基底网格 0 是市价单成交,非条件开仓单
-            }
+            // 注意:不再跳过 grid 0——价格驱动/补仓/对向加仓会在 grid 0 挂条件开仓单,
+            // 若跳过会导致止损全扫撤不掉 grid 0 的条件单,与追单并存形成双仓位。
+            // 基底市价单不注册在 *OrderIds 里,遍历无副作用。
             for (String oid : new ArrayList<>(e.getShortOrderIds())) {
                 // 同步清理对向加仓/补仓/加仓标记登记表,避免残留失效记录
                 tpOppositeShortOrderGridMap.remove(oid);
                 tpReplenishShortOrderMap.remove(oid);
+                reduceReplenishShortOrderMap.remove(oid);
                 pendingAddEntryOrderIds.remove(oid);
                 executor.cancelConditionalOrder(oid, o -> {});
             }
@@ -3732,31 +4177,35 @@
     }
 
     /**
-     * 基础止盈:对基础仓位(baseQuantity)也挂止盈单,与超额止盈并行。
+     * 基础止盈:对基础仓位挂止盈单,与超额止盈并行(原始仓位止盈挂单优化)。
      *
-     * <p>规则:从入场网格下一格(entryGridId ± 1)开始,每格 baseTakeProfitPerGrid 张,
-     * 最多挂 baseTakeProfitGridCount 格,挂到止损位前 2 格截止(即对手盘仓位线)。
+     * <p>规则:
+     * <ol>
+     *   <li>总数量 = {@code baseTakeProfitTotalQty}(原始仓位止盈总数量);</li>
+     *   <li>网格范围:从入场网格下一格(entryGridId ± 1,起始位置不变)
+     *       一直挂到<b>对手盘止损位的前一个格子</b>;</li>
+     *   <li>每格数量 = 总数量 ÷ 网格数平均分配,余数挂在最后一个格子;
+     *       每格最少 1 张,总量不够网格数时从起始格开始各挂 1 张(挂到哪算哪)。</li>
+     * </ol>
      *
-     * <p>边界:累计张数到 min(baseQuantity, 当前持仓) 即停(张数不足则最后一格挂剩余 = "挂几个算几个");
-     * 网格不足时挂到停止位置结束。
+     * <p>张数硬上限 = min(设置总量, baseQuantity, 当前持仓),避免持仓不足时超挂。
      *
      * @param posSize     当前总持仓张数
      * @param isLong      true=多仓止盈,false=空仓止盈
      * @param entryGridId 入场网格 ID
      */
     private void placeBaseTakeProfit(int posSize, boolean isLong, int entryGridId) {
-        BigDecimal perGrid = config.getBaseTakeProfitPerGrid();
-        int gridCount = config.getBaseTakeProfitGridCount();
-        if (perGrid == null || perGrid.compareTo(BigDecimal.ZERO) <= 0 || gridCount <= 0) {
+        int totalQty = config.getBaseTakeProfitTotalQty();
+        if (totalQty <= 0) {
             return;
         }
         int baseQty = Integer.parseInt(config.getBaseQuantity());
         if (baseQty <= 0) {
             return;
         }
-        // 张数硬上限 = min(基础张数, 当前持仓),避免持仓不足 baseQuantity 时超挂
-        int maxQty = Math.min(baseQty, posSize);
-        if (maxQty <= 0) {
+        // 张数硬上限 = min(设置总量, 基础张数, 当前持仓),避免持仓不足 baseQuantity 时超挂
+        totalQty = Math.min(totalQty, Math.min(baseQty, posSize));
+        if (totalQty <= 0) {
             return;
         }
 
@@ -3767,13 +4216,12 @@
         }
         int dir = isLong ? 1 : -1;
         int startId = entryGridId + dir;
-        // 分配范围到止损位前 2 格截止(即对手盘仓位线)
-        int endId = endElem.getId() - 2 * dir;
+        // 一直挂到对手盘止损位的前一个格子
+        int endId = endElem.getId() - dir;
 
-        BigDecimal remaining = BigDecimal.valueOf(maxQty);
-        int placed = 0;
-        int id = startId;
-        while (placed < gridCount && remaining.compareTo(BigDecimal.ZERO) > 0) {
+        // 收集范围内所有网格(安全上限防异常数据长循环)
+        List<GridElement> gridList = new ArrayList<>();
+        for (int id = startId; ; id += dir) {
             if (isLong ? id > endId : id < endId) {
                 break;
             }
@@ -3781,12 +4229,36 @@
             if (elem == null) {
                 break;
             }
-            BigDecimal qty = perGrid.min(remaining);
-            final int fqty = qty.intValue();
+            gridList.add(elem);
+            if (gridList.size() > config.getGridQueueSize() * 2 + 4) {
+                break;
+            }
+        }
+        if (gridList.isEmpty()) {
+            return;
+        }
+        int n = gridList.size();
+        int perGrid = totalQty / n;
+        int remainder = totalQty % n;
+
+        for (int i = 0; i < n; i++) {
+            int qty;
+            if (totalQty < n) {
+                // 总量不够铺满:每格至少 1 张,从起始格开始挂 totalQty 格,挂到哪算哪
+                qty = (i < totalQty) ? 1 : 0;
+            } else {
+                // 平均分配,余数挂在最后一个格子(最靠近对手盘止损位的那格)
+                qty = perGrid + (i == n - 1 ? remainder : 0);
+            }
+            if (qty <= 0) {
+                continue;
+            }
+            GridElement elem = gridList.get(i);
+            final int fqty = qty;
             final GridElement fe = elem;
-            final int gid = id;
+            final int gid = elem.getId();
             final BigDecimal triggerPrice = elem.getGridPrice();
-            final String size = isLong ? negate(qty.toPlainString()) : qty.toPlainString();
+            final String size = isLong ? negate(String.valueOf(qty)) : String.valueOf(qty);
             final String orderType = isLong ? ORDER_TYPE_CLOSE_LONG : ORDER_TYPE_CLOSE_SHORT;
             final FuturesPriceTrigger.RuleEnum rule = isLong ? FuturesPriceTrigger.RuleEnum.NUMBER_1
                     : FuturesPriceTrigger.RuleEnum.NUMBER_2;
@@ -3801,12 +4273,9 @@
                                 isLong ? "多仓" : "空仓", gid, triggerPrice, size, profitId);
                     }
             );
-            remaining = remaining.subtract(qty);
-            placed++;
-            id += dir;
         }
-        log.info("[Gate] 基础止盈 {} 挂单完成, 入场gridId:{}, 挂{}格, 剩余{}张",
-                isLong ? "多仓" : "空仓", entryGridId, placed, remaining);
+        log.info("[Gate] 基础止盈 {} 挂单完成, 入场gridId:{}, 网格数:{}, 总量:{}张, 每格:{}张, 余数:{}张",
+                isLong ? "多仓" : "空仓", entryGridId, n, totalQty, perGrid, remainder);
     }
 
     /**

--
Gitblit v1.9.1