1
zj
2024-06-13 a4662cc65a02f258062bf6cc392ceb1017db9292
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
package com.yami.trading.huobi.task;
 
 
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.service.MarketOpenChecker;
import com.yami.trading.huobi.hobi.internal.SpiderService;
import com.yami.trading.huobi.hobi.internal.TWDataServiceImpl;
import com.yami.trading.service.item.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.stream.Collectors;
 
@Component
@Lazy(value = false)
@Slf4j
public class AStockTradeListTask {
    @Autowired
    private DepthPushJob depthPushJob;
    @Autowired
    private ItemService itemService;
    @Autowired
    private SpiderService spiderService;
    @Autowired
    private TWDataServiceImpl twDataService;
    private volatile  boolean isAStockInit = false;
    private volatile  boolean isUsStockInit = false;
 
    private volatile  boolean isTwStockInit = false;
    @Scheduled(cron = "*/5 * * * * ?")
    public void sendTask() throws InterruptedException {
        if(!isAStockInit){
            fetchAStock();
            isAStockInit = true;
        }
        if(MarketOpenChecker.isMarketOpenByItemCloseType(Item.A_STOCKS)){
            fetchAStock();
        }
 
        if(!isUsStockInit){
            fetchUs();
 
            isUsStockInit = true;
        }
        if(MarketOpenChecker.isMarketOpenByItemCloseType(Item.US_STOCKS)){
            fetchUs();
 
        }
 
 
        if(!isTwStockInit){
            fetchTW();
 
            isTwStockInit = true;
        }
        if(MarketOpenChecker.isMarketOpenByItemCloseType(Item.TW_STOCKS)){
            fetchTW();
 
        }
 
    }
 
    private void fetchAStock() {
        String remarks = new ArrayList<>(itemService.list()).stream().filter(t->t.isActive() && Item.A_STOCKS.equalsIgnoreCase(t.getOpenCloseType())).map(Item::getRemarks).collect(Collectors.joining(","));
        spiderService.tradeList(remarks, false);
    }
 
    private void fetchUs() {
        String remarks = new ArrayList<>(itemService.list()).stream().filter(t->t.isActive() && Item.US_STOCKS.equalsIgnoreCase(t.getOpenCloseType())).map(Item::getRemarks).collect(Collectors.joining(","));
        spiderService.tradeList(remarks, true);
    }
    private void fetchTW() {
        String remarks = new ArrayList<>(itemService.list()).stream().filter(t->t.isActive() && Item.TW_STOCKS.equalsIgnoreCase(t.getOpenCloseType())).map(Item::getRemarks).collect(Collectors.joining(","));
        spiderService.tradeList(remarks, true);
    }
 
}