From 286b64cef4127c2ca917561c474842c375d2ea73 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 07 May 2026 17:01:46 +0800
Subject: [PATCH] fix(gateApi): 设置初始订单为仅减仓模式

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |   54 +++++++++++-------------------------------------------
 1 files changed, 11 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
index 410b6e7..f58b68a 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -55,10 +55,6 @@
     private BigDecimal shortEntryPrice;
     private Long longOrderId;
     private Long shortOrderId;
-    private Long longTpOrderId;
-    private Long longSlOrderId;
-    private Long shortTpOrderId;
-    private Long shortSlOrderId;
 
     private volatile BigDecimal lastClosePrice;
 
@@ -128,10 +124,6 @@
      */
     public void stopGrid() {
         strategyActive = false;
-        cancelTpSl(longTpOrderId);
-        cancelTpSl(longSlOrderId);
-        cancelTpSl(shortTpOrderId);
-        cancelTpSl(shortSlOrderId);
         closeAllPositions();
         log.info("[GateGrid] 网格策略已停止, 总盈亏: {}, 循环: {}", totalProfit, currentCycle);
     }
@@ -188,22 +180,19 @@
 
     private void placeLongTpSl(BigDecimal entryPrice) {
         BigDecimal tpPrice = entryPrice.multiply(BigDecimal.ONE.add(gridRate)).setScale(1, RoundingMode.HALF_UP);
-        BigDecimal slPrice = entryPrice.multiply(BigDecimal.ONE.subtract(gridRate)).setScale(1, RoundingMode.HALF_UP);
-        longTpOrderId = placePriceTriggeredOrder(tpPrice, FuturesPriceTrigger.RuleEnum.NUMBER_1, "close_long");
-        longSlOrderId = placePriceTriggeredOrder(slPrice, FuturesPriceTrigger.RuleEnum.NUMBER_2, "close_long");
-        log.info("[GateGrid] 多头TP/SL已设置, TP:{}, SL:{}, tpId:{}, slId:{}", tpPrice, slPrice, longTpOrderId, longSlOrderId);
+        placePriceTriggeredOrder(tpPrice, FuturesPriceTrigger.RuleEnum.NUMBER_1, "close-long-position", "close_long");
+        log.info("[GateGrid] 多头止盈已设置, TP:{}", tpPrice);
     }
 
     private void placeShortTpSl(BigDecimal entryPrice) {
         BigDecimal tpPrice = entryPrice.multiply(BigDecimal.ONE.subtract(gridRate)).setScale(1, RoundingMode.HALF_UP);
-        BigDecimal slPrice = entryPrice.multiply(BigDecimal.ONE.add(gridRate)).setScale(1, RoundingMode.HALF_UP);
-        shortTpOrderId = placePriceTriggeredOrder(tpPrice, FuturesPriceTrigger.RuleEnum.NUMBER_2, "close_short");
-        shortSlOrderId = placePriceTriggeredOrder(slPrice, FuturesPriceTrigger.RuleEnum.NUMBER_1, "close_short");
-        log.info("[GateGrid] 空头TP/SL已设置, TP:{}, SL:{}, tpId:{}, slId:{}", tpPrice, slPrice, shortTpOrderId, shortSlOrderId);
+        placePriceTriggeredOrder(tpPrice, FuturesPriceTrigger.RuleEnum.NUMBER_2, "close-short-position", "close_short");
+        log.info("[GateGrid] 空头止盈已设置, TP:{}", tpPrice);
     }
 
-    private Long placePriceTriggeredOrder(BigDecimal triggerPrice,
+    private void placePriceTriggeredOrder(BigDecimal triggerPrice,
                                            FuturesPriceTrigger.RuleEnum rule,
+                                           String orderType,
                                            String autoSize) {
         try {
             FuturesPriceTrigger trigger = new FuturesPriceTrigger();
@@ -224,27 +213,14 @@
             FuturesPriceTriggeredOrder order = new FuturesPriceTriggeredOrder();
             order.setTrigger(trigger);
             order.setInitial(initial);
+            order.setOrderType(orderType);
 
             TriggerOrderResponse response = futuresApi.createPriceTriggeredOrder(SETTLE, order);
-            log.info("[GateGrid] 条件单已创建, triggerPrice:{}, rule:{}, autoSize:{}, id:{}",
-                    triggerPrice, rule, autoSize, response.getId());
-            return response.getId();
+            log.info("[GateGrid] 止盈条件单已创建, triggerPrice:{}, rule:{}, orderType:{}, autoSize:{}, id:{}",
+                    triggerPrice, rule, orderType, autoSize, response.getId());
         } catch (Exception e) {
-            log.error("[GateGrid] 创建条件单失败, triggerPrice:{}, rule:{}, autoSize:{}",
-                    triggerPrice, rule, autoSize, e);
-            return null;
-        }
-    }
-
-    private void cancelTpSl(Long orderId) {
-        if (orderId == null) {
-            return;
-        }
-        try {
-            futuresApi.cancelPriceTriggeredOrder(SETTLE, orderId);
-            log.info("[GateGrid] 已取消条件单, id:{}", orderId);
-        } catch (Exception e) {
-            log.warn("[GateGrid] 取消条件单失败, id:{}", orderId, e);
+            log.error("[GateGrid] 止盈条件单创建失败, triggerPrice:{}, rule:{}, orderType:{}, autoSize:{}",
+                    triggerPrice, rule, orderType, autoSize, e);
         }
     }
 
@@ -358,10 +334,6 @@
         }
         longEntryPrice = null;
         longOrderId = null;
-        cancelTpSl(longTpOrderId);
-        cancelTpSl(longSlOrderId);
-        longTpOrderId = null;
-        longSlOrderId = null;
     }
 
     private void closeShortPosition() {
@@ -383,10 +355,6 @@
         }
         shortEntryPrice = null;
         shortOrderId = null;
-        cancelTpSl(shortTpOrderId);
-        cancelTpSl(shortSlOrderId);
-        shortTpOrderId = null;
-        shortSlOrderId = null;
     }
 
     private void closeAllPositions() {

--
Gitblit v1.9.1