From ad4287624aefa37aaa8fdc2b56886e868217f48e Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 21 Sep 2026 09:57:48 +0800
Subject: [PATCH] fix(gateApi): 修复止损逻辑只针对初始开仓仓位

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 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 3b1fde1..b87daf0 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -150,7 +150,7 @@
     /** 最近触发止损的空头网格ID */
     private volatile int lastShortStopLossGridId = Integer.MAX_VALUE;
     /** 自定义止损模式激活标记:true=尚未发生第一次止损触发,第一次触发后置 false(触发未触发侧重挂默认) */
-    private final AtomicBoolean customStopLossModeActive = new AtomicBoolean(false);
+    private final AtomicBoolean dualStopLossModeActive = new AtomicBoolean(false);
 
     private volatile BigDecimal lastKlinePrice;
     private volatile BigDecimal markPrice = BigDecimal.ZERO;
@@ -365,7 +365,7 @@
         accumulatedShortLossCount = 0;
         lastLongStopLossGridId = Integer.MAX_VALUE;
         lastShortStopLossGridId = Integer.MAX_VALUE;
-        customStopLossModeActive.set(false);
+        dualStopLossModeActive.set(false);
         shortPriceQueue.clear();
         longPriceQueue.clear();
         totalShortPriceQueue.clear();
@@ -978,7 +978,7 @@
 //                );
 //            }
 
-            if (config.isCustomStopLossEnabled()) {
+            if (config.isDualStopLossEnabled()) {
                 placeCustomStopLosses();
             } else {
                 placeDefaultStopLossLadders();
@@ -995,10 +995,10 @@
      * 多仓止损:NUMBER_2(价格 ≤ 触发价平多),空仓止损:NUMBER_1(价格 ≥ 触发价平空)。
      */
     private void placeCustomStopLosses() {
-        customStopLossModeActive.set(true);
+        dualStopLossModeActive.set(true);
         String baseQty = config.getBaseQuantity();
-        BigDecimal longPrice = config.getLongCustomStopLossPrice();
-        BigDecimal shortPrice = config.getShortCustomStopLossPrice();
+        BigDecimal longPrice = config.getLongStopLossPrice();
+        BigDecimal shortPrice = config.getShortStopLossPrice();
 
         if (longPrice != null && longPrice.compareTo(BigDecimal.ZERO) > 0) {
             GridElement longElem = findNearestGridElementByPrice(longPrice);
@@ -1654,7 +1654,7 @@
         }
 
         // 自定义止损模式:第一次止损触发时,取消未触发侧(空仓)自定义止损单并重挂默认阶梯
-        if (config.isCustomStopLossEnabled() && customStopLossModeActive.compareAndSet(true, false)) {
+        if (config.isDualStopLossEnabled() && dualStopLossModeActive.compareAndSet(true, false)) {
             cancelAllShortStopLossesOnly();
             placeDefaultShortStopLossLadder();
             log.info("[Gate] 自定义止损首次触发(多仓), 已取消空仓自定义止损并重挂默认阶梯");
@@ -1713,7 +1713,7 @@
         }
 
         // 自定义止损模式:第一次止损触发时,取消未触发侧(多仓)自定义止损单并重挂默认阶梯
-        if (config.isCustomStopLossEnabled() && customStopLossModeActive.compareAndSet(true, false)) {
+        if (config.isDualStopLossEnabled() && dualStopLossModeActive.compareAndSet(true, false)) {
             cancelAllLongStopLossesOnly();
             placeDefaultLongStopLossLadder();
             log.info("[Gate] 自定义止损首次触发(空仓), 已取消多仓自定义止损并重挂默认阶梯");
@@ -1943,7 +1943,8 @@
             return;
         }
 
-        int totalOrders = filledQty / qty;
+        // [Gate] 止损只针对初始开仓仓位(baseQuantity),加仓部分只做止盈
+        int totalOrders = baseQty / qty;
         int[] orders = new int[gridCount];
 
         if (gridCount == 1) {
@@ -2005,7 +2006,8 @@
             return;
         }
 
-        int totalOrders = filledQty / qty;
+        // [Gate] 止损只针对初始开仓仓位(baseQuantity),加仓部分只做止盈
+        int totalOrders = baseQty / qty;
         int[] orders = new int[gridCount];
 
         if (gridCount == 1) {

--
Gitblit v1.9.1