From b628b1f5dc30923c68ea397b715b5a9771423cc8 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sun, 20 Sep 2026 14:49:49 +0800
Subject: [PATCH] feat(gate): 添加自定义止损功能

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

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 0ceb025..3e45a95 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
@@ -93,7 +93,7 @@
                 .priceScale(GateWebSocketClientManager.DEFAULT_PRICE_SCALE)
                 .contractMultiplier(new BigDecimal(GateWebSocketClientManager.DEFAULT_CONTRACT_MULTIPLIER))
                 .unrealizedPnlPriceMode(GateConfig.PnLPriceMode.valueOf(GateWebSocketClientManager.DEFAULT_PNL_MODE))
-                .isProduction(true)
+                .isProduction(false)
                 .reopenMaxRetries(GateWebSocketClientManager.DEFAULT_REOPEN_MAX_RETRIES)
                 // 可调参数 — 从 DTO 读取
                 .gridRate(nvl(dto.getGridRate(), new BigDecimal("0.005")))
@@ -111,7 +111,10 @@
                 .addPositionQuantity(dto.getAddPositionQuantity() > 0 ? dto.getAddPositionQuantity() : 1)
                 .maxPositionPerSide(dto.getMaxPositionPerSide())
                 .addPositionStartThreshold(dto.getAddPositionStartThreshold() >= 0 ? dto.getAddPositionStartThreshold() : 1)
-                .placeExcessTakeProfit(dto.isPlaceExcessTakeProfit())
+                .placeExcessTakeProfit(normalizeTakeProfitMode(dto.getPlaceExcessTakeProfit()))
+                .customStopLossEnabled(nvl(dto.getCustomStopLossEnabled(), false))
+                .longCustomStopLossPrice(dto.getLongCustomStopLossPrice())
+                .shortCustomStopLossPrice(dto.getShortCustomStopLossPrice())
                 .build();
     }
 
@@ -141,4 +144,22 @@
     private static <T> T nvl(T value, T fallback) {
         return value != null ? value : fallback;
     }
+
+    /**
+     * 归一化止盈挂单模式,兼容旧版 boolean 配置(旧 JSON 的 true/false 会被 Jackson 反序列化为字符串)。
+     */
+    private static String normalizeTakeProfitMode(String raw) {
+        if (raw == null || raw.trim().isEmpty()) {
+            return GateConfig.EXCESS_TP_OFF;
+        }
+        switch (raw.trim()) {
+            case "true":
+            case "concentrated":
+                return GateConfig.EXCESS_TP_CONCENTRATED;
+            case "dispersed":
+                return GateConfig.EXCESS_TP_DISPERSED;
+            default:
+                return GateConfig.EXCESS_TP_OFF;
+        }
+    }
 }

--
Gitblit v1.9.1