From 212e20fa6e9d0cc69d7f70339ecd47d4ec286533 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sun, 04 Jan 2026 11:03:41 +0800
Subject: [PATCH] feat(okxNewPrice): 优化MACD策略交易判断逻辑
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java | 59 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
index d8981d0..c00f893 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
@@ -2,7 +2,7 @@
import com.xcong.excoin.modules.okxNewPrice.celue.CaoZuoService;
import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.ExchangeInfoEnum;
-import com.xcong.excoin.modules.okxNewPrice.wangge.WangGeService;
+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;
@@ -22,14 +22,18 @@
@ConditionalOnProperty(prefix = "app", name = "quant", havingValue = "true")
public class OkxWebSocketClientManager {
@Autowired
- private WangGeService wangGeService;
- @Autowired
private CaoZuoService caoZuoService;
@Autowired
private RedisUtils redisUtils;
+ @Autowired
+ private WangGeListService wangGeListService;
- // 存储所有WebSocket客户端实例,key为账号类型名称
- private final Map<String, OkxQuantWebSocketClient> clientMap = new ConcurrentHashMap<>();
+ // 存储所有OkxQuantWebSocketClient实例,key为账号类型名称
+ private final Map<String, OkxQuantWebSocketClient> quantClientMap = new ConcurrentHashMap<>();
+
+ // 存储OkxNewPriceWebSocketClient实例
+ private OkxKlineWebSocketClient klinePriceClient;
+
/**
* 初始化方法,在Spring Bean构造完成后执行
@@ -39,14 +43,23 @@
public void init() {
log.info("开始初始化OkxWebSocketClientManager");
+ // 初始化价格WebSocket客户端
+ try {
+ klinePriceClient = new OkxKlineWebSocketClient(redisUtils, caoZuoService, this, wangGeListService);
+ klinePriceClient.init();
+ log.info("已初始化OkxNewPriceWebSocketClient");
+ } catch (Exception e) {
+ log.error("初始化OkxNewPriceWebSocketClient失败", e);
+ }
+
// 获取所有ExchangeInfoEnum枚举值
ExchangeInfoEnum[] accounts = ExchangeInfoEnum.values();
// 为每个账号创建一个WebSocket客户端实例
for (ExchangeInfoEnum account : accounts) {
try {
- OkxQuantWebSocketClient client = new OkxQuantWebSocketClient(account, wangGeService, caoZuoService, redisUtils);
- clientMap.put(account.name(), client);
+ OkxQuantWebSocketClient client = new OkxQuantWebSocketClient(account, caoZuoService, redisUtils);
+ quantClientMap.put(account.name(), client);
client.init();
log.info("已初始化账号 {} 的WebSocket客户端", account.name());
} catch (Exception e) {
@@ -65,8 +78,18 @@
public void destroy() {
log.info("开始销毁OkxWebSocketClientManager");
- // 关闭所有客户端实例
- for (Map.Entry<String, OkxQuantWebSocketClient> entry : clientMap.entrySet()) {
+ // 关闭价格WebSocket客户端
+ if (klinePriceClient != null) {
+ try {
+ klinePriceClient.destroy();
+ log.info("已销毁OkxNewPriceWebSocketClient");
+ } catch (Exception e) {
+ log.error("销毁OkxNewPriceWebSocketClient失败", e);
+ }
+ }
+
+ // 关闭所有量化交易WebSocket客户端实例
+ for (Map.Entry<String, OkxQuantWebSocketClient> entry : quantClientMap.entrySet()) {
try {
OkxQuantWebSocketClient client = entry.getValue();
client.destroy();
@@ -77,25 +100,33 @@
}
// 清空客户端映射
- clientMap.clear();
+ quantClientMap.clear();
log.info("OkxWebSocketClientManager销毁完成");
}
/**
- * 获取指定账号的WebSocket客户端实例
+ * 获取指定账号的OkxQuantWebSocketClient实例
* @param accountName 账号类型名称
* @return WebSocket客户端实例
*/
public OkxQuantWebSocketClient getClient(String accountName) {
- return clientMap.get(accountName);
+ return quantClientMap.get(accountName);
}
/**
- * 获取所有WebSocket客户端实例
+ * 获取所有OkxQuantWebSocketClient实例
* @return 所有客户端实例的集合
*/
public Collection<OkxQuantWebSocketClient> getAllClients() {
- return clientMap.values();
+ return quantClientMap.values();
+ }
+
+ /**
+ * 获取OkxNewPriceWebSocketClient实例
+ * @return 价格WebSocket客户端实例
+ */
+ public OkxKlineWebSocketClient getKlineWebSocketClient() {
+ return klinePriceClient;
}
}
\ No newline at end of file
--
Gitblit v1.9.1