Administrator
2026-05-28 b7a2fa0ea40b15bd5b60d737cb96764884dcaaaa
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -428,40 +428,8 @@
                    tryGenerateQueues();
                }else {
                    longPositionSize = size;
                    List<GridElement> allShortOrders = GridElement.findAllLongOrders(longEntryPrice);
                    if (CollUtil.isNotEmpty(allShortOrders)){
                        GridElement keep = allShortOrders.stream()
                                .max((a, b) -> a.getGridPrice().compareTo(b.getGridPrice()))
                                .orElse(null);
                        for (GridElement e : allShortOrders) {
                            if (e == keep) {
                                continue;
                            }
                            executor.cancelConditionalOrder(
                                    e.getLongOrderId(),
                                    orderId -> {
                                        longEntryTraderIdParam(
                                                e,
                                                null,
                                                false
                                        );
                                    }
                            );
                            if (e.getLongTakeProfitOrderId() != null){
                                executor.cancelConditionalOrder(
                                        e.getLongTakeProfitOrderId(),
                                        orderId -> {
                                            longTakeProfitTraderIdParam(
                                                    e,
                                                    null,
                                                    false
                                            );
                                        }
                                );
                            }
                        }
                    }
                    checkShortEntryOrderToCancel();
                    checkLongEntryOrderToCancel();
                }
            } else {
                longActive = false;
@@ -479,39 +447,8 @@
                    tryGenerateQueues();
                }else {
                    shortPositionSize = size.abs();
                    List<GridElement> allLongOrders = GridElement.findAllShortOrders(shortEntryPrice);
                    if (CollUtil.isNotEmpty(allLongOrders)){
                        GridElement keep = allLongOrders.stream()
                                .min((a, b) -> a.getGridPrice().compareTo(b.getGridPrice()))
                                .orElse(null);
                        for (GridElement e : allLongOrders) {
                            if (e == keep) {
                                continue;
                            }
                            executor.cancelConditionalOrder(
                                    e.getShortOrderId(),
                                    orderId -> {
                                        shortEntryTraderIdParam(
                                                e,
                                                null,
                                                false
                                        );
                                    }
                            );
                            if (e.getShortTakeProfitOrderId() != null){
                                executor.cancelConditionalOrder(
                                        e.getShortTakeProfitOrderId(),
                                        orderId -> {
                                            shortTakeProfitTraderIdParam(
                                                    e,
                                                    null,
                                                    false
                                            );
                                        }
                                );
                            }
                        }
                    }
                    checkShortEntryOrderToCancel();
                    checkLongEntryOrderToCancel();
                }
            } else {
                shortActive = false;
@@ -520,6 +457,79 @@
        }
    }
    private void checkShortEntryOrderToCancel() {
        List<GridElement> allLongOrders = GridElement.findAllShortOrders(shortEntryPrice);
        if (CollUtil.isNotEmpty(allLongOrders)){
            GridElement keep = allLongOrders.stream()
                    .min((a, b) -> a.getGridPrice().compareTo(b.getGridPrice()))
                    .orElse(null);
            for (GridElement e : allLongOrders) {
                if (e == keep) {
                    continue;
                }
                executor.cancelConditionalOrder(
                        e.getShortOrderId(),
                        orderId -> {
                            shortEntryTraderIdParam(
                                    e,
                                    null,
                                    false
                            );
                        }
                );
                if (e.getShortTakeProfitOrderId() != null){
                    executor.cancelConditionalOrder(
                            e.getShortTakeProfitOrderId(),
                            orderId -> {
                                shortTakeProfitTraderIdParam(
                                        e,
                                        null,
                                        false
                                );
                            }
                    );
                }
            }
        }
    }
    private void checkLongEntryOrderToCancel() {
        List<GridElement> allShortOrders = GridElement.findAllLongOrders(longEntryPrice);
        if (CollUtil.isNotEmpty(allShortOrders)){
            GridElement keep = allShortOrders.stream()
                    .max((a, b) -> a.getGridPrice().compareTo(b.getGridPrice()))
                    .orElse(null);
            for (GridElement e : allShortOrders) {
                if (e == keep) {
                    continue;
                }
                executor.cancelConditionalOrder(
                        e.getLongOrderId(),
                        orderId -> {
                            longEntryTraderIdParam(
                                    e,
                                    null,
                                    false
                            );
                        }
                );
                if (e.getLongTakeProfitOrderId() != null){
                    executor.cancelConditionalOrder(
                            e.getLongTakeProfitOrderId(),
                            orderId -> {
                                longTakeProfitTraderIdParam(
                                        e,
                                        null,
                                        false
                                );
                            }
                    );
                }
            }
        }
    }
    // ---- 平仓推送回调 ----
    /**