Search in sources :

Example 1 with StockRealTimePrice

use of com.mistra.plank.pojo.dto.StockRealTimePrice in project plank by MistraR.

the class Barbarossa method monitor.

/**
 * 实时监测数据 显示股票实时涨跌幅度,最高,最低价格
 */
public void monitor() {
    executorService.submit(() -> {
        try {
            List<Stock> stocks = stockMapper.selectList(new QueryWrapper<Stock>().eq("track", true));
            Map<String, Stock> stockMap = stocks.stream().collect(Collectors.toMap(Stock::getName, e -> e));
            List<StockRealTimePrice> realTimePrices = new ArrayList<>();
            while (DateUtil.hour(new Date(), true) <= 15 && DateUtil.hour(new Date(), true) >= 9) {
                for (Stock stock : stocks) {
                    String url = plankConfig.getXueQiuStockDetailUrl().replace("{code}", stock.getCode()).replace("{time}", String.valueOf(System.currentTimeMillis())).replace("{recentDayNumber}", "1");
                    String body = HttpUtil.getHttpGetResponseString(url, plankConfig.getXueQiuCookie());
                    JSONObject data = JSON.parseObject(body).getJSONObject("data");
                    JSONArray list = data.getJSONArray("item");
                    if (org.apache.commons.collections.CollectionUtils.isNotEmpty(list)) {
                        for (Object o : list) {
                            double v = ((JSONArray) o).getDoubleValue(5);
                            double rate = -(double) Math.round(((v - stock.getPurchasePrice().doubleValue()) / v) * 100) / 100;
                            realTimePrices.add(StockRealTimePrice.builder().todayRealTimePrice(v).name(stock.getName()).todayHighestPrice(((JSONArray) o).getDoubleValue(3)).todayLowestPrice(((JSONArray) o).getDoubleValue(4)).purchasePrice(stock.getPurchasePrice()).rate((int) (rate * 100)).increaseRate(((JSONArray) o).getDoubleValue(7)).build());
                        }
                    }
                }
                // 暴跌
                List<StockRealTimePrice> slump = realTimePrices.stream().filter(e -> e.getIncreaseRate() < -5).collect(Collectors.toList());
                List<StockRealTimePrice> buy = realTimePrices.stream().filter(e -> e.getRate() >= -3).collect(Collectors.toList());
                Collections.sort(realTimePrices);
                Collections.sort(slump);
                Collections.sort(buy);
                System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                log.error("----------------------------------------持仓----------------------------------------");
                for (StockRealTimePrice realTimePrice : realTimePrices) {
                    if (stockMap.get(realTimePrice.getName()).getShareholding()) {
                        Barbarossa.log.warn(convertLog(realTimePrice));
                    }
                }
                log.error("--------------------------------------接近建仓点--------------------------------------");
                for (StockRealTimePrice realTimePrice : buy) {
                    if (!stockMap.get(realTimePrice.getName()).getShareholding()) {
                        if (realTimePrice.getRate() >= -1) {
                            Barbarossa.log.warn(convertLog(realTimePrice));
                        } else {
                            Barbarossa.log.info(convertLog(realTimePrice));
                        }
                    }
                }
                log.error("----------------------------------------暴跌----------------------------------------");
                for (StockRealTimePrice realTimePrice : slump) {
                    if (!stockMap.get(realTimePrice.getName()).getShareholding()) {
                        Barbarossa.log.warn(convertLog(realTimePrice));
                    }
                }
                realTimePrices.clear();
                Thread.sleep(10000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) Date(java.util.Date) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) DragonList(com.mistra.plank.pojo.entity.DragonList) HoldShares(com.mistra.plank.pojo.entity.HoldShares) PlankConfig(com.mistra.plank.config.PlankConfig) Clearance(com.mistra.plank.pojo.entity.Clearance) BigDecimal(java.math.BigDecimal) Map(java.util.Map) TradeRecord(com.mistra.plank.pojo.entity.TradeRecord) Days(org.joda.time.Days) HoldSharesMapper(com.mistra.plank.mapper.HoldSharesMapper) HttpUtil(com.mistra.plank.util.HttpUtil) RoundingMode(java.math.RoundingMode) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) FundHoldingsParam(com.mistra.plank.pojo.param.FundHoldingsParam) TradeRecordMapper(com.mistra.plank.mapper.TradeRecordMapper) FundHoldingsTrackingMapper(com.mistra.plank.mapper.FundHoldingsTrackingMapper) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Stock(com.mistra.plank.pojo.entity.Stock) UploadDataListener(com.mistra.plank.util.UploadDataListener) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) DragonListMapper(com.mistra.plank.mapper.DragonListMapper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) EasyExcel(com.alibaba.excel.EasyExcel) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JSONArray(com.alibaba.fastjson.JSONArray) CommandLineRunner(org.springframework.boot.CommandLineRunner) ExecutorService(java.util.concurrent.ExecutorService) DailyRecordMapper(com.mistra.plank.mapper.DailyRecordMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) DateUtils(org.apache.commons.lang3.time.DateUtils) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(org.joda.time.LocalDate) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Component(org.springframework.stereotype.Component) ClearanceReasonEnum(com.mistra.plank.pojo.enums.ClearanceReasonEnum) JSON(com.alibaba.fastjson.JSON) NamedThreadFactory(cn.hutool.core.thread.NamedThreadFactory) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) StockMapper(com.mistra.plank.mapper.StockMapper) Collections(java.util.Collections) ClearanceMapper(com.mistra.plank.mapper.ClearanceMapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) JSONObject(com.alibaba.fastjson.JSONObject) Stock(com.mistra.plank.pojo.entity.Stock)

Aggregations

DateUtil (cn.hutool.core.date.DateUtil)1 NamedThreadFactory (cn.hutool.core.thread.NamedThreadFactory)1 EasyExcel (com.alibaba.excel.EasyExcel)1 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 PlankConfig (com.mistra.plank.config.PlankConfig)1 ClearanceMapper (com.mistra.plank.mapper.ClearanceMapper)1 DailyRecordMapper (com.mistra.plank.mapper.DailyRecordMapper)1 DragonListMapper (com.mistra.plank.mapper.DragonListMapper)1 FundHoldingsTrackingMapper (com.mistra.plank.mapper.FundHoldingsTrackingMapper)1 HoldSharesMapper (com.mistra.plank.mapper.HoldSharesMapper)1 StockMapper (com.mistra.plank.mapper.StockMapper)1 TradeRecordMapper (com.mistra.plank.mapper.TradeRecordMapper)1 StockRealTimePrice (com.mistra.plank.pojo.dto.StockRealTimePrice)1 Clearance (com.mistra.plank.pojo.entity.Clearance)1 DailyRecord (com.mistra.plank.pojo.entity.DailyRecord)1 DragonList (com.mistra.plank.pojo.entity.DragonList)1