Administrator
2026-09-20 bec5d2437d131d51190ef639b2e4c776d2682391
refactor(gate): 重命名自定义止损相关字段以提高语义清晰度

- 将 customStopLossEnabled 重命名为 dualStopLossEnabled
- 将 longCustomStopLossPrice 重命名为 longStopLossPrice
- 将 shortCustomStopLossPrice 重命名为 shortStopLossPrice
- 更新前端HTML表单中的对应ID和默认值配置
- 更新Java实体类和构建器中的属性名称
- 更新配置持久化服务中的字段映射
- 更新交易服务中相关的变量和方法调用
5 files modified
96 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java 30 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java 24 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 16 ●●●●● patch | view | raw | blame | history
src/main/resources/static/gate-config.html 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -131,11 +131,11 @@
    /** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */
    private final String placeExcessTakeProfit;
    /** 自定义止损开关:true=启用自定义止损触发价(多空各挂一单),false=使用默认阶梯止损。默认 false */
    private final boolean customStopLossEnabled;
    private final boolean dualStopLossEnabled;
    /** 多仓自定义止损触发价(价格跌至该值触发平多),null/0=未设置 */
    private final BigDecimal longCustomStopLossPrice;
    private final BigDecimal longStopLossPrice;
    /** 空仓自定义止损触发价(价格涨至该值触发平空),null/0=未设置 */
    private final BigDecimal shortCustomStopLossPrice;
    private final BigDecimal shortStopLossPrice;
    /** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */
    private BigDecimal step;
    /** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */
@@ -177,9 +177,9 @@
        this.maxPositionPerSide = builder.maxPositionPerSide;
        this.addPositionStartThreshold = builder.addPositionStartThreshold;
        this.placeExcessTakeProfit = builder.placeExcessTakeProfit;
        this.customStopLossEnabled = builder.customStopLossEnabled;
        this.longCustomStopLossPrice = builder.longCustomStopLossPrice;
        this.shortCustomStopLossPrice = builder.shortCustomStopLossPrice;
        this.dualStopLossEnabled = builder.dualStopLossEnabled;
        this.longStopLossPrice = builder.longStopLossPrice;
        this.shortStopLossPrice = builder.shortStopLossPrice;
    }
    // ==================== REST/WS 地址 ====================
@@ -288,11 +288,11 @@
    /** @return 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈 */
    public String getPlaceExcessTakeProfit() { return placeExcessTakeProfit; }
    /** @return 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损 */
    public boolean isCustomStopLossEnabled() { return customStopLossEnabled; }
    public boolean isDualStopLossEnabled() { return dualStopLossEnabled; }
    /** @return 多仓自定义止损触发价,null/0=未设置 */
    public BigDecimal getLongCustomStopLossPrice() { return longCustomStopLossPrice; }
    public BigDecimal getLongStopLossPrice() { return longStopLossPrice; }
    /** @return 空仓自定义止损触发价,null/0=未设置 */
    public BigDecimal getShortCustomStopLossPrice() { return shortCustomStopLossPrice; }
    public BigDecimal getShortStopLossPrice() { return shortStopLossPrice; }
    // ==================== 运行时参数 ====================
@@ -406,11 +406,11 @@
        /** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */
        private String placeExcessTakeProfit = EXCESS_TP_OFF;
        /** 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损。默认 false */
        private boolean customStopLossEnabled = false;
        private boolean dualStopLossEnabled = false;
        /** 多仓自定义止损触发价,null=未设置 */
        private BigDecimal longCustomStopLossPrice;
        private BigDecimal longStopLossPrice;
        /** 空仓自定义止损触发价,null=未设置 */
        private BigDecimal shortCustomStopLossPrice;
        private BigDecimal shortStopLossPrice;
        /** 设置 API Key */
        public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; }
