refactor(gateApi): 优化网格交易服务中的变量作用域
- 将 actualPosSize 和 nextGridId 声明为 final 变量以解决闭包问题
- 确保在异步回调中正确访问这些变量的值
- 提高代码的线程安全性和可读性
| | |
| | | } |
| | | |
| | | 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); |