feat(config): 添加原始仓位减仓递减步长配置
- 在 GateConfig 与 StrategyStatus 实体中新增 originalPositionReduce 字段
- 更新 GateConfigDTO 以支持新字段的构建与字典转换
- 在前端 gate-config 与 station-dashboard 页面新增配置输入控件
- 在 station-schema 脚本中新增数据库字段定义与升级 ALTER 语句
- 更新 StationServiceImpl 与持久化服务以解析和保存该配置参数
| | |
| | | private final int addPositionStartThreshold; |
| | | /** 超额止盈开关:true=挂单成交后将超出基础仓位的部分挂止盈单(挂在对手第一止损位),默认 false */ |
| | | private final boolean placeExcessTakeProfit; |
| | | /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */ |
| | | private final int originalPositionReduce; |
| | | /** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */ |
| | | private BigDecimal step; |
| | | /** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */ |
| | |
| | | this.maxPositionPerSide = builder.maxPositionPerSide; |
| | | this.addPositionStartThreshold = builder.addPositionStartThreshold; |
| | | this.placeExcessTakeProfit = builder.placeExcessTakeProfit; |
| | | this.originalPositionReduce = builder.originalPositionReduce; |
| | | } |
| | | |
| | | // ==================== REST/WS 地址 ==================== |
| | |
| | | public int getAddPositionStartThreshold() { return addPositionStartThreshold; } |
| | | /** @return 超额止盈开关:true=挂单成交后将超出基础仓位的部分挂止盈单 */ |
| | | public boolean isPlaceExcessTakeProfit() { return placeExcessTakeProfit; } |
| | | /** @return 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长 */ |
| | | public int getOriginalPositionReduce() { return originalPositionReduce; } |
| | | |
| | | // ==================== 运行时参数 ==================== |
| | | |
| | |
| | | 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; } |
| | |
| | | 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); |
| | |
| | | private String longStopLossPrice; |
| | | /** 空头止损触发价 */ |
| | | private String shortStopLossPrice; |
| | | /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */ |
| | | private int originalPositionReduce; |
| | | |
| | | /** |
| | | * 从 GateConfig 构建 DTO(不暴露 apiSecret)。 |
| | |
| | | .maxPositionPerSide(config.getMaxPositionPerSide()) |
| | | .addPositionStartThreshold(config.getAddPositionStartThreshold()) |
| | | .placeExcessTakeProfit(config.isPlaceExcessTakeProfit()) |
| | | .originalPositionReduce(config.getOriginalPositionReduce()) |
| | | .build(); |
| | | } |
| | | |
| | |
| | | m.put("dualStopLossEnabled", dualStopLossEnabled); |
| | | m.put("longStopLossPrice", longStopLossPrice); |
| | | m.put("shortStopLossPrice", shortStopLossPrice); |
| | | m.put("originalPositionReduce", originalPositionReduce); |
| | | return m; |
| | | } |
| | | |
| | |
| | | .dualStopLossEnabled(false) |
| | | .longStopLossPrice(null) |
| | | .shortStopLossPrice(null) |
| | | .originalPositionReduce(0) |
| | | .build(); |
| | | } |
| | | } |
| | |
| | | .maxPositionPerSide(dto.getMaxPositionPerSide()) |
| | | .addPositionStartThreshold(dto.getAddPositionStartThreshold() >= 0 ? dto.getAddPositionStartThreshold() : 1) |
| | | .placeExcessTakeProfit(dto.isPlaceExcessTakeProfit()) |
| | | .originalPositionReduce(dto.getOriginalPositionReduce() >= 0 ? dto.getOriginalPositionReduce() : 0) |
| | | .build(); |
| | | } |
| | | |
| | |
| | | /** 原始仓位止盈总数量(平均分配到对手盘止损位前的所有网格,余数挂最后一格,每格至少1张) */ |
| | | private Integer baseTakeProfitTotalQty; |
| | | |
| | | /** 原始仓位减仓递减步长:0=关闭,>0=每次止损后追单量递减的步长,默认 0 */ |
| | | private Integer originalPositionReduce; |
| | | |
| | | /** 当前轮次 */ |
| | | private Integer currentRound; |
| | | |
| | |
| | | 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"))); |
| | | } |
| | |
| | | `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 '多头累计止损次数', |
| | |
| | | -- ============================================================ |
| | | 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`; |
| | |
| | | <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> |
| | |
| | | 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; |
| | |
| | | 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 || ''; |
| | |
| | | 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 |
| | |
| | | tpTriggerOppositeAddQuantity: 0, |
| | | tpPositionReplenishEnabled: false, |
| | | baseTakeProfitTotalQty: 0, |
| | | originalPositionReduce: 0, |
| | | }; |
| | | |
| | | async function loadConfig(md5) { |
| | |
| | | { 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: '开启后:任意方向止盈触发时,在对侧止损位挂相同张数、与止盈方向一致的开仓单(补回仓位);关闭:保持现有逻辑' }, |