zj
2025-10-17 bbc4713b23778aebc1eb3d46cb04d539179d883d
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
package com.yami.trading.huobi.task;
 
 
import com.google.common.collect.Lists;
import com.yami.trading.bean.data.domain.Depth;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.service.MarketOpenChecker;
import com.yami.trading.huobi.data.DataCache;
import com.yami.trading.huobi.data.internal.DepthTimeObject;
import com.yami.trading.service.etf.EtfSecKLineService;
import com.yami.trading.service.etf.MarketService;
import com.yami.trading.service.item.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
//@Component
//@Lazy(value = false)
@Slf4j
public class FakePanKouTask {
    @Autowired
    private DepthPushJob depthPushJob;
    @Autowired
    private ItemService itemService;
    @Autowired
    private MarketService marketService;
 
    @Autowired
    private EtfSecKLineService etfSecKLineService;
 
    private boolean isFirstInit = true;
    @Scheduled(cron = "*/20 * * * * ?")
    public void deleteOverdueEtfKLine() throws InterruptedException {
        etfSecKLineService.deleteOverdueEtfKLine();
 
    }
 
    @Scheduled(cron = "*/5 * * * * ?")
    public void sendTask() throws InterruptedException {
        List<Item> symbols = new ArrayList<>(itemService.list()).stream().filter(i -> "1".equalsIgnoreCase(i.getFake())).collect(Collectors.toList());
        List<Depth> pankous = Lists.newArrayList();
        for (Item item : symbols) {
            if( !isFirstInit  && !MarketOpenChecker.isMarketOpenByItemCloseType(item.getOpenCloseType())){
                continue;
            }
            Depth d = marketService.queryDepth(item.getSymbol());
            if (d != null) {
                DepthTimeObject timeObject = new DepthTimeObject();
                timeObject.setDepth(d);
                DataCache.putDepth(d.getSymbol(), timeObject);
                pankous.add(d);
                DataCache.depthToTrade(d);
            }
            isFirstInit = false;
        }
 
 
//        Set<String> symbolSet = pankous.stream().map(Depth::getSymbol).collect(Collectors.toSet());
//        Map<String, String> depthResultMap = new HashMap<>();
//        // 数据处理
//        ResultObject depthResult = new ResultObject();
//        for (String symbol : symbolSet) {
//            DepthTimeObject depth = DataCache.getDepth().get(symbol);
//            if (null != depth && null != depth.getDepth()) {
//                Depth depthData = depth.getDepth();
//                Realtime realtime = DataCache.getRealtime(symbol);
//                if (realtime == null) {
//                    continue;
//                }
//                depthResult.setData(depthPushJob.depthRevise(depthData, symbol, realtime.getClose().doubleValue()));
//            }
//            depthResultMap.put(symbol, JSONObject.toJSONString(depthResult));
//        }
//
//        if (depthResultMap.isEmpty()) {
//            return;
//        }
//        ConcurrentHashMap.KeySetView<String, WebSocketSession> stringWebSocketSessionKeySetView = WebSocketServer.depthMap.keySet();
//        for (String socketKey : stringWebSocketSessionKeySetView) {
//            WebSocketSession webSocketSession = WebSocketServer.depthMap.get(socketKey);
//            // WebSocketServer server = WebSocketServer.depthMap.get(socketKey);
//            String type = webSocketSession.getType();
//            String symbolKey = webSocketSession.getParam();
//            String message = depthResultMap.get(symbolKey);
//            if(StringUtils.isEmptyString(message)){
//                continue;
//            }
//            WebSocketServer.sendToMessageById(socketKey, message, type);
//        }
 
    }
}