From 6a1fcf0251b9e1ce063ceda7ebebe95649168fd3 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Fri, 17 Jul 2026 10:07:45 +0800
Subject: [PATCH] fix(gateApi): 解决网格交易止盈订单重复挂单问题
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 10 ++++++++--
1 files changed, 8 insertions(+), 2 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 4402a94..5249c57 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -675,9 +675,11 @@
for (int i = 0; i < shortTpCount; i++) {
int tpGridId = shortGridElement.getId() - 2 * (i + 1);
GridElement tpElem = GridElement.findById(tpGridId);
- if (tpElem == null || tpElem.getShortTakeProfitOrderId() != null) {
+ // 用 takeProfitPlaced 做同步标记,避免异步回调未执行时重复挂单
+ if (tpElem == null || tpElem.getShortTraderParam().isTakeProfitPlaced()) {
continue;
}
+ tpElem.getShortTraderParam().setTakeProfitPlaced(true);
BigDecimal tpPrice = tpElem.getGridPrice();
int finalTpGridId = tpGridId;
executor.placeTakeProfit(
@@ -741,9 +743,11 @@
for (int i = 0; i < longTpCount; i++) {
int tpGridId = longGridElement.getId() + 2 * (i + 1);
GridElement tpElem = GridElement.findById(tpGridId);
- if (tpElem == null || tpElem.getLongTakeProfitOrderId() != null) {
+ // 用 takeProfitPlaced 做同步标记,避免异步回调未执行时重复挂单
+ if (tpElem == null || tpElem.getLongTraderParam().isTakeProfitPlaced()) {
continue;
}
+ tpElem.getLongTraderParam().setTakeProfitPlaced(true);
BigDecimal tpPrice = tpElem.getGridPrice();
int finalTpGridId = tpGridId;
executor.placeTakeProfit(
@@ -1592,6 +1596,7 @@
for (GridElement e : config.getGridElements()) {
String tpId = e.getLongTakeProfitOrderId();
if (tpId != null) {
+ e.getLongTraderParam().setTakeProfitPlaced(false);
e.setLongTakeProfitOrderId(null);
executor.cancelConditionalOrder(tpId, oid -> {});
}
@@ -1611,6 +1616,7 @@
for (GridElement e : config.getGridElements()) {
String tpId = e.getShortTakeProfitOrderId();
if (tpId != null) {
+ e.getShortTraderParam().setTakeProfitPlaced(false);
e.setShortTakeProfitOrderId(null);
executor.cancelConditionalOrder(tpId, oid -> {});
}
--
Gitblit v1.9.1