From 5a2c3b8966269f77b60a698af602ffcfefc459ce Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 10 Aug 2026 13:53:01 +0800
Subject: [PATCH] feat(gate): 添加加仓止损配置功能

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 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 a583c2f..5f9ab69 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -81,6 +81,10 @@
     private final BigDecimal maxLoss;
     /** 下单数量(合约张数) */
     private final String quantity;
+    /** 基底开仓张数(初始化时多空各开的张数,如 "10") */
+    private final String baseQuantity;
+    /** 预期收益(USDT),unrealisedPnl + available > 初始本金 + 此值时重置 */
+    private final BigDecimal expectedProfit;
     /** 是否为生产环境 */
     private final boolean isProduction;
     /** 补仓最大重试次数 */
@@ -95,6 +99,26 @@
     private final int priceScale;
     /** 未实现盈亏计价模式:最新价 / 标记价格 */
     private final PnLPriceMode unrealizedPnlPriceMode;
+    /** 最大持仓张数(单方向),0=不限制 */
+    private final int maxPositionSize;
+    /** 策略重启跨度阈值:多空两边止盈触发数量均达到此值后触发重启,0=禁用 */
+    private final int restartGridSpan;
+    /** 止损阶梯次数:止损触发次数≤该值时挂单量=止损次数,超过后恢复默认逻辑。0=禁用,默认 0 */
+    private final int stopLossCount;
+    /** 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2(即隔一格挂一个止盈单) */
+    private final int takeProfitGridSpan;
+    /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。默认 true */
+    private final boolean priceDriveEnabled;
+    /** 策略运行轮数:达到盈利后重启算一轮,达到上限后不再重启。0=不限轮数 */
+    private final int rounds;
+    /** 止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计,默认 "dual" */
+    private final String stopLossCountMode;
+    /** 加仓间隔:每隔多少次止损触发一次加仓,默认 3 */
+    private final int addPositionInterval;
+    /** 加仓数量:每次加仓追加的张数,默认 1 */
+    private final int addPositionQuantity;
+    /** 单边最大仓位量:单向持仓张数上限,超出则按上限挂单,0=不限制 */
+    private final int maxPositionPerSide;
     /** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */
     private BigDecimal step;
     /** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */
@@ -115,6 +139,8 @@
         this.overallTp = builder.overallTp;
         this.maxLoss = builder.maxLoss;
         this.quantity = builder.quantity;
+        this.baseQuantity = builder.baseQuantity;
+        this.expectedProfit = builder.expectedProfit;
         this.isProduction = builder.isProduction;
         this.reopenMaxRetries = builder.reopenMaxRetries;
         this.gridQueueSize = builder.gridQueueSize;
@@ -122,6 +148,16 @@
         this.contractMultiplier = builder.contractMultiplier;
         this.priceScale = builder.priceScale;
         this.unrealizedPnlPriceMode = builder.unrealizedPnlPriceMode;
+        this.maxPositionSize = builder.maxPositionSize;
+        this.restartGridSpan = builder.restartGridSpan;
+        this.stopLossCount = builder.stopLossCount;
+        this.takeProfitGridSpan = builder.takeProfitGridSpan;
+        this.priceDriveEnabled = builder.priceDriveEnabled;
+        this.rounds = builder.rounds;
+        this.stopLossCountMode = builder.stopLossCountMode;
+        this.addPositionInterval = builder.addPositionInterval;
+        this.addPositionQuantity = builder.addPositionQuantity;
+        this.maxPositionPerSide = builder.maxPositionPerSide;
     }
 
     // ==================== REST/WS 地址 ====================
@@ -183,6 +219,10 @@
     public BigDecimal getMaxLoss() { return maxLoss; }
     /** @return 每次下单的张数(如 "1" 表示 1 张合约) */
     public String getQuantity() { return quantity; }
+    /** @return 基底开仓张数(初始化时多空各开的张数,如 "10") */
+    public String getBaseQuantity() { return baseQuantity; }
+    /** @return 预期收益(USDT),unrealisedPnl + available > 初始本金 + 此值时重置 */
+    public BigDecimal getExpectedProfit() { return expectedProfit; }
     /** @return 网格价格队列的容量上限(超出时截断尾部) */
     public int getGridQueueSize() { return gridQueueSize; }
 
@@ -201,6 +241,26 @@
     public int getPriceScale() { return priceScale; }
     /** @return 未实现盈亏计价模式:LAST_PRICE(最新成交价)/ MARK_PRICE(标记价格) */
     public PnLPriceMode getUnrealizedPnlPriceMode() { return unrealizedPnlPriceMode; }
+    /** @return 最大持仓张数(单方向),0=不限制 */
+    public int getMaxPositionSize() { return maxPositionSize; }
+    /** @return 策略重启跨度阈值:多空两边止盈触发数均达到此值后触发重启,0=禁用 */
+    public int getRestartGridSpan() { return restartGridSpan; }
+    /** @return 止损阶梯次数:止损触发次数≤该值时挂单量=止损次数,超过后恢复默认逻辑。0=禁用 */
+    public int getStopLossCount() { return stopLossCount; }
+    /** @return 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */
+    public int getTakeProfitGridSpan() { return takeProfitGridSpan; }
+    /** @return 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用 */
+    public boolean isPriceDriveEnabled() { return priceDriveEnabled; }
+    /** @return 策略运行轮数上限,0=不限 */
+    public int getRounds() { return rounds; }
+    /** @return 止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计 */
+    public String getStopLossCountMode() { return stopLossCountMode; }
+    /** @return 加仓间隔:每隔多少次止损触发一次加仓 */
+    public int getAddPositionInterval() { return addPositionInterval; }
+    /** @return 加仓数量:每次加仓追加的张数 */
+    public int getAddPositionQuantity() { return addPositionQuantity; }
+    /** @return 单边最大仓位量:单向持仓张数上限,0=不限制 */
+    public int getMaxPositionPerSide() { return maxPositionPerSide; }
 
     // ==================== 运行时参数 ====================
 
