Administrator
2026-05-19 7491d19c0412712080f23c389eb2f1bfa2924e09
```
fix(gate): 修复网格交易中订单状态更新处理逻辑

- 添加条件判断只处理完成状态的订单
- 实现止盈单匹配逻辑处理多单和空单的止盈订单
- 添加网格元素查找和止盈价格设置功能
- 注释掉WebSocket订单更新回调避免重复处理
- 完善订单成交后的止盈单创建和参数设置流程
```
2 files modified
88 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 82 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/OrdersChannelHandler.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -635,6 +635,88 @@
        }
        log.info("[Gate] 条件单状态变更, id:{}, status:{}, reason:{}, order_type:{}",
                orderId, status, reason, orderType);
        if (!"finished".equals(status)) {
            return;
        }
        /**
         * 匹配止盈单止盈
         */
        GridElement byLongTakeProfitOrderId = GridElement.findByLongTakeProfitOrderId(orderId);
        if (byLongTakeProfitOrderId != null){
            longTakeProfitTraderIdParam(
                    byLongTakeProfitOrderId,
                    null,
                    false
            );
            longEntryTraderIdParam(
                    byLongTakeProfitOrderId,
                    null,
                    false
            );
        }
        GridElement byShortTakeProfitOrderId = GridElement.findByShortTakeProfitOrderId(orderId);
        if (byShortTakeProfitOrderId != null){
            shortTakeProfitTraderIdParam(
                    byShortTakeProfitOrderId,
                    null,
                    false
            );
            shortEntryTraderIdParam(
                    byShortTakeProfitOrderId,
                    null,
                    false
            );
        }
        /**
         * 匹配挂单
         */
        GridElement longGridElement = GridElement.findByLongOrderId(orderId);
        if (longGridElement != null) {
            if (longGridElement.isHasLongOrder()){
                if (longGridElement.getLongTakeProfitOrderId() == null){
                    BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
                    if (longTp != null) {
                        executor.placeTakeProfit(longTp,
                                FuturesPriceTrigger.RuleEnum.NUMBER_1,
                                ORDER_TYPE_CLOSE_LONG,
                                negate(config.getQuantity()),
                                (profitId) -> {
                                    longTakeProfitTraderIdParam(
                                            longGridElement,
                                            profitId,
                                            true
                                    );
                                });
                        log.info("[Gate] 多单成交匹配止盈, orderId:{}, 止盈价:{}, size:{}", orderId, longTp, negate(config.getQuantity()));
                        return;
                    }
                }
            }
        }
        GridElement shortGridElement = GridElement.findByShortOrderId(orderId);
        if (shortGridElement != null) {
            if (shortGridElement.isHasShortOrder()){
                if (shortGridElement.getShortTakeProfitOrderId() == null){
                    BigDecimal shortTp = shortGridElement.getShortTraderParam().getTakeProfitPrice();
                    if (shortTp != null) {
                        executor.placeTakeProfit(shortTp,
                                FuturesPriceTrigger.RuleEnum.NUMBER_2,
                                ORDER_TYPE_CLOSE_SHORT,
                                config.getQuantity(),
                                (profitId) -> {
                                    shortTakeProfitTraderIdParam(
                                            shortGridElement,
                                            profitId,
                                            true
                                    );
                                });
                        log.info("[Gate] 空单成交匹配止盈, orderId:{}, 止盈价:{}, size:{}", orderId, shortTp, config.getQuantity());
                    }
                }
            }
        }
    }
    // ---- 网格队列处理 ----
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/OrdersChannelHandler.java
@@ -61,9 +61,9 @@
                log.info("[{}] 订单更新, id:{}, status:{}, finish_as:{}, price:{}, size:{},update_id:{}",
                        CHANNEL_NAME, orderId, status, finishAs,
                        order.get("price"), order.get("size"),updateId);
                if (getGridTradeService() != null) {
                    getGridTradeService().onOrderUpdate(orderId, status, finishAs);
                }
//                if (getGridTradeService() != null) {
//                    getGridTradeService().onOrderUpdate(orderId, status, finishAs);
//                }
            }
        } catch (Exception e) {
            log.error("[{}] 处理数据失败", CHANNEL_NAME, e);