From 900c9b20cca19df60d14b9ea61d336ba640250f0 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 11 May 2026 10:49:57 +0800
Subject: [PATCH] fix(gateApi): 修复网格交易中仓位大小更新逻辑
---
src/main/java/com/xcong/excoin/modules/gateApi/GateKlineWebSocketClient.java | 45 +++++++++++++++++++++++----------------------
1 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateKlineWebSocketClient.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateKlineWebSocketClient.java
index 14a46ba..5a5f7b0 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateKlineWebSocketClient.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateKlineWebSocketClient.java
@@ -48,6 +48,7 @@
*
* @author Administrator
*/
+@SuppressWarnings("ALL")
@Slf4j
public class GateKlineWebSocketClient {
@@ -100,7 +101,7 @@
*/
public void init() {
if (!isInitialized.compareAndSet(false, true)) {
- log.warn("[WS] already init, skip");
+ log.warn("[WS] 已初始化过,跳过重复初始化");
return;
}
connect();
@@ -113,7 +114,7 @@
* 避免 onClose 回调中的 reconnectWithBackoff 访问已关闭的线程池。
*/
public void destroy() {
- log.info("[WS] destroy...");
+ log.info("[WS] 开始销毁...");
if (webSocketClient != null && webSocketClient.isOpen()) {
for (GateChannelHandler handler : channelHandlers) {
@@ -123,7 +124,7 @@
Thread.sleep(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- log.warn("[WS] unsubscribe wait interrupted");
+ log.warn("[WS] 取消订阅等待被中断");
}
}
@@ -132,7 +133,7 @@
webSocketClient.closeBlocking();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- log.warn("[WS] close interrupted");
+ log.warn("[WS] 关闭连接时被中断");
}
}
@@ -146,7 +147,7 @@
}
shutdownExecutorGracefully(sharedExecutor);
- log.info("[WS] destroyed");
+ log.info("[WS] 销毁完成");
}
/**
@@ -155,7 +156,7 @@
*/
private void connect() {
if (isConnecting.get() || !isConnecting.compareAndSet(false, true)) {
- log.info("[WS] already connecting");
+ log.info("[WS] 连接进行中,跳过重复请求");
return;
}
try {
@@ -168,7 +169,7 @@
webSocketClient = new WebSocketClient(uri) {
@Override
public void onOpen(ServerHandshake handshake) {
- log.info("[WS] connected");
+ log.info("[WS] 连接成功");
isConnected.set(true);
isConnecting.set(false);
if (sharedExecutor != null && !sharedExecutor.isShutdown()) {
@@ -178,7 +179,7 @@
}
sendPing();
} else {
- log.warn("[WS] shutting down, ignore onOpen");
+ log.warn("[WS] 应用正在关闭,忽略连接成功回调");
}
}
@@ -191,28 +192,28 @@
@Override
public void onClose(int code, String reason, boolean remote) {
- log.warn("[WS] closed, code:{}, reason:{}", code, reason);
+ log.warn("[WS] 连接关闭, code:{}, reason:{}", code, reason);
isConnected.set(false);
isConnecting.set(false);
cancelPongTimeout();
if (sharedExecutor != null && !sharedExecutor.isShutdown() && !sharedExecutor.isTerminated()) {
sharedExecutor.execute(() -> {
- try { reconnectWithBackoff(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { log.error("[WS] reconnect fail", e); }
+ try { reconnectWithBackoff(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { log.error("[WS] 重连失败", e); }
});
} else {
- log.warn("[WS] executor closed, no reconnect");
+ log.warn("[WS] 线程池已关闭,不执行重连");
}
}
@Override
public void onError(Exception ex) {
- log.error("[WS] error", ex);
+ log.error("[WS] 发生错误", ex);
isConnected.set(false);
}
};
webSocketClient.connect();
} catch (URISyntaxException e) {
- log.error("[WS] bad uri", e);
+ log.error("[WS] URI格式错误", e);
isConnecting.set(false);
}
}
@@ -229,21 +230,21 @@
String event = response.getString("event");
if (FUTURES_PONG.equals(channel)) {
- log.debug("[WS] pong received");
+ log.debug("[WS] 收到 pong 响应");
cancelPongTimeout();
return;
}
if ("subscribe".equals(event)) {
- log.info("[WS] {} subscribed: {}", channel, response.getJSONObject("result"));
+ log.info("[WS] {} 订阅成功: {}", channel, response.getJSONObject("result"));
return;
}
if ("unsubscribe".equals(event)) {
- log.info("[WS] {} unsubscribed", channel);
+ log.info("[WS] {} 取消订阅成功", channel);
return;
}
if ("error".equals(event)) {
JSONObject error = response.getJSONObject("error");
- log.error("[WS] {} error, code:{}, msg:{}",
+ log.error("[WS] {} 错误, code:{}, msg:{}",
channel,
error != null ? error.getInteger("code") : "N/A",
error != null ? error.getString("message") : response.getString("msg"));
@@ -255,7 +256,7 @@
}
}
} catch (Exception e) {
- log.error("[WS] handle msg fail: {}", message, e);
+ log.error("[WS] 处理消息失败: {}", message, e);
}
}
@@ -286,9 +287,9 @@
pingMsg.put("time", System.currentTimeMillis() / 1000);
pingMsg.put("channel", FUTURES_PING);
webSocketClient.send(pingMsg.toJSONString());
- log.debug("[WS] ping sent");
+ log.debug("[WS] 发送 ping 请求");
}
- } catch (Exception e) { log.warn("[WS] ping fail", e); }
+ } catch (Exception e) { log.warn("[WS] 发送 ping 失败", e); }
}
private synchronized void cancelPongTimeout() {
@@ -301,9 +302,9 @@
int attempt = 0, maxAttempts = 3;
long delayMs = 5000;
while (attempt < maxAttempts) {
- try { Thread.sleep(delayMs); connect(); return; } catch (Exception e) { log.warn("[WS] reconnect attempt {} fail", attempt + 1, e); delayMs *= 2; attempt++; }
+ try { Thread.sleep(delayMs); connect(); return; } catch (Exception e) { log.warn("[WS] 第{}次重连失败", attempt + 1, e); delayMs *= 2; attempt++; }
}
- log.error("[WS] reconnect exhausted after {} attempts", maxAttempts);
+ log.error("[WS] 超过最大重试次数({}),放弃重连", maxAttempts);
}
private void shutdownExecutorGracefully(ExecutorService executor) {
--
Gitblit v1.9.1