Administrator
2026-05-20 0056bdee025f108f38b2c493e01cfa80d2b22c59
feat(gateApi): 添加交易ID参数支持自动订单处理

- 在AutoOrdersChannelHandler中添加trade_id字段解析和传递
- 更新GateGridTradeService中的onAutoOrder方法签名以接收tradeId参数
- 添加对做空止盈订单的取消逻辑处理
- 添加对做多止盈订单的取消逻辑处理
- 在订单状态更新时验证tradeId不为"0"才执行止盈订单创建
- 修复长订单和短订单的止盈参数设置方法调用错误
2 files modified
38 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 33 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/AutoOrdersChannelHandler.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -431,6 +431,19 @@
                                        );
                                    }
                            );
                            if (e.getShortTakeProfitOrderId() != null){
                                executor.cancelConditionalOrder(
                                        e.getShortTakeProfitOrderId(),
                                        orderId -> {
                                            shortTakeProfitTraderIdParam(
                                                    e,
                                                    null,
                                                    false
                                            );
                                        }
                                );
                            }
                        }
                    }
                }
@@ -457,13 +470,25 @@
                            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) {
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/AutoOrdersChannelHandler.java
@@ -90,13 +90,14 @@
                String status = autoOrder.getString("status");
                String reason = autoOrder.getString("reason");
                String orderType = autoOrder.getString("order_type");
                String tradeId = autoOrder.getString("trade_id");
                JSONObject trigger = autoOrder.getJSONObject("trigger");
                String triggerPrice = trigger != null ? trigger.getString("price") : null;
                log.info("[{}] 自动订单更新, id:{}, status:{}, reason:{}, order_type:{}, trigger_price:{}, trade_id:{}",
                        CHANNEL_NAME, orderId, status, reason, orderType, triggerPrice,
                        autoOrder.get("trade_id"));
                        tradeId);
                if (getGridTradeService() != null) {
                    getGridTradeService().onAutoOrder(orderId, status, reason, orderType);
                    getGridTradeService().onAutoOrder(orderId, status, reason, orderType, tradeId);
                }
            }
        } catch (Exception e) {