| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.nq.vo.foreigncurrency.ExchangeVO; |
| | | import com.nq.vo.position.UserPendingorderVO; |
| | | import com.nq.vo.stock.MarketVO; |
| | | import com.nq.vo.stock.PremarketStockVO; |
| | | import com.nq.vo.stock.StockListVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private UserPositionMapper userPositionMapper; |
| | | |
| | | @Autowired |
| | | IStockService iStockService; |
| | | |
| | | @Override |
| | | @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class) |
| | |
| | | // 查询所有待处理的挂单 |
| | | List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("status", 0)); |
| | | log.info("当前有挂单数量:{}", userPendingorders.size()); |
| | | |
| | | |
| | | |
| | | |
| | | List<PremarketStockVO> premarketStock = iStockService.getPremarketStock(); |
| | | |
| | | Map<String, PremarketStockVO> stockMap = premarketStock.stream() |
| | | .collect(Collectors.toMap( |
| | | PremarketStockVO::getCode, |
| | | stock -> stock |
| | | )); |
| | | |
| | | |
| | | orderLoop: for (UserPendingorder userPendingorder : userPendingorders) { |
| | | try { |
| | | // 参数校验 |
| | |
| | | this.userPendingorderMapper.updateById(userPendingorder); |
| | | continue; |
| | | } |
| | | |
| | | PremarketStockVO p = stockMap.get(stock.getStockCode()); |
| | | // 获取当前价格 |
| | | BigDecimal nowPrice = priceServices.getNowPrice(stock.getStockCode()); |
| | | if (nowPrice.compareTo(BigDecimal.ZERO) == 0) { |
| | | continue; |
| | | if(ObjectUtil.isEmpty(p)){ |
| | | |
| | | if (nowPrice.compareTo(BigDecimal.ZERO) == 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 判断价格是否达到目标价格:当前价格 <= 挂单价就买入 |
| | | if (nowPrice.compareTo(userPendingorder.getTargetPrice()) > 0) { |
| | | // 当前价格大于挂单价,继续等待 |
| | | continue; |
| | | } |
| | | |
| | | // 价格达到目标价格,先进行验证 |
| | | // 判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(stock.getStockCode(), stock.getStockType()); |
| | | if (!b) { |
| | | continue; |
| | | } |
| | | }else{ |
| | | // 判断价格是否达到目标价格:当前价格 <= 挂单价就买入 |
| | | if (p.getPrice().compareTo(userPendingorder.getTargetPrice()) > 0) { |
| | | // 当前价格大于挂单价,继续等待 |
| | | continue; |
| | | } |
| | | nowPrice = p.getPrice(); |
| | | } |
| | | |
| | | // 判断价格是否达到目标价格:当前价格 <= 挂单价就买入 |
| | | if (nowPrice.compareTo(userPendingorder.getTargetPrice()) > 0) { |
| | | // 当前价格大于挂单价,继续等待 |
| | | continue; |
| | | } |
| | | |
| | | // 价格达到目标价格,先进行验证 |
| | | // 判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(stock.getStockCode(), stock.getStockType()); |
| | | if (!b) { |
| | | continue; |
| | | } |
| | | |
| | | // 检查股票是否被锁定 |
| | | if (stock.getIsLock() != 0) { |