Administrator
2026-07-17 4d8c74156ee7e2c2bad2fbd04ed059cb5c0de6d3
fix(gateApi): 解决网格交易止盈订单重复挂单问题

- 使用 takeProfitPlaced 标记避免异步回调未执行时重复挂单
- 在止盈订单放置前设置同步标记为已放置状态
- 在取消止盈订单时重置同步标记为未放置状态
- 确保长短期止盈订单的状态标记同步处理
1 files modified
10 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 10 ●●●● patch | view | raw | blame | history
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 -> {});
            }