peter
2025-06-25 252184b1fff1b75e24032973996bfdc5b6126cb0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.yami.trading.huobi.data.job;
 
 
import cn.hutool.core.util.StrUtil;
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.data.domain.StockMarket;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.util.*;
import com.yami.trading.huobi.data.AdjustmentValueCache;
import com.yami.trading.huobi.data.DataCache;
import com.yami.trading.huobi.data.internal.DataDBService;
import com.yami.trading.huobi.data.model.AdjustmentValue;
import com.yami.trading.huobi.hobi.HobiDataService;
import com.yami.trading.huobi.hobi.internal.XueQiuDataServiceImpl;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.syspara.SysparaService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;
import java.util.stream.Collectors;
 
@Slf4j
@Component
public class StockGetDataJob extends AbstractGetDataJob {
 
    private static Logger logger = LoggerFactory.getLogger(StockGetDataJob.class);
 
    public static volatile boolean first = true;
 
    public static volatile boolean stockFirstFetch = true;
 
    @Autowired
    private SysparaService sysparaService;
    @Autowired
    private DataDBService dataDBService;
    @Autowired
    private HobiDataService hobiDataService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private XueQiuDataServiceImpl xueQiuDataService;
 
    public void start() {
        new Thread(this, "StockGetDataJob").start();
    }
 
    public void run() {
 
        if (first) {
            // data数据保存间隔时长(毫秒)
            this.interval = this.sysparaService.find("data_interval").getInteger().intValue();
            first = false;
        }
        while (true) {
            try {
                List<Item> list = itemService.list().stream().filter(i->"0".equalsIgnoreCase(i.getFake())).collect(Collectors.toList());
                // etf 和A股开盘时间是一样的
                String aStocSymbols = list.stream().filter(item ->item.getOpenCloseType() != null &&  item.getOpenCloseType().equalsIgnoreCase(Item.A_STOCKS))
                        .map(Item::getSymbol).collect(Collectors.joining(","));
                String hkStocSymbols = list.stream().filter(item -> item.getOpenCloseType() != null &&item.getOpenCloseType().equalsIgnoreCase(Item.HK_STOCKS)).map(Item::getSymbol).collect(Collectors.joining(","));
                String usStocSymbols = list.stream().filter(item -> item.getOpenCloseType() != null &&item.getOpenCloseType().equalsIgnoreCase(Item.US_STOCKS)).map(Item::getSymbol).collect(Collectors.joining(","));
                if(stockFirstFetch){
                    this.realtimeHandle(aStocSymbols);
                    this.realtimeHandle(hkStocSymbols);
                    this.realtimeHandle(usStocSymbols);
                    stockFirstFetch = false;
                }
                if(MarketOpenChecker.isMarketOpen(Item.A_STOCKS)){
                    this.realtimeHandle(aStocSymbols);
                }
                if(MarketOpenChecker.isMarketOpen(Item.HK_STOCKS)){
                    this.realtimeHandle(hkStocSymbols);
                }
                if(MarketOpenChecker.isMarketOpen(Item.US_STOCKS)){
                    this.realtimeHandle(usStocSymbols);
                }
 
//                String emptyRealTimeSymbols = list.stream().filter(i -> DataCache.getRealtime(i.getSymbol()) == null).map(Item::getSymbol).collect(Collectors.joining(","));
//                if(StringUtils.isNotEmpty(emptyRealTimeSymbols)){
//                    realtimeHandle(emptyRealTimeSymbols);
//                }
            } catch (Exception e) {
                logger.error("run fail", e);
            } finally {
                ThreadUtils.sleep(this.interval);
            }
        }
 
    }
 
    @Override
    public String getName() {
        return "股票实时数据采集";
    }
 
 
    public void realtimeHandle(String symbols ) {
 
        if (StrUtil.isEmpty(symbols)) {
            log.error("当前没有行情数据可以采集");
            return;
        }
 
        List<Realtime> realtimeList = this.hobiDataService.realtimeXueQiu(symbols);
        super.handleRealTimeList(realtimeList);
 
    }
 
 
}