Administrator
2026-09-22 da014bcdd947e917181c757e7046e8dc1263f881
fix(gateApi): 修复网格交易中长短仓逻辑错误

- 修复了价格驱动启用时长短仓处理逻辑颠倒的问题
- 移除了基础网格元素的冗余订单状态设置代码
- 重命名 processShortGrid 为 processLongGrid 并更新相关注释
- 重命名 processLongGrid 为 processShortGrid 并更新相关注释
- 修正了日志信息中多单和空单的描述错误
- 更新了空仓归零后的订单挂单逻辑以匹配正确的交易方向
1 files modified
20 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -529,7 +529,7 @@
                config.isPriceDriveEnabled() &&
                longActive == false &&
                    longPositionSize.compareTo(BigDecimal.ZERO) == 0){
            processShortGrid(closePrice);
            processLongGrid(closePrice);
        }
@@ -537,7 +537,7 @@
                config.isPriceDriveEnabled() &&
                shortActive == false &&
                        shortPositionSize.compareTo(BigDecimal.ZERO) == 0){
            processLongGrid(closePrice);
            processShortGrid(closePrice);
        }
    }
@@ -948,12 +948,6 @@
            generateShortQueue();
            generateLongQueue();
            updateGridElements();
            GridElement baseGridElement = GridElement.findById(0);
            baseGridElement.setLongOrderId(baseLongTraderParam.getEntryOrderId());
            baseGridElement.setHasLongOrder(true);
            baseGridElement.setShortOrderId(baseShortTraderParam.getEntryOrderId());
            baseGridElement.setHasShortOrder(true);
//            // 空仓止损对应的多仓止盈:多仓止盈挂在ID=3
//            int tpGridIdLong = 3;
@@ -1449,7 +1443,8 @@
    }
    private void processShortGrid(BigDecimal currentPrice) {
    /** 多仓仓位归零后,在当前价上方最近网格重新挂多单(遍历 totalLongPriceQueue 升序)。 */
    private void processLongGrid(BigDecimal currentPrice) {
        BigDecimal matched = BigDecimal.ZERO;
        synchronized (totalLongPriceQueue) {
            for (BigDecimal p : totalLongPriceQueue) {
@@ -1522,7 +1517,8 @@
    }
    private void processLongGrid(BigDecimal currentPrice) {
    /** 空仓仓位归零后,在当前价下方最近网格重新挂空单(遍历 totalShortPriceQueue 降序)。 */
    private void processShortGrid(BigDecimal currentPrice) {
        BigDecimal matched = BigDecimal.ZERO;
        synchronized (totalShortPriceQueue) {
            for (BigDecimal p : totalShortPriceQueue) {
@@ -1571,7 +1567,7 @@
                                    GridElement finalCancelCursor = cancelCursor;
                                    executor.cancelConditionalOrder(shortOrderId, oid -> {
                                        shortEntryTraderIdParam(finalCancelCursor, shortOrderId, false);
                                        log.info("[Gate] 空仓仓位归零, 取消gridId:{}的多单{}", finalCancelCursor.getId(), shortOrderId);
                                        log.info("[Gate] 空仓仓位归零, 取消gridId:{}的空单{}", finalCancelCursor.getId(), shortOrderId);
                                    });
                                }
                            }
@@ -1582,7 +1578,7 @@
                        if (!newEntryGrid.isHasShortOrder() && !hasShortOrderAbove){
                            BigDecimal triggerPrice = newEntryGrid.getGridPrice();
                            String size = quantity;
                            log.info("[Gate] 空仓仓位归零 gridId:{}, 挂{}基础张多单",
                            log.info("[Gate] 空仓仓位归零 gridId:{}, 挂{}基础张空单",
                                    newEntryGrid.getId(),  size);
                            newEntryGrid.getShortTraderParam().setQuantity(size);
                            placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,