From 3ebd59a88bc0bdcf91dff94ad2ba25e1f4fe682f Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 19 Nov 2026 17:38:35 +0800
Subject: [PATCH] feat(config): 添加原始仓位减仓递减步长配置
---
src/main/resources/static/station-dashboard.html | 2 ++
src/main/java/com/xcong/excoin/modules/station/entity/StrategyStatus.java | 3 +++
src/main/resources/static/gate-config.html | 5 ++++-
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java | 5 +++++
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java | 1 +
src/main/java/com/xcong/excoin/modules/station/service/impl/StationServiceImpl.java | 1 +
src/main/resources/db/station-schema.sql | 8 ++++++++
src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java | 9 +++++++++
8 files changed, 33 insertions(+), 1 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 9afad22..dfb20d7 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -123,6 +123,8 @@
private final int addPositionStartThreshold;
/** 超额止盈开关:true=挂单成交后将超出基础仓位的部分挂止盈单(挂在对手第一止损位),默认 false */
private final boolean placeExcessTakeProfit;
+ /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */
+ private final int originalPositionReduce;
/** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */
private BigDecimal step;
/** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */
@@ -164,6 +166,7 @@
this.maxPositionPerSide = builder.maxPositionPerSide;
this.addPositionStartThreshold = builder.addPositionStartThreshold;
this.placeExcessTakeProfit = builder.placeExcessTakeProfit;
+ this.originalPositionReduce = builder.originalPositionReduce;
}
// ==================== REST/WS 地址 ====================
@@ -271,6 +274,8 @@
public int getAddPositionStartThreshold() { return addPositionStartThreshold; }
/** @return 超额止盈开关:true=挂单成交后将超出基础仓位的部分挂止盈单 */
public boolean isPlaceExcessTakeProfit() { return placeExcessTakeProfit; }
+ /** @return 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长 */
+ public int getOriginalPositionReduce() { return originalPositionReduce; }
// ==================== 运行时参数 ====================
@@ -383,6 +388,8 @@
private int addPositionStartThreshold = 1;
/** 超额止盈开关:true=挂单成交后将超出基础仓位的部分挂止盈单,默认 false */
private boolean placeExcessTakeProfit = false;
+ /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */
+ private int originalPositionReduce = 0;
/** 设置 API Key */
public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; }
@@ -446,6 +453,8 @@
public Builder addPositionStartThreshold(int addPositionStartThreshold) { this.addPositionStartThreshold = addPositionStartThreshold; return this; }
/** 设置超额止盈开关:true=挂单成交后将超出基础仓位的部分挂止盈单 */
public Builder placeExcessTakeProfit(boolean placeExcessTakeProfit) { this.placeExcessTakeProfit = placeExcessTakeProfit; return this; }
+ /** 设置原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长 */
+ public Builder originalPositionReduce(int originalPositionReduce) { this.originalPositionReduce = originalPositionReduce; 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 c083e4d..ed07e29 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java
@@ -77,6 +77,8 @@
private String longStopLossPrice;
/** 空头止损触发价 */
private String shortStopLossPrice;
+ /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */
+ private int originalPositionReduce;
/**
* 从 GateConfig 构建 DTO(不暴露 apiSecret)。
@@ -110,6 +112,7 @@
.maxPositionPerSide(config.getMaxPositionPerSide())
.addPositionStartThreshold(config.getAddPositionStartThreshold())
.placeExcessTakeProfit(config.isPlaceExcessTakeProfit())
+ .originalPositionReduce(config.getOriginalPositionReduce())
.build();
}
@@ -140,6 +143,7 @@
m.put("dualStopLossEnabled", dualStopLossEnabled);
m.put("longStopLossPrice", longStopLossPrice);
m.put("shortStopLossPrice", shortStopLossPrice);
+ m.put("originalPositionReduce", originalPositionReduce);
return m;
}
@@ -177,6 +181,7 @@
.dualStopLossEnabled(false)
.longStopLossPrice(null)
.shortStopLossPrice(null)
+ .originalPositionReduce(0)
.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 7f1a9e3..b552113 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
@@ -114,6 +114,7 @@
.maxPositionPerSide(dto.getMaxPositionPerSide())
.addPositionStartThreshold(dto.getAddPositionStartThreshold() >= 0 ? dto.getAddPositionStartThreshold() : 1)
.placeExcessTakeProfit(dto.isPlaceExcessTakeProfit())
+ .originalPositionReduce(dto.getOriginalPositionReduce() >= 0 ? dto.getOriginalPositionReduce() : 0)
.build();
}
diff --git a/src/main/java/com/xcong/excoin/modules/station/entity/StrategyStatus.java b/src/main/java/com/xcong/excoin/modules/station/entity/StrategyStatus.java
index 9245e57..76da82f 100644
--- a/src/main/java/com/xcong/excoin/modules/station/entity/StrategyStatus.java
+++ b/src/main/java/com/xcong/excoin/modules/station/entity/StrategyStatus.java
@@ -97,6 +97,9 @@
/** 原始仓位止盈总数量(平均分配到对手盘止损位前的所有网格,余数挂最后一格,每格至少1张) */
private Integer baseTakeProfitTotalQty;
+ /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */
+ private Integer originalPositionReduce;
+
/** 当前轮次 */
private Integer currentRound;
diff --git a/src/main/java/com/xcong/excoin/modules/station/service/impl/StationServiceImpl.java b/src/main/java/com/xcong/excoin/modules/station/service/impl/StationServiceImpl.java
index 13c562c..6333414 100644
--- a/src/main/java/com/xcong/excoin/modules/station/service/impl/StationServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/station/service/impl/StationServiceImpl.java
@@ -299,6 +299,7 @@
if (params.containsKey("tpTriggerOppositeAddQuantity")) status.setTpTriggerOppositeAddQuantity(intVal(params.get("tpTriggerOppositeAddQuantity")));
if (params.containsKey("tpPositionReplenishEnabled")) status.setTpPositionReplenishEnabled(boolVal(params.get("tpPositionReplenishEnabled")));
if (params.containsKey("baseTakeProfitTotalQty")) status.setBaseTakeProfitTotalQty(intVal(params.get("baseTakeProfitTotalQty")));
+ if (params.containsKey("originalPositionReduce")) status.setOriginalPositionReduce(intVal(params.get("originalPositionReduce")));
if (params.containsKey("rounds")) status.setTotalRounds(intVal(params.get("rounds")));
if (params.containsKey("principal")) status.setPrincipal(str(params.get("principal")));
}
diff --git a/src/main/resources/db/station-schema.sql b/src/main/resources/db/station-schema.sql
index 67ae672..e102efe 100644
--- a/src/main/resources/db/station-schema.sql
+++ b/src/main/resources/db/station-schema.sql
@@ -31,6 +31,7 @@
`tp_trigger_opposite_add_quantity` INT(11) DEFAULT 0 COMMENT '对向加仓挂单数量',
`tp_position_replenish_enabled` TINYINT(1) DEFAULT 0 COMMENT '仓位止盈补仓开关',
`base_take_profit_total_qty` INT(11) DEFAULT 0 COMMENT '原始仓位止盈总数量(平均分配到对手盘止损位前的所有网格,余数挂最后一格)',
+ `original_position_reduce` INT(11) DEFAULT 0 COMMENT '原始仓位减仓递减步长(0=关闭;>0=每次止损后追单量递减的步长)',
`current_round` INT(11) DEFAULT 0 COMMENT '当前轮次',
`total_rounds` INT(11) DEFAULT 0 COMMENT '总轮数上限',
`accumulated_long_loss` INT(11) DEFAULT 0 COMMENT '多头累计止损次数',
@@ -132,3 +133,10 @@
-- ============================================================
ALTER TABLE `strategy_status`
ADD COLUMN `add_position_stop_threshold` INT(11) DEFAULT 0 COMMENT '加仓停止阈值(0=不限制)' AFTER `add_position_start_threshold`;
+
+-- ============================================================
+-- 升级脚本:原始仓位减仓递减步长(2026-11 新增)
+-- 0=关闭;>0=每次止损后追单量递减的步长
+-- ============================================================
+ALTER TABLE `strategy_status`
+ ADD COLUMN `original_position_reduce` INT(11) DEFAULT 0 COMMENT '原始仓位减仓递减步长(0=关闭;>0=每次止损后追单量递减的步长)' AFTER `base_take_profit_total_qty`;
diff --git a/src/main/resources/static/gate-config.html b/src/main/resources/static/gate-config.html
index 319c8f3..c156438 100644
--- a/src/main/resources/static/gate-config.html
+++ b/src/main/resources/static/gate-config.html
@@ -133,6 +133,7 @@
<div class="form-group"><label>单边最大仓位量(张)</label><input id="maxPositionPerSide" type="number" placeholder="0(不限制)"></div>
<div class="form-group"><label>加仓启动阈值(次)</label><input id="addPositionStartThreshold" type="number" placeholder="1(前N次止损不加仓)"></div>
<div class="form-group"><label>超额止盈开关</label><select id="placeExcessTakeProfit"><option value="false" selected>关闭</option><option value="true">开启</option></select></div>
+ <div class="form-group"><label>原始仓位减仓(0=关闭)</label><input id="originalPositionReduce" type="number" placeholder="0"></div>
<!-- ===== 双开止损触发配置 ===== -->
<div class="form-group full" style="margin-top:6px;border-top:1px solid var(--border);padding-top:8px">
<label style="font-size:13px;font-weight:600;color:var(--text)">双开止损触发</label>
@@ -217,7 +218,7 @@
fillForm({ gridRate:0.005, expectedProfit:0.15, maxLoss:1.5,
baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2, priceDriveEnabled: true, rounds: 0,
stopLossCountMode:'dual', addPositionInterval:3, addPositionQuantity:1, maxPositionPerSide:0, addPositionStartThreshold:1, placeExcessTakeProfit: false,
- dualStopLossEnabled: false, longStopLossPrice: '', shortStopLossPrice: '' });
+ originalPositionReduce: 0, dualStopLossEnabled: false, longStopLossPrice: '', shortStopLossPrice: '' });
toast('未找到配置,已加载默认值,编辑后请保存', 'success');
}
currentApiKey = key;
@@ -243,6 +244,7 @@
byId('maxPositionPerSide').value = d.maxPositionPerSide ?? 0;
byId('addPositionStartThreshold').value = d.addPositionStartThreshold ?? 1;
byId('placeExcessTakeProfit').value = (d.placeExcessTakeProfit === true || d.placeExcessTakeProfit === 'true') ? 'true' : 'false';
+ byId('originalPositionReduce').value = d.originalPositionReduce ?? 0;
byId('dualStopLossEnabled').value = (d.dualStopLossEnabled === true || d.dualStopLossEnabled === 'true') ? 'true' : 'false';
byId('longStopLossPrice').value = d.longStopLossPrice || '';
byId('shortStopLossPrice').value = d.shortStopLossPrice || '';
@@ -267,6 +269,7 @@
maxPositionPerSide: intVal(byId('maxPositionPerSide').value, 0),
addPositionStartThreshold: intVal(byId('addPositionStartThreshold').value, 1),
placeExcessTakeProfit: byId('placeExcessTakeProfit').value === 'true',
+ originalPositionReduce: intVal(byId('originalPositionReduce').value, 0),
dualStopLossEnabled: byId('dualStopLossEnabled').value === 'true',
longStopLossPrice: byId('longStopLossPrice').value,
shortStopLossPrice: byId('shortStopLossPrice').value
diff --git a/src/main/resources/static/station-dashboard.html b/src/main/resources/static/station-dashboard.html
index df8b629..941b614 100644
--- a/src/main/resources/static/station-dashboard.html
+++ b/src/main/resources/static/station-dashboard.html
@@ -1099,6 +1099,7 @@
tpTriggerOppositeAddQuantity: 0,
tpPositionReplenishEnabled: false,
baseTakeProfitTotalQty: 0,
+ originalPositionReduce: 0,
};
async function loadConfig(md5) {
@@ -1143,6 +1144,7 @@
{ key: 'maxPositionPerSide', label: '单边最大仓位 (0=不限)', type: 'number', placeholder: '0', jtype: 'int', group: 'addon' },
{ key: 'addPositionStartThreshold', label: '加仓启动阈值 (次)', type: 'number', placeholder: '1', jtype: 'int', group: 'addon', tip: '前 N 次止损不触发加仓' },
{ key: 'addPositionStopThreshold', label: '加仓停止阈值 (次)', type: 'number', placeholder: '0', jtype: 'int', group: 'addon', tip: '启动加仓后累计次数超过该值时,加仓张数恢复为基础张数;0 = 不限制' },
+ { key: 'originalPositionReduce', label: '原始仓位减仓 (0=关闭)', type: 'number', placeholder: '0', jtype: 'int', group: 'addon', tip: '0=关闭;>0=每次止损后追单量递减的步长' },
{ key: 'tpTriggerOppositeAddEnabled', label: '止盈触发对向加仓', type: 'select', options: [{ v: 'false', l: '关闭' }, { v: 'true', l: '开启' }], group: 'addon', tip: '止盈单成交后触发对向加仓' },
{ key: 'tpTriggerOppositeAddQuantity', label: '对向加仓挂单数量 (张)', type: 'number', placeholder: '0', jtype: 'int', group: 'addon', tip: '止盈成交后在对向挂出的加仓张数' },
{ key: 'tpPositionReplenishEnabled', label: '仓位止盈补仓', type: 'select', options: [{ v: 'false', l: '关闭' }, { v: 'true', l: '开启' }], group: 'addon', tip: '开启后:任意方向止盈触发时,在对侧止损位挂相同张数、与止盈方向一致的开仓单(补回仓位);关闭:保持现有逻辑' },
--
Gitblit v1.9.1