Administrator
2026-06-06 aaa9b2d954e3dc3c1588ecbb749b46b413c5fc5b
refactor(gateApi): 优化网格交易服务中的变量作用域

- 将 actualPosSize 和 nextGridId 声明为 final 变量以解决闭包问题
- 确保在异步回调中正确访问这些变量的值
- 提高代码的线程安全性和可读性
1 files modified
6 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -1559,20 +1559,22 @@
                }
                BigDecimal tpPrice = nextGrid.getGridPrice();
                final long finalPosSize = actualPosSize;
                final int finalNextGridId = nextGridId;
                if (isLong) {
                    executor.placeTakeProfit(tpPrice,
                            FuturesPriceTrigger.RuleEnum.NUMBER_1,
                            ORDER_TYPE_CLOSE_LONG,
                            negate(config.getQuantity()),
                            profitId -> log.info("[Gate] 多仓超限止盈已挂(持仓:{})>, gridId:{}, tpPrice:{}, id:{}",
                                    actualPosSize, nextGridId, tpPrice, profitId));
                                    finalPosSize, finalNextGridId, tpPrice, profitId));
                } else {
                    executor.placeTakeProfit(tpPrice,
                            FuturesPriceTrigger.RuleEnum.NUMBER_2,
                            ORDER_TYPE_CLOSE_SHORT,
                            config.getQuantity(),
                            profitId -> log.info("[Gate] 空仓超限止盈已挂(持仓:{})>, gridId:{}, tpPrice:{}, id:{}",
                                    actualPosSize, nextGridId, tpPrice, profitId));
                                    finalPosSize, finalNextGridId, tpPrice, profitId));
                }
            } catch (Exception e) {
                log.warn("[Gate] 通过API查询持仓超限检查失败", e);