From 1b55621d4dcf3b4ee6b9c4beb81ad69e5b7a5856 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Fri, 05 Jun 2026 17:58:08 +0800
Subject: [PATCH] refactor(okxNewPrice): 优化止损管理器的挂单数量计算逻辑

---
 src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxGridWsClient.java |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxGridWsClient.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxGridWsClient.java
index da664ba..8d5329b 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxGridWsClient.java
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxGridWsClient.java
@@ -38,10 +38,10 @@
 
     private static final int HEARTBEAT_TIMEOUT = 10;
 
-    /** 模拟盘公共 WS 地址 */
-    private static final String WS_PUBLIC_URL_SIM = "wss://wspap.okx.com:8443/ws/v5/public";
-    /** 实盘公共 WS 地址 */
-    private static final String WS_PUBLIC_URL_PROD = "wss://ws.okx.com:8443/ws/v5/public";
+    /** 模拟盘业务 WS 地址(K线等行情数据) */
+    private static final String WS_BUSINESS_URL_SIM = "wss://wspap.okx.com:8443/ws/v5/business";
+    /** 实盘业务 WS 地址(K线等行情数据) */
+    private static final String WS_BUSINESS_URL_PROD = "wss://ws.okx.com:8443/ws/v5/business";
     /** 模拟盘私有 WS 地址 */
     private static final String WS_PRIVATE_URL_SIM = "wss://wspap.okx.com:8443/ws/v5/private";
     /** 实盘私有 WS 地址 */
@@ -119,9 +119,9 @@
             System.setProperty("https.protocols", "TLSv1.2,TLSv1.3");
             String wsUrl;
             if (account.isAccountType()) {
-                wsUrl = isPublic ? WS_PUBLIC_URL_PROD : WS_PRIVATE_URL_PROD;
+                wsUrl = isPublic ? WS_BUSINESS_URL_PROD : WS_PRIVATE_URL_PROD;
             } else {
-                wsUrl = isPublic ? WS_PUBLIC_URL_SIM : WS_PRIVATE_URL_SIM;
+                wsUrl = isPublic ? WS_BUSINESS_URL_SIM : WS_PRIVATE_URL_SIM;
             }
             URI uri = new URI(wsUrl);
 
@@ -171,6 +171,7 @@
                     isConnected.set(false);
                 }
             };
+            webSocketClient.setConnectionLostTimeout(0);
             webSocketClient.connect();
         } catch (URISyntaxException e) {
             log.error("[{}] URI格式错误", logPrefix, e);
@@ -212,6 +213,10 @@
 
     private void handleMessage(String message) {
         try {
+            if ("pong".equals(message)) {
+                log.debug("[{}] 收到 pong", logPrefix);
+                return;
+            }
             JSONObject response = JSON.parseObject(message);
             String event = response.getString("event");
             String op = response.getString("op");
@@ -224,6 +229,21 @@
 
             if ("subscribe".equals(event) || "unsubscribe".equals(event)) {
                 log.info("[{}] {}事件: {}", logPrefix, event, response.getString("arg"));
+                // 订阅成功确认:解析频道名并通知对应 handler
+                if ("subscribe".equals(event)) {
+                    JSONObject argObj = response.getJSONObject("arg");
+                    if (argObj != null) {
+                        String channel = argObj.getString("channel");
+                        if (channel != null) {
+                            for (OkxGridChannelHandler handler : channelHandlers) {
+                                if (channel.equals(handler.getChannelName())) {
+                                    handler.onSubscribed();
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
                 return;
             }
 

--
Gitblit v1.9.1