From 8cadc2c947d541bd2621892b5764d2d3e7697cad Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Fri, 30 Oct 2026 17:49:33 +0800
Subject: [PATCH] feat(gate): 实现仓位止盈补仓功能

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
index fa70691..f87a98a 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -121,6 +121,8 @@
     private final int maxPositionPerSide;
     /** 加仓启动阈值:前N次止损不触发加仓,默认 1(第1次止损不加仓,第2次起按公式计算) */
     private final int addPositionStartThreshold;
+    /** 加仓停止阈值:启动加仓后按「加仓执行次数」计数,超过该值后加仓张数恢复为基础张数;0=不限制 */
+    private final int addPositionStopThreshold;
     /** 止盈挂单模式:关闭 */
     public static final String EXCESS_TP_OFF = "off";
     /** 止盈挂单模式:集中止盈(挂在对手第一止损位) */
@@ -140,6 +142,8 @@
     private final boolean tpTriggerOppositeAddEnabled;
     /** 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数,0=不启用。默认 0 */
     private final int tpTriggerOppositeAddQuantity;
+    /** 仓位止盈补仓开关:true=止盈触发时在对侧止损位挂同方向同张数开仓单,false=保持现有逻辑。默认 false */
+    private final boolean tpPositionReplenishEnabled;
     /** 单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数,支持小数。默认 0 */
     private final BigDecimal baseTakeProfitPerGrid;
     /** 止盈网格数量:基础仓位止盈挂单的网格数量。默认 0 */
@@ -184,12 +188,14 @@
         this.addPositionQuantity = builder.addPositionQuantity;
         this.maxPositionPerSide = builder.maxPositionPerSide;
         this.addPositionStartThreshold = builder.addPositionStartThreshold;
+        this.addPositionStopThreshold = builder.addPositionStopThreshold;
         this.placeExcessTakeProfit = builder.placeExcessTakeProfit;
         this.dualStopLossEnabled = builder.dualStopLossEnabled;
         this.longStopLossPrice = builder.longStopLossPrice;
         this.shortStopLossPrice = builder.shortStopLossPrice;
         this.tpTriggerOppositeAddEnabled = builder.tpTriggerOppositeAddEnabled;
         this.tpTriggerOppositeAddQuantity = builder.tpTriggerOppositeAddQuantity;
+        this.tpPositionReplenishEnabled = builder.tpPositionReplenishEnabled;
         this.baseTakeProfitPerGrid = builder.baseTakeProfitPerGrid;
         this.baseTakeProfitGridCount = builder.baseTakeProfitGridCount;
     }
@@ -297,6 +303,8 @@
     public int getMaxPositionPerSide() { return maxPositionPerSide; }
     /** @return 加仓启动阈值:前N次止损不触发加仓 */
     public int getAddPositionStartThreshold() { return addPositionStartThreshold; }
+    /** @return 加仓停止阈值:启动加仓后加仓执行次数上限,超过后加仓张数恢复基础张数;0=不限制 */
+    public int getAddPositionStopThreshold() { return addPositionStopThreshold; }
     /** @return 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈 */
     public String getPlaceExcessTakeProfit() { return placeExcessTakeProfit; }
     /** @return 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损 */
@@ -309,6 +317,8 @@
     public boolean isTpTriggerOppositeAddEnabled() { return tpTriggerOppositeAddEnabled; }
     /** @return 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数 */
     public int getTpTriggerOppositeAddQuantity() { return tpTriggerOppositeAddQuantity; }
+    /** @return 仓位止盈补仓开关:true=止盈触发时在对侧止损位挂同方向同张数开仓单 */
+    public boolean isTpPositionReplenishEnabled() { return tpPositionReplenishEnabled; }
     /** @return 单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数 */
     public BigDecimal getBaseTakeProfitPerGrid() { return baseTakeProfitPerGrid; }
     /** @return 止盈网格数量:基础仓位止盈挂单的网格数量 */
@@ -423,6 +433,8 @@
         private int maxPositionPerSide = 0;
         /** 加仓启动阈值:前N次止损不触发加仓,调整后的 effectiveCount = max(0, count - threshold)。默认 1 */
         private int addPositionStartThreshold = 1;
+        /** 加仓停止阈值:启动加仓后按加仓执行次数计数,超过该值后加仓张数恢复基础张数,0=不限制。默认 0 */
+        private int addPositionStopThreshold = 0;
         /** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */
         private String placeExcessTakeProfit = EXCESS_TP_OFF;
         /** 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损。默认 false */
@@ -435,6 +447,8 @@
         private boolean tpTriggerOppositeAddEnabled = false;
         /** 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数,默认 0 */
         private int tpTriggerOppositeAddQuantity = 0;
+        /** 仓位止盈补仓开关:true=止盈触发时在对侧止损位挂同方向同张数开仓单。默认 false */
+        private boolean tpPositionReplenishEnabled = false;
         /** 单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数,默认 0 */
         private BigDecimal baseTakeProfitPerGrid = BigDecimal.ZERO;
         /** 止盈网格数量:基础仓位止盈挂单的网格数量,默认 0 */
@@ -500,6 +514,8 @@
         public Builder maxPositionPerSide(int maxPositionPerSide) { this.maxPositionPerSide = maxPositionPerSide; return this; }
         /** 设置加仓启动阈值:前N次止损不触发加仓,0=立即启动 */
         public Builder addPositionStartThreshold(int addPositionStartThreshold) { this.addPositionStartThreshold = addPositionStartThreshold; return this; }
+        /** 设置加仓停止阈值:启动加仓后加仓执行次数上限,0=不限制 */
+        public Builder addPositionStopThreshold(int addPositionStopThreshold) { this.addPositionStopThreshold = addPositionStopThreshold; return this; }
         /** 设置止盈挂单模式:off / concentrated / dispersed */
         public Builder placeExcessTakeProfit(String placeExcessTakeProfit) { this.placeExcessTakeProfit = placeExcessTakeProfit; return this; }
         /** 设置自定义止损开关:true=启用自定义止损触发价 */
@@ -512,6 +528,8 @@
         public Builder tpTriggerOppositeAddEnabled(boolean tpTriggerOppositeAddEnabled) { this.tpTriggerOppositeAddEnabled = tpTriggerOppositeAddEnabled; return this; }
         /** 设置对向加仓挂单数量:止盈成交后在对向挂出的开仓张数 */
         public Builder tpTriggerOppositeAddQuantity(int tpTriggerOppositeAddQuantity) { this.tpTriggerOppositeAddQuantity = tpTriggerOppositeAddQuantity; return this; }
+        /** 设置仓位止盈补仓开关:true=启用,false=禁用 */
+        public Builder tpPositionReplenishEnabled(boolean tpPositionReplenishEnabled) { this.tpPositionReplenishEnabled = tpPositionReplenishEnabled; return this; }
         /** 设置单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数 */
         public Builder baseTakeProfitPerGrid(BigDecimal baseTakeProfitPerGrid) { this.baseTakeProfitPerGrid = baseTakeProfitPerGrid; return this; }
         /** 设置止盈网格数量:基础仓位止盈挂单的网格数量 */

--
Gitblit v1.9.1