新版仿ok交易所-后端
zyy
2026-01-28 7aa5b5509eaa80e0361f261093f9d4ddabbadc0e
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.yami.trading.huobi.data.job;
 
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.util.ThreadUtils;
import com.yami.trading.huobi.data.DataCache;
import com.yami.trading.huobi.data.internal.DataDBService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.syspara.SysparaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 最高最低修正
 *
 */
@Component
public class HighLowHandleJob implements Runnable {
    
    private static Logger logger = LoggerFactory.getLogger(HighLowHandleJob.class);
    
    /**
     * 数据接口调用间隔时长(毫秒)
     */
    private int interval;
    public static boolean first = true;
    @Autowired
    private SysparaService sysparaService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private DataService dataService;
    @Autowired
    DataDBService dataDBService;
 
    public void start() {
        new Thread(this, "HighLowHandleJob").start();
    }
 
    @Override
    public void run() {
        bulidHighLow();
        ThreadUtils.sleep(1000 * 60 * 5);
        while (true) {
            bulidHighLow();
            ThreadUtils.sleep(1000 * 60 * 5);
        }
    }
 
    public void bulidHighLow() {
        try {
            /*if (first) {
                // data数据保存间隔时长(毫秒)
                this.interval = this.sysparaService.find("data_interval").getInteger().intValue() / 1000;
                first = false;
            }
            // 秒
            int num = (24 * 60 * 60) / this.interval;*/
            List<Item> item_list = itemService.findByType(Item.cryptos);
            item_list = item_list.stream()
                    .filter(x -> x.getAdjustmentValue()!=null && x.getAdjustmentValue().doubleValue()!=0)
                    .collect(Collectors.toList());
            for (int i = 0; i < item_list.size(); i++) {
                String symbol = item_list.get(i).getSymbol();
                //重新查询缓存
                dataDBService.cacheBefore24Hour(symbol);
            }
 
            /*for (int i = 0; i < item_list.size(); i++) {
                Item item = item_list.get(i);
                try {
 
                    List<Realtime> history = bulidNum(DataCache.getRealtimeHistory().get(item.getSymbol()), num);
                    if (history == null || history.size() == 0) {
                        continue;
                    }
                    Double high = null;
                    Double low = null;
 
                    for (int j = 0; j < history.size(); j++) {
                        Realtime realtime = history.get(j);
 
                        if (high == null || high < realtime.getClose().doubleValue()) {
                            high = realtime.getClose().doubleValue();
                        }
 
                        if ((low == null || low > realtime.getClose().doubleValue()) && realtime.getClose() .doubleValue()> 0) {
                            low = realtime.getClose().doubleValue();
                        }
                    }
                    if (item == null || item.getSymbol() == null) {
                        logger.error("run fail");
                    }
                    if (high != null) {
                        DataCache.getRealtimeHigh().put(item.getSymbol(), high);
                    }
                    if (low != null && low > 0) {
                        DataCache.getRealtimeLow().put(item.getSymbol(), low);
                    }
 
                    Collections.sort(history);
                    DataCache.getRealtime24HBeforeOpen().put(item.getSymbol(), history.get(0).getClose().doubleValue());
 
                } catch (Exception e) {
                    logger.error("run fail", e);
                }
            }*/
 
        } catch (Exception e) {
            logger.error("bulidHighLow run fail", e);
        }
    }
 
    private List<Realtime> bulidNum(List<Realtime> cacheList, int num) {
        List<Realtime> list = new ArrayList<Realtime>();
        if (cacheList == null) {
            return list;
        }
        if (num > cacheList.size()) {
            num = cacheList.size();
        }
 
        for (int i = cacheList.size() - num; i < cacheList.size(); i++) {
            list.add(cacheList.get(i));
        }
 
        return list;
    }
 
    public void setSysparaService(SysparaService sysparaService) {
        this.sysparaService = sysparaService;
    }
 
    public void setItemService(ItemService itemService) {
        this.itemService = itemService;
    }
 
}