fix(binance): 修复 K 线 WebSocket 断开后无法重连导致 openPrice/closePrice 丢失的问题
当 WebSocket 因网络问题断开时,updateSubscriptions() 只检查订阅集合是否相同, 未检查连接是否真的存在,导致断开后无法重连。 现在会额外检查需要的连接是否都存在,如果缺失则重新建立连接。 Made-with: Cursor
This commit is contained in:
+6
-1
@@ -91,7 +91,12 @@ class BinanceKlineService {
|
|||||||
}
|
}
|
||||||
}.toSet()
|
}.toSet()
|
||||||
val wsKeysNeeded = parsed.map { (_, symbol, interval) -> "$symbol-$interval" }.toSet()
|
val wsKeysNeeded = parsed.map { (_, symbol, interval) -> "$symbol-$interval" }.toSet()
|
||||||
if (normalized == requiredMarketPrefixes.get()) return
|
|
||||||
|
// 检查是否有需要的 WebSocket 连接缺失(可能因网络问题断开)
|
||||||
|
val hasMissingConnection = wsKeysNeeded.any { it !in connectedWebSockets.keys }
|
||||||
|
|
||||||
|
// 只有当集合相同且所有需要的连接都存在时才跳过
|
||||||
|
if (normalized == requiredMarketPrefixes.get() && !hasMissingConnection) return
|
||||||
requiredMarketPrefixes.set(normalized)
|
requiredMarketPrefixes.set(normalized)
|
||||||
synchronized(subscriptionLock) {
|
synchronized(subscriptionLock) {
|
||||||
connectedWebSockets.keys.toList().forEach { wsKey ->
|
connectedWebSockets.keys.toList().forEach { wsKey ->
|
||||||
|
|||||||
Reference in New Issue
Block a user