Parcourir la source

搭建完成了。准备接通测试。

skyffire il y a 6 mois
Parent
commit
27e682f42d
4 fichiers modifiés avec 44 ajouts et 14 suppressions
  1. 1 0
      Cargo.toml
  2. 9 11
      src/exchange/mexc_spot_ws.rs
  3. 33 2
      src/main.rs
  4. 1 1
      src/utils/mod.rs

+ 1 - 0
Cargo.toml

@@ -72,6 +72,7 @@ thiserror = "1"
 # - "macros": 启用宏支持,用于 compile-time query checking (强烈推荐)
 # - "offline": 用于离线模式下的宏检查 (与 "macros" 配合使用)
 sqlx = { version = "0.7", features = ["runtime-tokio", "sqlite", "macros"] }
+backtrace = "0.3.74"
 
 # 可选项:更高级的配置管理库,如果配置结构比较复杂,可以考虑使用
 # config = "0.13"

+ 9 - 11
src/exchange/mexc_spot_ws.rs

@@ -1,3 +1,4 @@
+use std::fmt::format;
 use std::io::Read;
 use std::sync::Arc;
 use std::sync::atomic::AtomicBool;
@@ -130,20 +131,19 @@ impl MexcSpotWs {
             // 深度
             MexcSpotWsSubscribeType::PuFuturesDepth => {
                 json!({
-                    "method":"sub.depth",
-                    "param":{
-                        "symbol": symbol
-                    }
+                    "method": "SUBSCRIPTION",
+                    "param": [
+                        format!("spot@public.aggre.depth.v3.api.pb@10ms@{symbol}")
+                    ]
                 })
             }
             // k线
             MexcSpotWsSubscribeType::PuFuturesRecords(interval) => {
                 json!({
-                    "method":"sub.kline",
-                    "param":{
-                        "symbol": symbol,
-                        "interval": interval
-                    }
+                    "method": "SUBSCRIPTION",
+                    "param": [
+                        format!("spot@public.kline.v3.api.pb@{symbol}@{interval}")
+                    ]
                 })
             }
         }
@@ -287,8 +287,6 @@ impl MexcSpotWs {
                         res_data.channel = "futures.order_book".to_string();
                     } else if method.contains(".kline") {
                         res_data.channel = "futures.candlesticks".to_string();
-                    } else if method.contains(".deal") {
-                        res_data.channel = "futures.trades".to_string();
                     } else {
                         res_data.channel = "未知频道推送".to_string();
                     }

+ 33 - 2
src/main.rs

@@ -8,6 +8,37 @@ mod strategy;
 mod exchange;
 mod api;
 
-fn main() {
-    println!("Hello, world!");
+use backtrace::Backtrace;
+use std::sync::Arc;
+use std::sync::atomic::{AtomicBool, Ordering};
+use tracing::{info, warn};
+use utils::log_setup;
+use tokio::sync::Mutex;
+
+#[tokio::main]
+async fn main() {
+    let _guards = log_setup::setup_logging().unwrap();
+
+    // 主进程控制
+    let running = Arc::new(AtomicBool::new(true));
+
+    // panic错误捕获,panic级别的错误直接退出
+    let panic_running = running.clone();
+    std::panic::set_hook(Box::new(move |panic_info| {
+        let msg = format!(
+            "type=panic, msg={:?}, location={:?}",
+            panic_info.to_string(),
+            panic_info.location()
+        );
+
+        // 生成并格式化完整的堆栈跟踪
+        let backtrace = Backtrace::new();
+        let stack_trace = format!("{:?}", backtrace);
+
+        // 一并打印堆栈跟踪
+        warn!("{}\nStack Trace:\n{}", msg, stack_trace);
+        panic_running.store(false, Ordering::Relaxed);
+    }));
+
+    info!("测试完成");
 }

+ 1 - 1
src/utils/mod.rs

@@ -1,2 +1,2 @@
 mod error;
-mod log_setup;
+pub mod log_setup;