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;
|
}
|
}
|