Administrator
2025-12-29 2cb4335ce706ccb451ccc7edb92fd89b5ad427e2
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
package com.xcong.excoin.modules.okxNewPrice.okxpi.config;
 
 
import com.xcong.excoin.modules.okxNewPrice.utils.FebsException;
import com.xcong.excoin.modules.okxNewPrice.okxpi.config.impl.ExchangeLoginEventServiceImpl;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 交易所登录服务 singleton模式
 * 负责根据交易所类型提供对应的交易所登录事件服务
 */
public class ExchangeLoginService {
    // 存储交易所类型与登录服务实例的映射
    private final static Map<String, ExchangeLoginEventService> eventMap = new HashMap<>();
 
    // 静态代码块,用于初始化eventMap
    static {
        for (ExchangeInfoEnum infoEnum : ExchangeInfoEnum.values()) {
            eventMap.put(infoEnum.name(), new ExchangeLoginEventServiceImpl(
                    infoEnum.getApiKey(),
                    infoEnum.getSecretKey(),
                    infoEnum.getPassphrase(),
                    infoEnum.isAccountType()));
        }
    }
 
    // 私有构造方法,防止外部实例化
    private ExchangeLoginService() {
    }
 
    // Singleton实例
    public final static ExchangeLoginService INSTANCE = new ExchangeLoginService();
 
    /**
     * 根据交易所类型获取对应的交易所登录事件服务
     * @param exchangeType 交易所类型
     * @return 对应的交易所登录事件服务实例
     * @throws FebsException 如果提供的交易所类型无效,则抛出异常
     */
    public static ExchangeLoginEventService getInstance(String exchangeType) {
        ExchangeLoginEventService exchange = eventMap.get(exchangeType);
        if (exchange == null) {
            throw new FebsException("参数错误");
        }
 
        return exchange;
    }
}