From faa59ad8f374d64b187dc087312c3aef397006ee Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sat, 13 Dec 2025 21:53:51 +0800
Subject: [PATCH] fix(okxNewPrice): 修复 WebSocket 推送数据字段缺失问题
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java
index b71c120..3687ea6 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java
@@ -145,7 +145,7 @@
}
try {
- InstrumentsWs.handleEvent(redisUtils);
+ InstrumentsWs.handleEvent();
wangGeService.initWangGe();
SSLConfig.configureSSL();
System.setProperty("https.protocols", "TLSv1.2,TLSv1.3");
@@ -273,7 +273,7 @@
log.error("WebSocket登录失败, code: {}, msg: {}", code, response.getString("msg"));
}
} else if ("subscribe".equals(event)) {
- log.info("订阅成功: {}", response.getJSONObject("arg"));
+ subscribeEvent(response);
} else if ("error".equals(event)) {
log.error("订阅错误: code={}, msg={}",
response.getString("code"), response.getString("msg"));
@@ -288,6 +288,29 @@
}
}
+ private void subscribeEvent(JSONObject response) {
+ JSONObject arg = response.getJSONObject("arg");
+ if (arg == null) {
+ log.warn("无效的推送数据,缺少 'arg' 字段 :{}",response);
+ return;
+ }
+
+ String channel = arg.getString("channel");
+ if (channel == null) {
+ log.warn("无效的推送数据,缺少 'channel' 字段{}",response);
+ return;
+ }
+ if (OrderInfoWs.ORDERINFOWS_CHANNEL.equals(channel)) {
+ OrderInfoWs.initEvent(response);
+ }
+ if (AccountWs.ACCOUNTWS_CHANNEL.equals(channel)) {
+ AccountWs.initEvent(response);
+ }
+ if (PositionsWs.POSITIONSWS_CHANNEL.equals(channel)) {
+ PositionsWs.initEvent(response);
+ }
+ }
+
/**
* 解析并处理价格推送数据。
* 将最新的标记价格存入 Redis 并触发后续业务逻辑比较处理。
@@ -295,29 +318,38 @@
* @param response 包含价格数据的 JSON 对象
*/
private void processPushData(JSONObject response) {
+ String op = response.getString("op");
+ if (op != null){
+ if (TradeOrderWs.ORDERWS_CHANNEL.equals(op)) {
+ // 直接使用Object类型接收,避免强制类型转换
+ Object data = response.get("data");
+ log.info("收到下单推送结果: {}", JSON.toJSONString(data));
+ return;
+ }
+ }
JSONObject arg = response.getJSONObject("arg");
if (arg == null) {
- log.warn("无效的推送数据,缺少 'arg' 字段");
+ log.warn("无效的推送数据,缺少 'arg' 字段 :{}",response);
return;
}
String channel = arg.getString("channel");
if (channel == null) {
- log.warn("无效的推送数据,缺少 'channel' 字段");
+ log.warn("无效的推送数据,缺少 'channel' 字段{}",response);
return;
}
if (OrderInfoWs.ORDERINFOWS_CHANNEL.equals(channel)) {
OrderInfoWs.handleEvent(response, redisUtils);
}else if (AccountWs.ACCOUNTWS_CHANNEL.equals(channel)) {
- AccountWs.handleEvent(response, redisUtils);
- String side = caoZuoService.caoZuo();
- TradeOrderWs.orderEvent(webSocketClient, redisUtils, side);
+ AccountWs.handleEvent(response);
} else if (PositionsWs.POSITIONSWS_CHANNEL.equals(channel)) {
- PositionsWs.handleEvent(response, redisUtils);
+ PositionsWs.handleEvent(response);
} else if (BalanceAndPositionWs.CHANNEL_NAME.equals(channel)) {
BalanceAndPositionWs.handleEvent(response);
}
+ String side = caoZuoService.caoZuo();
+ TradeOrderWs.orderEvent(webSocketClient, side);
}
/**
--
Gitblit v1.9.1