| | |
| | | List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("status", 0)); |
| | | log.info("当前有挂单数量:{}", userPendingorders.size()); |
| | | |
| | | for (UserPendingorder userPendingorder : userPendingorders) { |
| | | orderLoop: for (UserPendingorder userPendingorder : userPendingorders) { |
| | | try { |
| | | // 参数校验 |
| | | if (userPendingorder.getUserId() == null || userPendingorder.getStockId() == null |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 价格达到目标价格,执行买入逻辑 |
| | | synchronized (userPendingorder.getUserId()) { |
| | | // 价格达到目标价格,先进行验证 |
| | | // 判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(stock.getStockCode(), stock.getStockType()); |
| | | if (!b) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 执行买入逻辑(在 synchronized 块内) |
| | | synchronized (userPendingorder.getUserId()) { |
| | | // 再次检查挂单状态,防止并发处理 |
| | | UserPendingorder checkOrder = userPendingorderMapper.selectById(userPendingorder.getId()); |
| | | if (checkOrder == null || checkOrder.getStatus() != 0) { |
| | | // 挂单已被处理,跳过本次循环 |
| | | continue orderLoop; |
| | | } |
| | | |
| | | // 手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(com.nq.enums.EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()); |
| | | |