Administrator
2026-06-08 1b2020988806a738220a7e31f7a9f1986a578a2a
fix(gateApi): 修复网格交易中的空指针异常

- 在访问newEntryGrid之前添加null检查
- 调整if条件判断顺序以避免潜在的NullPointerException
- 确保在操作前验证对象存在性
- 修复多仓和空仓仓位归零逻辑中的安全检查
1 files modified
14 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 14 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -1203,11 +1203,11 @@
        Integer upId = matchedUpGridElement.getUpId();
        GridElement newEntryGrid = GridElement.findById(upId);
        if (newEntryGrid != null) {
        GridElement cancelGridElement = GridElement.findById(newEntryGrid.getUpId());
        if (cancelGridElement != null) {
            if (newEntryGrid != null) {
                BigDecimal triggerPrice = newEntryGrid.getGridPrice();
                String size = cancelGridElement.getLongTraderParam().getQuantity();
                log.info("[Gate] 多仓仓位归零 gridId:{}, 挂{}基础张多单",
@@ -1216,7 +1216,6 @@
                placeEntryOrderWithPreFlag(newEntryGrid, true, triggerPrice,
                        FuturesPriceTrigger.RuleEnum.NUMBER_1, size);
            }
            /**
             * 看是否有多仓挂单,有就取消
@@ -1228,7 +1227,7 @@
                });
            }
        }
        }
    }
    private void processLongGrid(BigDecimal currentPrice) {
@@ -1252,11 +1251,11 @@
        Integer downId = matchedUpGridElement.getDownId();
        GridElement newEntryGrid = GridElement.findById(downId);
        if (newEntryGrid != null) {
        GridElement cancelGridElement = GridElement.findById(newEntryGrid.getDownId());
        if (cancelGridElement != null) {
            if (newEntryGrid != null) {
                BigDecimal triggerPrice = newEntryGrid.getGridPrice();
                String size = cancelGridElement.getShortTraderParam().getQuantity();
                log.info("[Gate] 空仓仓位归零 gridId:{}, 挂{}基础张多单",
@@ -1264,7 +1263,6 @@
                newEntryGrid.getShortTraderParam().setQuantity(size);
                placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
                        FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size));
            }
            /**
             * 看是否有空仓挂单,有就取消
@@ -1276,6 +1274,8 @@
                });
            }
        }
        }
    }
    private void handleLongStopLossTriggered(GridElement gridElement) {