From 652f81a7b5c2bc12263cc32541f2250079699f4f Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 21 May 2026 22:01:11 +0800
Subject: [PATCH] fix(gateApi): 修复网格交易服务中的订单更新处理逻辑
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 74 ++++++++++++++++++++++++++-----------
1 files changed, 52 insertions(+), 22 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 4fd0216..0559f92 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -342,6 +342,16 @@
lastKlinePrice = closePrice;
updateUnrealizedPnl();
if (state == StrategyState.STOPPED) {
+ try {
+ futuresApi.cancelPriceTriggeredOrderList(SETTLE, config.getContract());
+ } catch (ApiException e) {
+ e.printStackTrace();
+ }
+ closeExistingPositions();
+
+ BigDecimal totalPnl = cumulativePnl.add(unrealizedPnl);
+ log.info("[Gate] 已实现:{}, 未实现:{}, 合计:{}",
+ cumulativePnl, unrealizedPnl, totalPnl);
return;
}
@@ -518,8 +528,8 @@
}
cumulativePnl = cumulativePnl.add(pnl);
BigDecimal totalPnl = cumulativePnl.add(unrealizedPnl);
- log.info("[Gate] 盈亏累加:{}, 方向:{}, 已实现:{}, 未实现:{}, 合计:{}",
- pnl, side, cumulativePnl, unrealizedPnl, totalPnl);
+ log.info("[Gate] 已实现:{}, 未实现:{}, 合计:{}",
+ cumulativePnl, unrealizedPnl, totalPnl);
if (totalPnl.compareTo(config.getOverallTp()) >= 0) {
log.info("[Gate] 已达止盈目标(合计{})→已停止, 已实现:{}, 未实现:{}",
@@ -561,11 +571,11 @@
null,
false
);
- longEntryTraderIdParam(
- byLongTakeProfitOrderId,
- null,
- false
- );
+// longEntryTraderIdParam(
+// byLongTakeProfitOrderId,
+// null,
+// false
+// );
}
GridElement byShortTakeProfitOrderId = GridElement.findByShortTakeProfitOrderId(orderId);
if (byShortTakeProfitOrderId != null){
@@ -574,11 +584,11 @@
null,
false
);
- shortEntryTraderIdParam(
- byShortTakeProfitOrderId,
- null,
- false
- );
+// shortEntryTraderIdParam(
+// byShortTakeProfitOrderId,
+// null,
+// false
+// );
}
/**
@@ -587,6 +597,11 @@
GridElement longGridElement = GridElement.findByLongOrderId(orderId);
if (longGridElement != null) {
if (longGridElement.isHasLongOrder()){
+ longEntryTraderIdParam(
+ longGridElement,
+ null,
+ false
+ );
if (longGridElement.getLongTakeProfitOrderId() == null){
BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
if (longTp != null) {
@@ -610,6 +625,11 @@
GridElement shortGridElement = GridElement.findByShortOrderId(orderId);
if (shortGridElement != null) {
if (shortGridElement.isHasShortOrder()){
+ shortEntryTraderIdParam(
+ shortGridElement,
+ null,
+ false
+ );
if (shortGridElement.getShortTakeProfitOrderId() == null){
BigDecimal shortTp = shortGridElement.getShortTraderParam().getTakeProfitPrice();
if (shortTp != null) {
@@ -680,11 +700,11 @@
null,
false
);
- longEntryTraderIdParam(
- byLongTakeProfitOrderId,
- null,
- false
- );
+// longEntryTraderIdParam(
+// byLongTakeProfitOrderId,
+// null,
+// false
+// );
}
GridElement byShortTakeProfitOrderId = GridElement.findByShortTakeProfitOrderId(orderId);
if (byShortTakeProfitOrderId != null){
@@ -693,11 +713,11 @@
null,
false
);
- shortEntryTraderIdParam(
- byShortTakeProfitOrderId,
- null,
- false
- );
+// shortEntryTraderIdParam(
+// byShortTakeProfitOrderId,
+// null,
+// false
+// );
}
/**
@@ -706,6 +726,11 @@
GridElement longGridElement = GridElement.findByLongOrderId(orderId);
if (longGridElement != null) {
if (longGridElement.isHasLongOrder() && !tradeId.equals("0")){
+ longEntryTraderIdParam(
+ longGridElement,
+ null,
+ false
+ );
if (longGridElement.getLongTakeProfitOrderId() == null){
BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
if (longTp != null) {
@@ -729,6 +754,11 @@
GridElement shortGridElement = GridElement.findByShortOrderId(orderId);
if (shortGridElement != null) {
if (shortGridElement.isHasShortOrder() && !tradeId.equals("0")){
+ shortEntryTraderIdParam(
+ shortGridElement,
+ null,
+ false
+ );
if (shortGridElement.getShortTakeProfitOrderId() == null){
BigDecimal shortTp = shortGridElement.getShortTraderParam().getTakeProfitPrice();
if (shortTp != null) {
--
Gitblit v1.9.1