@@ -271,6 +331,10 @@
         private BigDecimal maxLoss = new BigDecimal("7.5");
         /** 每次下单张数,默认 "1" */
         private String quantity = "1";
+        /** 基底开仓张数,默认 "10"(初始化时多空各开10张) */
+        private String baseQuantity = "10";
+        /** 预期收益(USDT),默认 0.5 */
+        private BigDecimal expectedProfit = new BigDecimal("0.5");
         /** 是否为生产环境,默认 false(测试网) */
         private boolean isProduction = false;
         /** 补仓最大重试次数,默认 3 */
@@ -285,6 +349,26 @@
         private int priceScale = 1;
         /** 未实现盈亏计价模式,默认 LAST_PRICE(最新成交价) */
         private PnLPriceMode unrealizedPnlPriceMode = PnLPriceMode.LAST_PRICE;
+        /** 最大持仓张数(单方向),默认 0=不限制 */
+        private int maxPositionSize = 0;
+        /** 策略重启跨度阈值:多空两边止盈触发数量均达到此值后触发重启,默认 0=禁用 */
+        private int restartGridSpan = 0;
+        /** 止损阶梯次数:止损触发次数≤该值时挂单量=止损次数,超过后恢复默认逻辑。0=禁用,默认 0 */
+        private int stopLossCount = 0;
+        /** 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */
+        private int takeProfitGridSpan = 2;
+        /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。默认 true */
+        private boolean priceDriveEnabled = true;
+        /** 策略运行轮数上限,0=不限轮数。默认 0 */
+        private int rounds = 0;
+        /** 止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计,默认 "dual" */
+        private String stopLossCountMode = "dual";
+        /** 加仓间隔:每隔多少次止损触发一次加仓,默认 3 */
+        private int addPositionInterval = 3;
+        /** 加仓数量:每次加仓追加的张数,默认 1 */
+        private int addPositionQuantity = 1;
+        /** 单边最大仓位量:单向持仓张数上限,超出则按上限挂单,0=不限制 */
+        private int maxPositionPerSide = 0;
 
         /** 设置 API Key */
         public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; }
@@ -306,6 +390,10 @@
         public Builder maxLoss(BigDecimal maxLoss) { this.maxLoss = maxLoss; return this; }
         /** 设置每次下单张数 */
         public Builder quantity(String quantity) { this.quantity = quantity; return this; }
+        /** 设置基底开仓张数 */
+        public Builder baseQuantity(String baseQuantity) { this.baseQuantity = baseQuantity; return this; }
+        /** 设置预期收益(USDT) */
+        public Builder expectedProfit(BigDecimal expectedProfit) { this.expectedProfit = expectedProfit; return this; }
         /** 设置环境(true=实盘生产网 / false=模拟盘测试网) */
         public Builder isProduction(boolean isProduction) { this.isProduction = isProduction; return this; }
         /** 设置补仓最大重试次数 */
@@ -320,6 +408,26 @@
         public Builder gridQueueSize(int gridQueueSize) { this.gridQueueSize = gridQueueSize; return this; }
         /** 设置未实现盈亏计价模式 */
         public Builder unrealizedPnlPriceMode(PnLPriceMode mode) { this.unrealizedPnlPriceMode = mode; return this; }
+        /** 设置最大持仓张数(单方向),0=不限制 */
+        public Builder maxPositionSize(int maxPositionSize) { this.maxPositionSize = maxPositionSize; return this; }
+        /** 设置策略重启跨度阈值:多空两边止盈触发数均达到此值后触发重启,0=禁用 */
+        public Builder restartGridSpan(int restartGridSpan) { this.restartGridSpan = restartGridSpan; return this; }
+        /** 设置止损阶梯次数:止损触发次数≤该值时挂单量=止损次数,超过后恢复默认逻辑。0=禁用 */
+        public Builder stopLossCount(int stopLossCount) { this.stopLossCount = stopLossCount; return this; }
+        /** 设置止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */
+        public Builder takeProfitGridSpan(int takeProfitGridSpan) { this.takeProfitGridSpan = takeProfitGridSpan; return this; }
+        /** 设置价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用 */
+        public Builder priceDriveEnabled(boolean priceDriveEnabled) { this.priceDriveEnabled = priceDriveEnabled; return this; }
+        /** 设置策略运行轮数上限:达到盈利后重启计数,达到此值后不再重启。0=不限 */
+        public Builder rounds(int rounds) { this.rounds = rounds; return this; }
+        /** 设置止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计 */
+        public Builder stopLossCountMode(String stopLossCountMode) { this.stopLossCountMode = stopLossCountMode; return this; }
+        /** 设置加仓间隔:每隔多少次止损触发一次加仓 */
+        public Builder addPositionInterval(int addPositionInterval) { this.addPositionInterval = addPositionInterval; return this; }
+        /** 设置加仓数量:每次加仓追加的张数 */
+        public Builder addPositionQuantity(int addPositionQuantity) { this.addPositionQuantity = addPositionQuantity; return this; }
+        /** 设置单边最大仓位量:单向持仓张数上限,0=不限制 */
+        public Builder maxPositionPerSide(int maxPositionPerSide) { this.maxPositionPerSide = maxPositionPerSide; return this; }
 
         public GateConfig build() {
             return new GateConfig(this);

--
Gitblit v1.9.1