From ff4092f79b634f0921283a15167a867e06a99add Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 25 Jun 2026 14:45:27 +0800
Subject: [PATCH] refactor(gateApi): 止盈都严格保持 2 个 grid 间距

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 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 d0c264a..7e458a9 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -650,7 +650,7 @@
                     BigDecimal shortExcess = BigDecimal.valueOf(posSize).subtract(shortBaseQty);
                     int shortExcessCount = shortExcess.divide(shortGridQty, 0, RoundingMode.DOWN).intValue();
                     for (int i = 0; i < shortExcessCount; i++) {
-                        int tpGridId = shortGridElement.getId() - 2 - i;
+                        int tpGridId = shortGridElement.getId() - 2 * (i + 1);
                         GridElement tpElem = GridElement.findById(tpGridId);
                         if (tpElem == null || tpElem.getShortTakeProfitOrderId() != null) {
                             continue;
@@ -692,7 +692,7 @@
                     BigDecimal longExcess = BigDecimal.valueOf(posSize).subtract(longBaseQty);
                     int longExcessCount = longExcess.divide(longGridQty, 0, RoundingMode.DOWN).intValue();
                     for (int i = 0; i < longExcessCount; i++) {
-                        int tpGridId = longGridElement.getId() + 2 + i;
+                        int tpGridId = longGridElement.getId() + 2 * (i + 1);
                         GridElement tpElem = GridElement.findById(tpGridId);
                         if (tpElem == null || tpElem.getLongTakeProfitOrderId() != null) {
                             continue;
@@ -1331,6 +1331,14 @@
         if (span <= 0) {
             return;
         }
+
+        // 检查是否还有剩余止盈单,只有多空止盈全部清空才继续
+        if (GridElement.getLongTakeProfitCount() > 0 || GridElement.getShortTakeProfitCount() > 0) {
+            log.info("[Gate] 尚有未触发止盈单, 暂不检查跨度重启 longTpCount:{}, shortTpCount:{}",
+                    GridElement.getLongTakeProfitCount(), GridElement.getShortTakeProfitCount());
+            return;
+        }
+
         BigDecimal step = config.getStep();
         if (step == null || step.compareTo(BigDecimal.ZERO) == 0) {
             return;

--
Gitblit v1.9.1