From 0056bdee025f108f38b2c493e01cfa80d2b22c59 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 20 May 2026 22:21:08 +0800
Subject: [PATCH] feat(gateApi): 添加交易ID参数支持自动订单处理

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 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 88a5545..b3354d1 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -421,7 +421,7 @@
                     List<GridElement> allShortOrders = GridElement.findAllShortOrders(longEntryPrice);
                     if (CollUtil.isNotEmpty(allShortOrders)){
                         for (GridElement e : allShortOrders) {
-                            executor.cancelOrder(
+                            executor.cancelConditionalOrder(
                                     e.getShortOrderId(),
                                     orderId -> {
                                         shortEntryTraderIdParam(
@@ -431,6 +431,19 @@
                                         );
                                     }
                             );
+
+                            if (e.getShortTakeProfitOrderId() != null){
+                                executor.cancelConditionalOrder(
+                                        e.getShortTakeProfitOrderId(),
+                                        orderId -> {
+                                            shortTakeProfitTraderIdParam(
+                                                    e,
+                                                    null,
+                                                    false
+                                            );
+                                        }
+                                );
+                            }
                         }
                     }
                 }
@@ -454,16 +467,28 @@
                     List<GridElement> allLongOrders = GridElement.findAllLongOrders(shortEntryPrice);
                     if (CollUtil.isNotEmpty(allLongOrders)){
                         for (GridElement e : allLongOrders) {
-                            executor.cancelOrder(
+                            executor.cancelConditionalOrder(
                                     e.getLongOrderId(),
                                     orderId -> {
-                                        shortEntryTraderIdParam(
+                                        longEntryTraderIdParam(
                                                 e,
                                                 null,
                                                 false
                                         );
                                     }
                             );
+                            if (e.getLongTakeProfitOrderId() != null){
+                                executor.cancelConditionalOrder(
+                                        e.getLongTakeProfitOrderId(),
+                                        orderId -> {
+                                            longTakeProfitTraderIdParam(
+                                                    e,
+                                                    null,
+                                                    false
+                                            );
+                                        }
+                                );
+                            }
                         }
                     }
                 }
@@ -631,7 +656,7 @@
      * @param reason    变更原因
      * @param orderType 订单类型(plan-close-long-position 等)
      */
-    public void onAutoOrder(String orderId, String status, String reason, String orderType) {
+    public void onAutoOrder(String orderId, String status, String reason, String orderType, String tradeId) {
         if (state == StrategyState.STOPPED) {
             return;
         }
@@ -676,7 +701,7 @@
          */
         GridElement longGridElement = GridElement.findByLongOrderId(orderId);
         if (longGridElement != null) {
-            if (longGridElement.isHasLongOrder()){
+            if (longGridElement.isHasLongOrder() && !tradeId.equals("0")){
                 if (longGridElement.getLongTakeProfitOrderId() == null){
                     BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
                     if (longTp != null) {
@@ -699,7 +724,7 @@
         }
         GridElement shortGridElement = GridElement.findByShortOrderId(orderId);
         if (shortGridElement != null) {
-            if (shortGridElement.isHasShortOrder()){
+            if (shortGridElement.isHasShortOrder() && !tradeId.equals("0")){
                 if (shortGridElement.getShortTakeProfitOrderId() == null){
                     BigDecimal shortTp = shortGridElement.getShortTraderParam().getTakeProfitPrice();
                     if (shortTp != null) {

--
Gitblit v1.9.1