From cfa95932813c1497195384df19f23913007fcd1a Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 22 Jul 2026 15:56:15 +0800
Subject: [PATCH] feat(gate-config): 添加价格驱动开关配置功能

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java         |    2 ++
 src/main/resources/static/gate-config.html                                       |    7 +++++--
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java                |    3 +++
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java |    1 +
 src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java   |    1 +
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java                   |    9 +++++++++
 6 files changed, 21 insertions(+), 2 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 f7e1d46..88f0a48 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -107,6 +107,8 @@
     private final int stopLossCount;
     /** 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2(即隔一格挂一个止盈单) */
     private final int takeProfitGridSpan;
+    /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。默认 false */
+    private final boolean priceDriveEnabled;
     /** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */
     private BigDecimal step;
     /** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */
@@ -140,6 +142,7 @@
         this.restartGridSpan = builder.restartGridSpan;
         this.stopLossCount = builder.stopLossCount;
         this.takeProfitGridSpan = builder.takeProfitGridSpan;
+        this.priceDriveEnabled = builder.priceDriveEnabled;
     }
 
     // ==================== REST/WS 地址 ====================
@@ -231,6 +234,8 @@
     public int getStopLossCount() { return stopLossCount; }
     /** @return 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */
     public int getTakeProfitGridSpan() { return takeProfitGridSpan; }
+    /** @return 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用 */
+    public boolean isPriceDriveEnabled() { return priceDriveEnabled; }
 
     // ==================== 运行时参数 ====================
 
@@ -327,6 +332,8 @@
         private int stopLossCount = 0;
         /** 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */
         private int takeProfitGridSpan = 2;
+        /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。默认 true */
+        private boolean priceDriveEnabled = true;
 
         /** 设置 API Key */
         public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; }
@@ -374,6 +381,8 @@
         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; }
 
         public GateConfig build() {
             return new GateConfig(this);
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java
index ba1de66..98e1ef1 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java
@@ -53,6 +53,8 @@
     private String unrealizedPnlPriceMode;
     /** 是否为生产环境 */
     private boolean isProduction;
+    /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。null=未设置(默认true) */
+    private Boolean priceDriveEnabled;
 
     /**
      * 从 GateConfig 构建 DTO(不暴露 apiSecret)。
@@ -78,6 +80,7 @@
                 .unrealizedPnlPriceMode(config.getUnrealizedPnlPriceMode() != null
                         ? config.getUnrealizedPnlPriceMode().name() : "LAST_PRICE")
                 .isProduction(config.isProduction())
+                .priceDriveEnabled(config.isPriceDriveEnabled())
                 .build();
     }
 }
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
index 3a8d315..4828f0a 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
@@ -104,6 +104,7 @@
                 .maxPositionSize(dto.getMaxPositionSize())
                 .stopLossCount(dto.getStopLossCount())
                 .takeProfitGridSpan(dto.getTakeProfitGridSpan())
+                .priceDriveEnabled(nvl(dto.getPriceDriveEnabled(), true))
                 .build();
     }
 
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 790c147..c640610 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -403,6 +403,7 @@
         executor.submitTask(this::checkProfitAndReset);
 
         if (state == StrategyState.ACTIVE &&
+                config.isPriceDriveEnabled() &&
                 longActive == false &&
                     longPositionSize.compareTo(BigDecimal.ZERO) == 0){
             processShortGrid(closePrice);
@@ -410,6 +411,7 @@
 
 
         if (state == StrategyState.ACTIVE &&
+                config.isPriceDriveEnabled() &&
                 shortActive == false &&
                         shortPositionSize.compareTo(BigDecimal.ZERO) == 0){
             processLongGrid(closePrice);
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
index f68a09e..1bbfcfc 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
@@ -94,6 +94,7 @@
                         .quantity("2")
                         .maxPositionSize(4)
                         .stopLossCount(0)
+                        .priceDriveEnabled(true)
                         .build();
                 // 确保配置文件存在
                 persistenceService.ensureExists(DEFAULT_API_KEY, defaults);
diff --git a/src/main/resources/static/gate-config.html b/src/main/resources/static/gate-config.html
index 8d91360..cbb6b2d 100644
--- a/src/main/resources/static/gate-config.html
+++ b/src/main/resources/static/gate-config.html
@@ -115,6 +115,7 @@
             <div class="form-group"><label>最大持仓张数</label><input id="maxPositionSize" placeholder="4"></div>
             <div class="form-group"><label>止损阶梯次数</label><input id="stopLossCount" placeholder="0"></div>
             <div class="form-group"><label>止盈网格跨度</label><input id="takeProfitGridSpan" placeholder="2"></div>
+            <div class="form-group"><label>价格驱动开关</label><select id="priceDriveEnabled"><option value="true" selected>开启</option><option value="false">关闭</option></select></div>
         </form>
     </div>
 
@@ -190,7 +191,7 @@
     } catch(e) {
         // 文件不存在 → 用默认值填充,用户可编辑后保存
         fillForm({ gridRate:0.005, expectedProfit:0.15, maxLoss:1.5,
-            baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2 });
+            baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2, priceDriveEnabled: true });
         toast('未找到配置,已加载默认值,编辑后请保存', 'success');
     }
     currentApiKey = key;
@@ -208,6 +209,7 @@
     byId('maxPositionSize').value = d.maxPositionSize ?? '';
     byId('stopLossCount').value = d.stopLossCount ?? '';
     byId('takeProfitGridSpan').value = d.takeProfitGridSpan ?? '';
+    byId('priceDriveEnabled').value = (d.priceDriveEnabled === true || d.priceDriveEnabled === 'true') ? 'true' : 'false';
 }
 
 function collectForm() {
@@ -220,7 +222,8 @@
         quantity: byId('quantity').value,
         maxPositionSize: parseInt(byId('maxPositionSize').value) || 0,
         stopLossCount: parseInt(byId('stopLossCount').value) || 0,
-        takeProfitGridSpan: parseInt(byId('takeProfitGridSpan').value) || 2
+        takeProfitGridSpan: parseInt(byId('takeProfitGridSpan').value) || 2,
+        priceDriveEnabled: byId('priceDriveEnabled').value === 'true'
     };
 }
 

--
Gitblit v1.9.1