新版仿ok交易所-后端
zj
2025-01-06 6e21cf6973aa1898259ddceda665f0f1b06272ab
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
package com.yami.trading.service.data;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yami.trading.bean.data.domain.*;
import com.yami.trading.common.util.ApplicationContextUtils;
import com.yami.trading.common.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
 
import java.util.ArrayList;
import java.util.List;
 
@Component
@Slf4j
public class RestDataService  implements DataService {
    @Autowired
    private RestTemplate restTemplate;
 
    @Override
    public List<Realtime> realtime(String symbol) {
        DataService dataService;
        try {
             dataService = ApplicationContextUtils.getBean("dataService", DataService.class);
            if(dataService != null){
                return dataService.realtime(symbol);
            }
        }catch (NoSuchBeanDefinitionException exception){
            log.error("获取 dataService 失败", exception);
        }
 
        return Lists.newArrayList();
    }
 
    @Override
    public Depth depth(String symbol) {
        DataService dataService;
        try {
            dataService = ApplicationContextUtils.getBean("dataService", DataService.class);
            if(dataService != null){
                return dataService.depth(symbol);
            }
        }catch (NoSuchBeanDefinitionException exception){
            log.error("获取 dataService 失败", exception);
        }
        return new Depth();
    }
 
    @Override
    public List<Trend> trend(String symbol) {
        DataService dataService;
        try {
            dataService = ApplicationContextUtils.getBean("dataService", DataService.class);
            if(dataService != null){
                return dataService.trend(symbol);
            }
        }catch (NoSuchBeanDefinitionException exception){
            log.error("获取 dataService 失败", exception);
        }
        return new ArrayList<>();
    }
 
    @Override
    public List<Kline> kline(String symbol, String line) {
        DataService dataService;
        try {
            dataService = ApplicationContextUtils.getBean("dataService", DataService.class);
            if(dataService != null){
                return dataService.kline(symbol, line);
            }
        }catch (NoSuchBeanDefinitionException exception){
            log.error("获取 dataService 失败", exception);
        }
        return new ArrayList<>();
    }
 
    @Override
    public Trade trade(String symbol) {
        DataService dataService;
        try {
            dataService = ApplicationContextUtils.getBean("dataService", DataService.class);
            if(dataService != null){
                return dataService.trade(symbol);
            }
        }catch (NoSuchBeanDefinitionException exception){
            log.error("获取 dataService 失败", exception);
        }
        return new Trade();
    }
 
 
}