@@ -475,11 +475,11 @@
        /** 设置止盈挂单模式:off / concentrated / dispersed */
        public Builder placeExcessTakeProfit(String placeExcessTakeProfit) { this.placeExcessTakeProfit = placeExcessTakeProfit; return this; }
        /** 设置自定义止损开关:true=启用自定义止损触发价 */
        public Builder customStopLossEnabled(boolean customStopLossEnabled) { this.customStopLossEnabled = customStopLossEnabled; return this; }
        public Builder dualStopLossEnabled(boolean dualStopLossEnabled) { this.dualStopLossEnabled = dualStopLossEnabled; return this; }
        /** 设置多仓自定义止损触发价 */
        public Builder longCustomStopLossPrice(BigDecimal longCustomStopLossPrice) { this.longCustomStopLossPrice = longCustomStopLossPrice; return this; }
        public Builder longStopLossPrice(BigDecimal longStopLossPrice) { this.longStopLossPrice = longStopLossPrice; return this; }
        /** 设置空仓自定义止损触发价 */
        public Builder shortCustomStopLossPrice(BigDecimal shortCustomStopLossPrice) { this.shortCustomStopLossPrice = shortCustomStopLossPrice; return this; }
        public Builder shortStopLossPrice(BigDecimal shortStopLossPrice) { this.shortStopLossPrice = shortStopLossPrice; return this; }
        public GateConfig build() {
            return new GateConfig(this);
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigDTO.java
@@ -72,11 +72,11 @@
    /** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */
    private String placeExcessTakeProfit;
    /** 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损。null=未设置(默认false) */
    private Boolean customStopLossEnabled;
    private Boolean dualStopLossEnabled;
    /** 多仓自定义止损触发价(价格跌至该值触发平多),null=未设置 */
    private BigDecimal longCustomStopLossPrice;
    private BigDecimal longStopLossPrice;
    /** 空仓自定义止损触发价(价格涨至该值触发平空),null=未设置 */
    private BigDecimal shortCustomStopLossPrice;
    private BigDecimal shortStopLossPrice;
    /**
     * 从 GateConfig 构建 DTO(不暴露 apiSecret)。
@@ -110,9 +110,9 @@
                .maxPositionPerSide(config.getMaxPositionPerSide())
                .addPositionStartThreshold(config.getAddPositionStartThreshold())
                .placeExcessTakeProfit(config.getPlaceExcessTakeProfit())
                .customStopLossEnabled(config.isCustomStopLossEnabled())
                .longCustomStopLossPrice(config.getLongCustomStopLossPrice())
                .shortCustomStopLossPrice(config.getShortCustomStopLossPrice())
                .dualStopLossEnabled(config.isDualStopLossEnabled())
                .longStopLossPrice(config.getLongStopLossPrice())
                .shortStopLossPrice(config.getShortStopLossPrice())
                .build();
    }
@@ -140,9 +140,9 @@
        m.put("maxPositionPerSide", maxPositionPerSide);
        m.put("addPositionStartThreshold", addPositionStartThreshold);
        m.put("placeExcessTakeProfit", placeExcessTakeProfit);
        m.put("customStopLossEnabled", customStopLossEnabled);
        m.put("longCustomStopLossPrice", longCustomStopLossPrice);
        m.put("shortCustomStopLossPrice", shortCustomStopLossPrice);
        m.put("dualStopLossEnabled", dualStopLossEnabled);
        m.put("longStopLossPrice", longStopLossPrice);
        m.put("shortStopLossPrice", shortStopLossPrice);
        return m;
    }
@@ -177,9 +177,9 @@
                .maxPositionPerSide(0)
                .addPositionStartThreshold(1)
                .placeExcessTakeProfit("off")
                .customStopLossEnabled(false)
                .longCustomStopLossPrice(null)
                .shortCustomStopLossPrice(null)
                .dualStopLossEnabled(false)
                .longStopLossPrice(null)
                .shortStopLossPrice(null)
                .build();
    }
}
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
@@ -112,9 +112,9 @@
                .maxPositionPerSide(dto.getMaxPositionPerSide())
                .addPositionStartThreshold(dto.getAddPositionStartThreshold() >= 0 ? dto.getAddPositionStartThreshold() : 1)
                .placeExcessTakeProfit(normalizeTakeProfitMode(dto.getPlaceExcessTakeProfit()))
                .customStopLossEnabled(nvl(dto.getCustomStopLossEnabled(), false))
                .longCustomStopLossPrice(dto.getLongCustomStopLossPrice())
                .shortCustomStopLossPrice(dto.getShortCustomStopLossPrice())
                .dualStopLossEnabled(nvl(dto.getDualStopLossEnabled(), false))
                .longStopLossPrice(dto.getLongStopLossPrice())
                .shortStopLossPrice(dto.getShortStopLossPrice())
                .build();
    }
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -150,7 +150,7 @@
    /** 最近触发止损的空头网格ID */
    private volatile int lastShortStopLossGridId = Integer.MAX_VALUE;
    /** 自定义止损模式激活标记:true=尚未发生第一次止损触发,第一次触发后置 false(触发未触发侧重挂默认) */
    private final AtomicBoolean customStopLossModeActive = new AtomicBoolean(false);
    private final AtomicBoolean dualStopLossModeActive = new AtomicBoolean(false);
    private volatile BigDecimal lastKlinePrice;
    private volatile BigDecimal markPrice = BigDecimal.ZERO;
@@ -365,7 +365,7 @@
        accumulatedShortLossCount = 0;
        lastLongStopLossGridId = Integer.MAX_VALUE;
        lastShortStopLossGridId = Integer.MAX_VALUE;
        customStopLossModeActive.set(false);
        dualStopLossModeActive.set(false);
        shortPriceQueue.clear();
        longPriceQueue.clear();
        totalShortPriceQueue.clear();
@@ -978,7 +978,7 @@
//                );
//            }
            if (config.isCustomStopLossEnabled()) {
            if (config.isDualStopLossEnabled()) {
                placeCustomStopLosses();
            } else {
                placeDefaultStopLossLadders();
@@ -995,10 +995,10 @@
     * 多仓止损:NUMBER_2(价格 ≤ 触发价平多),空仓止损:NUMBER_1(价格 ≥ 触发价平空)。
     */
    private void placeCustomStopLosses() {
        customStopLossModeActive.set(true);
        dualStopLossModeActive.set(true);
        String baseQty = config.getBaseQuantity();
        BigDecimal longPrice = config.getLongCustomStopLossPrice();
        BigDecimal shortPrice = config.getShortCustomStopLossPrice();
        BigDecimal longPrice = config.getLongStopLossPrice();
        BigDecimal shortPrice = config.getShortStopLossPrice();
        if (longPrice != null && longPrice.compareTo(BigDecimal.ZERO) > 0) {
            GridElement longElem = findNearestGridElementByPrice(longPrice);
@@ -1654,7 +1654,7 @@
        }
        // 自定义止损模式:第一次止损触发时,取消未触发侧(空仓)自定义止损单并重挂默认阶梯
        if (config.isCustomStopLossEnabled() && customStopLossModeActive.compareAndSet(true, false)) {
        if (config.isDualStopLossEnabled() && dualStopLossModeActive.compareAndSet(true, false)) {
            cancelAllShortStopLossesOnly();
            placeDefaultShortStopLossLadder();
            log.info("[Gate] 自定义止损首次触发(多仓), 已取消空仓自定义止损并重挂默认阶梯");
@@ -1713,7 +1713,7 @@
        }
        // 自定义止损模式:第一次止损触发时,取消未触发侧(多仓)自定义止损单并重挂默认阶梯
        if (config.isCustomStopLossEnabled() && customStopLossModeActive.compareAndSet(true, false)) {
        if (config.isDualStopLossEnabled() && dualStopLossModeActive.compareAndSet(true, false)) {
            cancelAllLongStopLossesOnly();
            placeDefaultLongStopLossLadder();
            log.info("[Gate] 自定义止损首次触发(空仓), 已取消多仓自定义止损并重挂默认阶梯");
src/main/resources/static/gate-config.html
@@ -137,9 +137,9 @@
            <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>
            </div>
            <div class="form-group"><label>自定义止损开关</label><select id="customStopLossEnabled"><option value="false" selected>关闭</option><option value="true">开启</option></select></div>
            <div class="form-group"><label>多仓止损触发价</label><input id="longCustomStopLossPrice" placeholder="如 2540(价格跌至触发平多)"></div>
            <div class="form-group"><label>空仓止损触发价</label><input id="shortCustomStopLossPrice" placeholder="如 2650(价格涨至触发平空)"></div>
            <div class="form-group"><label>自定义止损开关</label><select id="dualStopLossEnabled"><option value="false" selected>关闭</option><option value="true">开启</option></select></div>
            <div class="form-group"><label>多仓止损触发价</label><input id="longStopLossPrice" placeholder="如 2540(价格跌至触发平多)"></div>
            <div class="form-group"><label>空仓止损触发价</label><input id="shortStopLossPrice" placeholder="如 2650(价格涨至触发平空)"></div>
        </form>
    </div>
@@ -217,7 +217,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: 'off',
            customStopLossEnabled: false, longCustomStopLossPrice: null, shortCustomStopLossPrice: null });
            dualStopLossEnabled: false, longStopLossPrice: null, shortStopLossPrice: null });
        toast('未找到配置,已加载默认值,编辑后请保存', 'success');
    }
    currentApiKey = key;
@@ -243,9 +243,9 @@
    byId('maxPositionPerSide').value = d.maxPositionPerSide ?? 0;
    byId('addPositionStartThreshold').value = d.addPositionStartThreshold ?? 1;
    byId('placeExcessTakeProfit').value = normalizeTpMode(d.placeExcessTakeProfit);
    byId('customStopLossEnabled').value = (d.customStopLossEnabled === true || d.customStopLossEnabled === 'true') ? 'true' : 'false';
    byId('longCustomStopLossPrice').value = d.longCustomStopLossPrice || '';
    byId('shortCustomStopLossPrice').value = d.shortCustomStopLossPrice || '';
    byId('dualStopLossEnabled').value = (d.dualStopLossEnabled === true || d.dualStopLossEnabled === 'true') ? 'true' : 'false';
    byId('longStopLossPrice').value = d.longStopLossPrice || '';
    byId('shortStopLossPrice').value = d.shortStopLossPrice || '';
}
function collectForm() {
@@ -267,9 +267,9 @@
        maxPositionPerSide: intVal(byId('maxPositionPerSide').value, 0),
        addPositionStartThreshold: intVal(byId('addPositionStartThreshold').value, 1),
        placeExcessTakeProfit: byId('placeExcessTakeProfit').value,
        customStopLossEnabled: byId('customStopLossEnabled').value === 'true',
        longCustomStopLossPrice: parseFloat(byId('longCustomStopLossPrice').value) || null,
        shortCustomStopLossPrice: parseFloat(byId('shortCustomStopLossPrice').value) || null
        dualStopLossEnabled: byId('dualStopLossEnabled').value === 'true',
        longStopLossPrice: parseFloat(byId('longStopLossPrice').value) || null,
        shortStopLossPrice: parseFloat(byId('shortStopLossPrice').value) || null
    };
}
function intVal(str, fallback) {