Administrator
4 days ago 3a0a282099dc5354e2bc070e289e30b43358cd38
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
package com.xcong.excoin.modules.gateApi;
 
import com.xcong.excoin.modules.okxNewPrice.celue.CaoZuoService;
import com.xcong.excoin.modules.okxNewPrice.okxWs.wanggeList.WangGeListService;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.math.BigDecimal;
 
/**
 * 管理 Gate WebSocket 客户端和网格交易服务实例
 */
@Slf4j
@Component
public class GateWebSocketClientManager {
    @Autowired
    private CaoZuoService caoZuoService;
    @Autowired
    private WangGeListService wangGeListService;
 
    private GateKlineWebSocketClient klinePriceClient;
    private GateGridTradeService gridTradeService;
 
    private static final String API_KEY = "d90ca272391992b8e74f8f92cedb21ec";
    private static final String API_SECRET = "1861e4f52de4bb53369ea3208d9ede38ece4777368030f96c77d27934c46c274";
 
    @PostConstruct
    public void init() {
        log.info("开始初始化GateWebSocketClientManager");
 
        try {
            gridTradeService = new GateGridTradeService(
                    API_KEY, API_SECRET,
                    "XAUT_USDT",
                    "30",
                    "cross",
                    "dual",
                    new BigDecimal("0.0035"),
                    new BigDecimal("0.5"),
                    3,
                    new BigDecimal("7.5"),
                    "10"
            );
            gridTradeService.init();
 
            klinePriceClient = new GateKlineWebSocketClient(caoZuoService, this, wangGeListService, gridTradeService, API_KEY, API_SECRET);
            klinePriceClient.init();
            log.info("已初始化GateKlineWebSocketClient");
 
            gridTradeService.startGrid();
        } catch (Exception e) {
            log.error("初始化GateWebSocketClientManager失败", e);
        }
    }
 
    @PreDestroy
    public void destroy() {
        log.info("开始销毁GateWebSocketClientManager");
 
        if (gridTradeService != null) {
            gridTradeService.stopGrid();
        }
        if (klinePriceClient != null) {
            try {
                klinePriceClient.destroy();
                log.info("已销毁GateKlineWebSocketClient");
            } catch (Exception e) {
                log.error("销毁GateKlineWebSocketClient失败", e);
            }
        }
 
        log.info("GateWebSocketClientManager销毁完成");
    }
 
    public GateKlineWebSocketClient getKlineWebSocketClient() {
        return klinePriceClient;
    }
 
    public GateGridTradeService getGridTradeService() {
        return gridTradeService;
    }
}