| | |
| | | package com.nq.utils.task.stock; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.google.gson.Gson; |
| | | import com.nq.dao.*; |
| | | import com.nq.dao.StockMapper; |
| | | import com.nq.dao.UserPositionMapper; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.*; |
| | | import com.nq.pojo.DataStockBean; |
| | | import com.nq.pojo.ReponseBase; |
| | | import com.nq.pojo.Stock; |
| | | import com.nq.pojo.UserPosition; |
| | | import com.nq.service.IMandatoryLiquidationService; |
| | | import com.nq.service.IStockService; |
| | | import com.nq.service.IUserPositionService; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.redis.RedisShardedPoolUtils; |
| | | import com.nq.utils.stock.BuyAndSellUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | private final Lock stockConstraintLock = new ReentrantLock(); |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | IMandatoryLiquidationService mandatoryLiquidationService; |
| | | |
| | | |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(StockTask.class); |
| | | |
| | | |
| | | boolean syncINStockData = true; |
| | | |
| | | private final Lock syncINStockDataLock = new ReentrantLock(); |
| | | |
| | | /** |
| | | * 同步系统所需要的股票 |
| | | * */ |
| | | */ |
| | | @Scheduled(cron = "0 0 0/2 * * ?") |
| | | public void syncINStockData() { |
| | | if (syncINStockData) |
| | | syncINStockData = false; |
| | | else return; |
| | | if (syncINStockDataLock.tryLock()) { |
| | | try { |
| | | loadAllStock(EStockType.IN); |
| | | // loadAllStock(EStockType.HK); |
| | | } finally { |
| | | syncINStockDataLock.unlock(); |
| | | syncINStockData = true; |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 同步美国股票 |
| | | * */ |
| | | */ |
| | | // @Scheduled(cron = "0 0/30 * * * ?") |
| | | public void loadStockCompanies(){ |
| | | loadAllCompanies(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 加载公司信息 |
| | | * */ |
| | | */ |
| | | public void loadAllCompanies(){ |
| | | List<Stock> list = stockMapper.findStockList(); |
| | | for (int i = 0; i <list.size() ; i++) { |
| | |
| | | |
| | | /** |
| | | * 加载所有股票数据 |
| | | * */ |
| | | */ |
| | | public void loadAllStock(EStockType eStockType){ |
| | | log.info("同步股票 数据 {}",eStockType.getCode()); |
| | | List<DataStockBean> list = new ArrayList<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | boolean stockConstraint = true; |
| | | |
| | | /** |
| | | * 强制平仓 |
| | | */ |
| | | @Scheduled(cron = "0/1 * * * * ?") |
| | | public void stockConstraint(){ |
| | | if (stockConstraint) |
| | | stockConstraint = false; |
| | | else return; |
| | | if (stockConstraintLock.tryLock()) { |
| | | try { |
| | | List<UserPosition> userPositions = userPositionMapper.selectList(new LambdaQueryWrapper<UserPosition>().isNull(UserPosition::getSellOrderId)); |
| | |
| | | log.error("强制平仓任务错误:" + e.getMessage()); |
| | | } finally { |
| | | stockConstraintLock.unlock(); |
| | | stockConstraint = true; |
| | | } |
| | | } else { |
| | | log.info("强制平仓任务--------->上次任务还未执行完成,本次任务忽略"); |