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); 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(); } } 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(); } 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); 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); 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' }; }