1
zyy
18 hours ago 4fefff17528a878d345ff3311c297a66a671b8d6
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
package com.yami.trading.huobi.task;
 
import com.yami.trading.bean.data.domain.Depth;
import com.yami.trading.bean.data.domain.Trade;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.huobi.data.DataCache;
import com.yami.trading.huobi.data.internal.DepthTimeObject;
import com.yami.trading.huobi.data.internal.TradeTimeObject;
import com.yami.trading.huobi.hobi.HobiDataService;
import com.yami.trading.service.item.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * 加密货币 定时器
 *
 * @author Jerry
 * @date 2023/11/12
 */
@Component
@Lazy(value = false)
@Slf4j
public class CryptoCurrencyDataTask {
    @Resource
    ItemService itemService;
 
    @Resource
    HobiDataService hobiDataService;
 
    private volatile boolean isHuobiInit = false;
 
    /**
     * 深度数据、近期交易记录 火币采集任务
     */
    @Async
    @Scheduled(cron = "*/3 * * * * ?")
    public void DepthTradeCollectionTask() {
        try {
            List<Item> items = itemService.findByType(Item.cryptos);
            for (Item item : items) {
                // 暂不使用
//                boolean isOpen = MarketOpenChecker.isMarketOpenByItemCloseType(item.getOpenCloseType());
//                if (isHuobiInit && !isOpen) {
//                    log.warn("---> CryptoCurrencyDataTask.DepthTradeCollectionTask 当前 symbol:{} 对应的股票处于未开盘状态," +
//                            "忽略采集的深度数据", item.getSymbol());
//                    continue;
//                }
 
                collection(item);
            }
            isHuobiInit = true;
        } catch (Throwable e) {
            log.error("深度数据、近期交易记录 火币采集任务,异常信息:", e);
        }
    }
 
    private void collection(Item item) {
        Depth depth = hobiDataService.depthDecorator(item.getRemarks(), 0);
        if (depth != null) {
            DepthTimeObject timeObject = new DepthTimeObject();
            timeObject.setDepth(depth);
            DataCache.putDepth(item.getSymbol(), timeObject);
        }
 
        Trade trade = hobiDataService.tradeDecorator(item.getRemarks(), 0);
        if (trade != null) {
            TradeTimeObject timeObject = new TradeTimeObject();
            timeObject.put(item.getSymbol(), trade.getData());
            DataCache.putTrade(item.getSymbol(), timeObject);
        }
    }
 
}