Răsfoiți Sursa

修复k线信息解析错误的bug。

skyffire 6 luni în urmă
părinte
comite
81f3ab169b
4 a modificat fișierele cu 8 adăugiri și 17 ștergeri
  1. 2 2
      proto/mexc_spot_kline_v3.proto
  2. 2 2
      src/exchange/mexc_spot_ws.rs
  3. 1 10
      src/main.rs
  4. 3 3
      src/ws_manager.rs

+ 2 - 2
proto/mexc_spot_kline_v3.proto

@@ -40,8 +40,8 @@ message PublicSpotKlineV3ApiMessage {
   string id_info = 4;
   // Tag 5 可能是一个时间戳或版本号,根据值大小和你的需要定义类型
   // 1745894084490 看起来像毫秒时间戳 (或者其他什么)
-  // 如果需要解析为数字,改为 sint64 或 int64。如果不需要深入解析,可以仍然定义为 bytes 或 string
-  sint64 timestamp_or_version = 5; // 假设它是一个 sint64
+  // 如果需要解析为数字,使用sint会覆盖不了,所以要用int64。如果不需要深入解析,可以仍然定义为 bytes 或 string
+  int64 timestamp = 5;
 
   // Tag 308 是包含实际 K 线数据的嵌套消息
   KlineDataV3 kline_data = 308; // <-- 这里的 Tag 编号是 308,类型是我们上面定义的 KlineDataV3 消息

+ 2 - 2
src/exchange/mexc_spot_ws.rs

@@ -279,7 +279,7 @@ impl MexcSpotWs {
                                     "topic_info": kline_message.topic_info,
                                     "symbol": kline_message.symbol,
                                     "id_info": kline_message.id_info,
-                                    "timestamp_or_version": kline_message.timestamp_or_version,
+                                    "timestamp": kline_message.timestamp,
                                 })
                         );
                         return Some(response_data);
@@ -294,7 +294,7 @@ impl MexcSpotWs {
                                 "topic_info": kline_message.topic_info,
                                 "symbol": kline_message.symbol,
                                 "id_info": kline_message.id_info,
-                                "timestamp_or_version": kline_message.timestamp_or_version,
+                                "timestamp": kline_message.timestamp,
                             })
                         ));
                     }

+ 1 - 10
src/main.rs

@@ -120,16 +120,7 @@ pub async fn run_mexc_subscriptions(
     // 调用过滤函数,注意现在传入的是 &Value
     let filtered_map = process_exchange_info(&default_symbols_response.data, &exchange_info_response.data)?;
     info!("成功过滤并转换了交易对信息,最终数量: {}", filtered_map.len());
-    // 使用 filtered_map...
-    if let Some(symbol_info) = filtered_map.get("BTCUSDT") { // 示例
-        let pretty_info = serde_json::to_string_pretty(symbol_info).unwrap_or_else(|e| format!("序列化错误: {}", e));
-        info!("BTCUSDT 的信息: {}", pretty_info);
-    } else if !filtered_map.is_empty() {
-        if let Some((first_key, first_value)) = filtered_map.iter().next() {
-            let pretty_info = serde_json::to_string_pretty(first_value).unwrap_or_else(|e| format!("序列化错误: {}", e));
-            info!("过滤后 map 中的第一个交易对 '{}' 的信息: {}", first_key, pretty_info);
-        }
-    } else {
+    if filtered_map.is_empty() {
         return Err(anyhow!("未能获取到任何有效的交易对,请检查网络或 API 接口。"));
     }
 

+ 3 - 3
src/ws_manager.rs

@@ -18,7 +18,7 @@ pub struct WsManager {
 impl WsManager {
     pub fn new(symbols: Vec<String>, data_manager_am: Arc<Mutex<DataManager>>, running: Arc<AtomicBool>) -> WsManager {
         WsManager {
-            symbols,
+            symbols: symbols[0..1].to_owned(),
             data_manager_am,
             running
         }
@@ -48,7 +48,7 @@ impl WsManager {
 
             // 获取当前批次的交易对
             let current_batch_symbols = self.symbols[start_index..end_index].to_vec();
-            info!("正在创建 [{}, {}) 的连接...", start_index, end_index);
+            info!("正在创建 {:?} 的连接...", current_batch_symbols);
 
             // 这个通道主要是为了后面给这个ws发送消息
             let (write_tx, write_rx) = futures_channel::mpsc::unbounded::<Message>();
@@ -60,7 +60,7 @@ impl WsManager {
                 let mut ws = MexcSpotWs::new_with_tag("Mexc".to_string(), None, MexcSpotWsType::PublicAndPrivate);
                 ws.set_subscribe(vec![
                     MexcSpotWsSubscribeType::PuFuturesRecords("Min1".to_string()),
-                    MexcSpotWsSubscribeType::PuFuturesDepth
+                    // MexcSpotWsSubscribeType::PuFuturesDepth
                 ]);
 
                 ws.set_symbols(current_batch_symbols);