Parcourir la source

移除所有警告信息、让rest请求走代理。

skyffire il y a 6 mois
Parent
commit
f1a347af86

+ 2 - 2
src/data_manager.rs

@@ -24,11 +24,11 @@ impl DataManager {
         }
     }
     
-    pub async fn process_klines_map(symbol: String, depth: Value) -> Result<()> {
+    pub async fn process_klines_map(_symbol: String, _depth: Value) -> Result<()> {
         Ok(())
     }
     
-    pub async fn process_depth_data(symbol: String, depth: Value) -> Result<()> {
+    pub async fn process_depth_data(_symbol: String, _depth: Value) -> Result<()> {
         Ok(())
     }
 }

+ 11 - 6
src/exchange/mexc_spot_client.rs

@@ -8,6 +8,8 @@ use rust_decimal_macros::dec;
 use tracing::{error, trace};
 use ring::hmac;
 use serde_json::Value;
+use crate::exchange::proxy;
+use crate::exchange::proxy::ProxyEnum;
 use crate::exchange::response_base::Response;
 use crate::utils::rest_utils::RestUtils;
 
@@ -27,6 +29,9 @@ impl MexcSpotClient {
     pub fn new_with_tag(tag: String, login_param: Option<BTreeMap<String, String>>) -> MexcSpotClient {
         let base_url = "https://api.mexc.com".to_string();
 
+        // 根据环境变量配置代理
+        proxy::ParsingDetail::env_proxy(ProxyEnum::REST);
+
         MexcSpotClient {
             tag,
             base_url,
@@ -342,7 +347,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_mexc_spot_klines() {
-        let guard = setup_logging().unwrap();
+        let _guard = setup_logging().unwrap();
         let mut client = MexcSpotClient::new_with_tag("MexcSpot".to_string(), None);
 
         let params = serde_json::json!({
@@ -355,7 +360,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_mexc_spot_depth() {
-        let guard = setup_logging().unwrap();
+        let _guard = setup_logging().unwrap();
         let mut client = MexcSpotClient::new_with_tag("MexcSpot".to_string(), None);
 
         let params = serde_json::json!({
@@ -367,7 +372,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_mexc_spot_exchange_info() {
-        let guard = setup_logging().unwrap();
+        let _guard = setup_logging().unwrap();
         let mut client = MexcSpotClient::new_with_tag("MexcSpot".to_string(), None);
 
         // info!("{}", serde_json::to_string_pretty(&client.exchange_info(serde_json::Value::Null).await.data).unwrap());
@@ -380,7 +385,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_mexc_spot_default_symbols() {
-        let guard = setup_logging().unwrap();
+        let _guard = setup_logging().unwrap();
         let mut client = MexcSpotClient::new_with_tag("MexcSpot".to_string(), None);
 
         info!("{}", serde_json::to_string_pretty(&client.default_symbols().await.data).unwrap());
@@ -388,7 +393,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_mexc_spot_time() {
-        let guard = setup_logging().unwrap();
+        let _guard = setup_logging().unwrap();
         let mut client = MexcSpotClient::new_with_tag("MexcSpot".to_string(), None);
 
         info!("{}", serde_json::to_string_pretty(&client.time().await.data).unwrap());
@@ -396,7 +401,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_mexc_spot_ping() {
-        let guard = setup_logging().unwrap();
+        let _guard = setup_logging().unwrap();
         let mut client = MexcSpotClient::new_with_tag("MexcSpot".to_string(), None);
 
         info!("{}", serde_json::to_string_pretty(&client.ping().await.data).unwrap());

+ 14 - 37
src/exchange/mexc_spot_ws.rs

@@ -15,7 +15,7 @@ use tracing::{error, info, trace, warn};
 use anyhow::Result;
 
 use crate::exchange::response_base::Response;
-use crate::exchange::socket_tool::AbstractWsMode;
+use crate::exchange::socket_tool::{AbstractWsMode, HeartbeatType};
 
 //类型
 pub enum MexcSpotWsType {
@@ -30,16 +30,6 @@ pub mod mexc_spot {
 use mexc_spot::PublicSpotKlineV3ApiMessage;
 use mexc_spot::PublicIncreaseDepthsV3ApiMessage;
 
-#[derive(Debug)]
-#[derive(Clone)]
-pub struct MexcSpotWsParam {
-    pub token: String,
-    pub ws_url: String,
-    pub ws_ping_interval: i64,
-    pub ws_ping_timeout: i64,
-    pub is_ok_subscribe: bool,
-}
-
 //订阅频道
 #[derive(Clone)]
 pub enum MexcSpotWsSubscribeType {
@@ -62,9 +52,9 @@ pub enum MexcSpotWsSubscribeType {
 //账号信息
 #[derive(Clone, Debug)]
 pub struct MexcSpotWsLogin {
-    pub access_key: String,
-    pub secret_key: String,
-    pub pass_key: String,
+    // pub access_key: String,
+    // pub secret_key: String,
+    // pub pass_key: String,
 }
 
 #[derive(Clone)]
@@ -76,8 +66,6 @@ pub struct MexcSpotWs {
     address_url: String,
     //账号
     login_param: Option<MexcSpotWsLogin>,
-    //登录数据
-    ws_param: MexcSpotWsParam,
     //币对
     symbol_s: Vec<String>,
     //订阅
@@ -97,23 +85,13 @@ impl MexcSpotWs {
             }
         };
 
-        /*******公共频道-私有频道数据组装*/
-        let ws_param = MexcSpotWsParam {
-            token: "".to_string(),
-            ws_url: "".to_string(),
-            ws_ping_interval: 0,
-            ws_ping_timeout: 0,
-            is_ok_subscribe: false,
-        };
-
         MexcSpotWs {
             tag,
             address_url,
             login_param,
-            ws_param,
             symbol_s: vec![],
             subscribe_types: vec![],
-            heartbeat_time: 1000 * 18,
+            heartbeat_time: 1000 * 10,
         }
     }
 
@@ -183,7 +161,7 @@ impl MexcSpotWs {
     pub async fn ws_connect_async<F, Future>(&mut self,
                                              is_shutdown_arc: Arc<AtomicBool>,
                                              handle_function: F,
-                                             _write_tx_am: &Arc<Mutex<UnboundedSender<Message>>>,
+                                             write_tx_am: &Arc<Mutex<UnboundedSender<Message>>>,
                                              write_to_socket_rx: UnboundedReceiver<Message>) -> Result<()>
         where
             F: Fn(Response) -> Future + Clone + Send + 'static + Sync,
@@ -193,15 +171,14 @@ impl MexcSpotWs {
         let subscription = self.get_subscription();
         let address_url = self.address_url.clone();
         let tag = self.tag.clone();
-        // let heartbeat_time = self.ws_param.ws_ping_interval.clone();
-
-        //心跳-- 方法内部线程启动
-        // let write_tx_clone1 = write_tx_am.clone();
-        // tokio::spawn(async move {
-        //     trace!("线程-异步心跳-开始");
-        //     AbstractWsMode::ping_or_pong(write_tx_clone1, HeartbeatType::Ping, heartbeat_time as u64).await;
-        //     trace!("线程-异步心跳-结束");
-        // });
+
+        // 自动心跳包
+        let write_tx_clone1 = write_tx_am.clone();
+        let heartbeat_time = self.heartbeat_time.clone();
+        tokio::spawn(async move {
+            let ping_obj = json!({"method":"PING"});
+            AbstractWsMode::ping_pong(write_tx_clone1, HeartbeatType::Custom(ping_obj.to_string()), heartbeat_time).await;
+        });
 
 
         // 设置订阅

+ 73 - 75
src/exchange/proxy.rs

@@ -18,8 +18,8 @@ pub enum ProxyResponseEnum {
 #[derive(Debug)]
 #[derive(Clone)]
 pub struct ParsingDetail {
-    pub ip_address: String,
-    pub port: String,
+    // pub ip_address: String,
+    // pub port: String,
 }
 
 impl ParsingDetail {
@@ -38,12 +38,13 @@ impl ParsingDetail {
                 "".to_string()
             }
         };
+
         if ip_port.len() > 0 {
-            match proxy_enum {
+            return match proxy_enum {
                 ProxyEnum::REST => {
                     env::set_var("http_proxy", ip_port.to_string());
                     env::set_var("https_proxy", ip_port.to_string());
-                    return ProxyResponseEnum::NO;
+                    ProxyResponseEnum::NO
                 }
                 ProxyEnum::WS => {
                     let ip_port: Vec<&str> = ip_port.split(":").collect();
@@ -54,81 +55,78 @@ impl ParsingDetail {
                         ip_array[2].parse().unwrap(),
                         ip_array[3].parse().unwrap())
                     ), ip_port[1].parse().unwrap());
-                    return ProxyResponseEnum::YES(proxy);
-                }
-            }
-        }
-        return ProxyResponseEnum::NO;
-    }
-
-    fn new(ip_address: String,
-           port: String, ) -> ParsingDetail {
-        ParsingDetail { ip_address, port }
-    }
-    //获取环境变量配置'proxy_address'拿到代理地址
-    pub fn parsing_environment_variables(is_unusual: Option<&str>) -> ParsingDetail {
-        let proxy_address_name = match is_unusual {
-            None => {
-                "proxy_address"
-            }
-            Some(v) => {
-                match v {
-                    "binance" => {
-                        "binance_proxy_address"
-                    }
-                    _ => {
-                        "proxy_address"
-                    }
+                    ProxyResponseEnum::YES(proxy)
                 }
             }
-        };
-        let proxy_address = env::var(proxy_address_name);
-        // 使用std::env::var函数获取环境变量的值,如果返回Err,则说明环境变量不存在
-        match proxy_address {
-            Ok(value) => {
-                trace!("环境变量读取成功:key:proxy_address , val:{}", value);
-                let ip_port: Vec<&str> = value.split(":").collect();
-                let parsing_detail = ParsingDetail::new(ip_port[0].to_string(), ip_port[1].to_string());
-                parsing_detail
-            }
-            Err(_) => {
-                trace!("环境变量读取失败:'proxy_address'");
-                let parsing_detail = ParsingDetail::new("".to_string(), "".to_string());
-                parsing_detail
-            }
         }
-    }
 
-    //http请求是否开启代理:HTTP 只需要调用该方法即可
-    //原理是 设置全局代理,所以程序如果要走代理只需要执行一次,后续的get,post..都会走代理
-    pub fn http_enable_proxy(is_unusual: Option<&str>) -> bool {
-        //拿到环境变量解析的数据
-        let parsing_detail = Self::parsing_environment_variables(is_unusual);
-        if parsing_detail.ip_address.len() > 0 && parsing_detail.port.len() > 0 {
-            let http_proxy = format!("http://{}:{}", parsing_detail.ip_address, parsing_detail.port);
-            env::set_var("http_proxy", http_proxy.clone());
-            env::set_var("https_proxy", http_proxy.clone());
-            trace!("代理设置成功{0}", http_proxy.to_string());
-            true
-        } else {
-            trace!("无法开启代理:环境变量获取失败:{:?}", parsing_detail);
-            false
-        }
+        ProxyResponseEnum::NO
     }
 
-    pub fn removes_proxy(is_unusual: Option<&str>) -> bool {
-        //拿到环境变量解析的数据
-        let parsing_detail = Self::parsing_environment_variables(is_unusual);
-        if parsing_detail.ip_address.len() > 0 && parsing_detail.port.len() > 0 {
-            env::remove_var("http_proxy");
-            env::remove_var("https_proxy");
-            true
-        } else {
-            false
-        }
-    }
+    // fn new(ip_address: String, port: String) -> ParsingDetail {
+    //     ParsingDetail { ip_address, port }
+    // }
+    //
+    // //获取环境变量配置'proxy_address'拿到代理地址
+    // pub fn parsing_environment_variables(is_unusual: Option<&str>) -> ParsingDetail {
+    //     let proxy_address_name = match is_unusual {
+    //         None => {
+    //             "proxy_address"
+    //         }
+    //         Some(v) => {
+    //             match v {
+    //                 "binance" => {
+    //                     "binance_proxy_address"
+    //                 }
+    //                 _ => {
+    //                     "proxy_address"
+    //                 }
+    //             }
+    //         }
+    //     };
+    //     let proxy_address = env::var(proxy_address_name);
+    //     // 使用std::env::var函数获取环境变量的值,如果返回Err,则说明环境变量不存在
+    //     match proxy_address {
+    //         Ok(value) => {
+    //             trace!("环境变量读取成功:key:proxy_address , val:{}", value);
+    //             let ip_port: Vec<&str> = value.split(":").collect();
+    //             let parsing_detail = ParsingDetail::new(ip_port[0].to_string(), ip_port[1].to_string());
+    //             parsing_detail
+    //         }
+    //         Err(_) => {
+    //             trace!("环境变量读取失败:'proxy_address'");
+    //             let parsing_detail = ParsingDetail::new("".to_string(), "".to_string());
+    //             parsing_detail
+    //         }
+    //     }
+    // }
+    //
+    // //http请求是否开启代理:HTTP 只需要调用该方法即可
+    // //原理是 设置全局代理,所以程序如果要走代理只需要执行一次,后续的get,post..都会走代理
+    // pub fn http_enable_proxy(is_unusual: Option<&str>) -> bool {
+    //     //拿到环境变量解析的数据
+    //     let parsing_detail = Self::parsing_environment_variables(is_unusual);
+    //     if parsing_detail.ip_address.len() > 0 && parsing_detail.port.len() > 0 {
+    //         let http_proxy = format!("http://{}:{}", parsing_detail.ip_address, parsing_detail.port);
+    //         env::set_var("http_proxy", http_proxy.clone());
+    //         env::set_var("https_proxy", http_proxy.clone());
+    //         trace!("代理设置成功{0}", http_proxy.to_string());
+    //         true
+    //     } else {
+    //         trace!("无法开启代理:环境变量获取失败:{:?}", parsing_detail);
+    //         false
+    //     }
+    // }
+    //
+    // pub fn removes_proxy(is_unusual: Option<&str>) -> bool {
+    //     //拿到环境变量解析的数据
+    //     let parsing_detail = Self::parsing_environment_variables(is_unusual);
+    //     if parsing_detail.ip_address.len() > 0 && parsing_detail.port.len() > 0 {
+    //         env::remove_var("http_proxy");
+    //         env::remove_var("https_proxy");
+    //         true
+    //     } else {
+    //         false
+    //     }
+    // }
 }
-
-
-
-

+ 18 - 195
src/exchange/socket_tool.rs

@@ -1,4 +1,3 @@
-use std::net::{IpAddr, Ipv4Addr, SocketAddr};
 use std::sync::Arc;
 use std::sync::atomic::{AtomicBool, Ordering};
 use std::time::Duration;
@@ -6,9 +5,7 @@ use std::time::Duration;
 use chrono::Utc;
 use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
 use futures_util::{future, pin_mut, SinkExt, StreamExt};
-use futures_util::stream::{SplitSink, SplitStream};
-use ring::hmac;
-use serde_json::{json, Value};
+use serde_json::{Value};
 use tokio::net::TcpStream;
 use tokio::sync::Mutex;
 use tokio::time::Instant;
@@ -22,8 +19,8 @@ use crate::exchange::response_base::Response;
 
 #[derive(Debug)]
 pub enum HeartbeatType {
-    Ping,
-    Pong,
+    // Ping,
+    // Pong,
     Custom(String),
 }
 
@@ -112,7 +109,7 @@ impl AbstractWsMode {
                             handle_function(data_c).await;
                         }
                         -200 => {
-                            //登录成功
+                            // 登录成功
                             info!("ws登录成功:{:?}", data);
                             if is_first_login {
                                 for s in &subscribe_array {
@@ -128,7 +125,7 @@ impl AbstractWsMode {
                             // trace!("订阅成功:{:?}", data);
                         }
                         -300 => {
-                            //服务器发送心跳 ping 给客户端,客户端需要pong回应
+                            // 服务器发送心跳 ping 给客户端,客户端需要pong回应
                             trace!("服务器响应-ping");
                             if data.data != Value::Null {
                                 let mut ws_write = ws_write_inner.lock().await;
@@ -137,7 +134,7 @@ impl AbstractWsMode {
                             }
                         }
                         -301 => {
-                            //服务器发送心跳 pong 给客户端,客户端需要ping回应
+                            // 服务器发送心跳 pong 给客户端,客户端需要ping回应
                             trace!("服务器响应-pong");
                             if data.data != Value::Null {
                                 let mut ws_write = ws_write_inner.lock().await;
@@ -146,7 +143,7 @@ impl AbstractWsMode {
                             }
                         }
                         -302 => {
-                            //客户端收到服务器心跳自定义,需要响应自定义
+                            // 客户端收到服务器心跳自定义,需要响应自定义
                             trace!("特定字符心跳,特殊响应:{:?}", data);
                             let mut ws_write = ws_write_inner.lock().await;
                             ws_write.send(Message::Text(data.data.to_string())).await?;
@@ -185,8 +182,7 @@ impl AbstractWsMode {
               F: Fn(Response) -> Future + Clone,
               Future: future::Future<Output=()> + Send + 'static,
     {
-        //1.是否走代理
-        /*******走代理:根据环境变量配置来决定,如果配置了走代理,没有配置不走*******/
+        // 1.是否走代理
         let proxy = match proxy::ParsingDetail::env_proxy(ProxyEnum::WS) {
             ProxyResponseEnum::NO => {
                 // trace!("非 代理");
@@ -220,19 +216,19 @@ impl AbstractWsMode {
         }
     }
 
-    //心跳包
-    pub async fn ping_or_pong(write_tx_clone: Arc<Mutex<UnboundedSender<Message>>>, h_type: HeartbeatType, millis: u64) {
+    // 自动心跳包
+    pub async fn ping_pong(write_tx_clone: Arc<Mutex<UnboundedSender<Message>>>, h_type: HeartbeatType, millis: u64) {
         loop {
             tokio::time::sleep(Duration::from_millis(millis)).await;
             let write_tx_clone = write_tx_clone.lock().await;
             match write_tx_clone.unbounded_send(
                 match h_type {
-                    HeartbeatType::Ping => {
-                        Message::Ping(Vec::from("Ping"))
-                    }
-                    HeartbeatType::Pong => {
-                        Message::Pong(Vec::from("Pong"))
-                    }
+                    // HeartbeatType::Ping => {
+                    //     Message::Ping(Vec::from("Ping"))
+                    // }
+                    // HeartbeatType::Pong => {
+                    //     Message::Pong(Vec::from("Pong"))
+                    // }
                     HeartbeatType::Custom(ref str) => {
                         Message::Text(str.parse().unwrap())
                     }
@@ -245,22 +241,10 @@ impl AbstractWsMode {
                     error!("发送失败:原因{:?}",k)
                 }
             }
-            // write_tx_clone.unbounded_send(
-            //     match h_type {
-            //         HeartbeatType::Ping => {
-            //             Message::Ping(Vec::from("Ping"))
-            //         }
-            //         HeartbeatType::Pong => {
-            //             Message::Pong(Vec::from("Pong"))
-            //         }
-            //         HeartbeatType::Custom(ref str) => {
-            //             Message::Text(str.parse().unwrap())
-            //         }
-            //     }
-            // ).expect("发送失败");
         }
     }
-    //数据解析
+
+    // 数据解析
     pub fn analysis_message<T, PI, PO, B>(message: Result<Message, Error>,
                                           message_text: T,
                                           message_ping: PI,
@@ -294,165 +278,4 @@ impl AbstractWsMode {
             }
         }
     }
-    //发送数据
-    pub async fn send_subscribe(write_tx_clone: Arc<Mutex<UnboundedSender<Message>>>, message: Message) -> bool {
-        let write_tx_clone = write_tx_clone.lock().await;
-        write_tx_clone.unbounded_send(message.clone()).unwrap();
-        trace!("发送指令:{:?}",message);
-        true
-    }
-}
-
-//创建链接
-pub async fn ws_connect_async(address_url: String) -> (SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>,
-                                                       SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>) {
-    //1.是否走代理
-    /*******走代理:根据环境变量配置来决定,如果配置了走代理,没有配置不走*******/
-    let proxy = match proxy::ParsingDetail::env_proxy(ProxyEnum::WS) {
-        ProxyResponseEnum::NO => {
-            trace!("非代理");
-            None
-        }
-        ProxyResponseEnum::YES(proxy) => {
-            trace!("代理");
-            Option::from(proxy)
-        }
-    };
-
-    let (ws_stream, _) = connect_async(address_url, proxy).await.expect("链接失败!");
-    trace!("WebSocket 握手完成。");
-    ws_stream.split()
-}
-
-
-pub async fn client(add_url: String) {
-    let proxy = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(
-        127,
-        0,
-        0,
-        1)
-    ), 7890);
-
-
-    //创建通道 开启线程,向通道写入数据
-    let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
-    let (read_tx, read_rx) = futures_channel::mpsc::unbounded();
-    tokio::spawn(write_sell(write_tx));
-
-
-    //创建socket,并且读写分离
-    let (ws_stream, _) = connect_async(add_url, Option::from(proxy)).await.expect("Failed to connect");
-    trace!("WebSocket handshake has been successfully completed");
-    let (write, read) = ws_stream.split();
-
-    //将socket 的写操作与 写通道链接起来,将数据以ok的结构体封装进行传递
-    let stdin_to_ws = write_rx.map(Ok).forward(write);
-    let ws_to_stdout = {
-        trace!("---1");
-        //读,循环读取,然后拿到 message,,然后开启异步处理 message,
-        let result = read.for_each(|message| async {
-            read_tx.unbounded_send(message.unwrap()).unwrap();
-        });
-        trace!("---3");
-        result
-    };
-
-    tokio::spawn(read_sell(read_rx));
-
-    //必须操作。,因为不同于其他的高级语言,有自动内存管理,所以为了防范地址改变,所以需要做此处理
-    pin_mut!(stdin_to_ws, ws_to_stdout);
-    future::select(stdin_to_ws, ws_to_stdout).await;
-}
-
-
-//模拟 业务场景中 发送指令给目标交易所
-async fn write_sell(tx: UnboundedSender<Message>) {
-    let _str = json!({
-                "op": "subscribe",
-                "args": [
-                    {
-                        // "channel":"orders",
-                        // "instType":"SWAP",
-                        // "instFamily":"BTC-USDT"
-                        "channel":"books5",
-                        "instId":"BTC-USDT"
-                    }
-                ]
-            });
-    let str_array: Vec<String> = vec![
-        // log_in_to_str(),
-        // str.to_string(),
-    ];
-
-    let i = 0;
-    loop {
-        if str_array.len() > i {
-            let send_str = str_array.get(i).unwrap();
-            tx.unbounded_send(Message::Text(send_str.to_string())).unwrap();
-        }
-        tokio::time::sleep(Duration::from_secs(5)).await;
-        tx.unbounded_send(Message::Ping(Vec::from("Ping"))).unwrap();
-        tx.unbounded_send(Message::Ping(Vec::from("Pong"))).unwrap();
-    }
-}
-
-async fn read_sell(mut rx: UnboundedReceiver<Message>) {
-    loop {
-        if let Some(message) = rx.next().await {
-            match message {
-                Message::Text(s) => {
-                    trace!("Text: {}", s);
-                }
-                Message::Binary(s) => {
-                    trace!("Binary: {:?}", s);
-                }
-                Message::Ping(s) => {
-                    trace!("Ping: {:?}", s);
-                }
-                Message::Pong(s) => {
-                    trace!("Pong: {:?}", s);
-                }
-                Message::Close(s) => {
-                    trace!("Close: {:?}", s);
-                }
-                Message::Frame(s) => {
-                    trace!("Frame: {:?}", s);
-                }
-            }
-        }
-        tokio::time::sleep(Duration::from_millis(1)).await
-    }
 }
-
-pub fn log_in_to_str() -> String {
-    let mut login_json_str = "".to_string();
-
-    let access_key: String = "".to_string();
-    let secret_key: String = "".to_string();
-    let passphrase: String = "".to_string();
-
-    if access_key.len() > 0 || secret_key.len() > 0 || passphrase.len() > 0 {
-        let timestamp = Utc::now().timestamp().to_string();
-        // 时间戳 + 请求类型+ 请求参数字符串
-        let message = format!("{}GET{}", timestamp, "/users/self/verify");
-        let hmac_key = ring::hmac::Key::new(hmac::HMAC_SHA256, secret_key.as_bytes());
-        let result = ring::hmac::sign(&hmac_key, &message.as_bytes());
-        let sign = base64::encode(result);
-
-        let login_json = json!({
-            "op": "login",
-            "args": [{
-                "apiKey": access_key,
-                "passphrase": passphrase,
-                "timestamp": timestamp,
-                "sign": sign
-            }]
-        });
-
-        // trace!("---login_json:{0}", login_json.to_string());
-        // trace!("--登录:{}", login_json.to_string());
-        login_json_str = login_json.to_string();
-    }
-
-    login_json_str
-}

+ 3 - 37
src/utils/rest_utils.rs

@@ -1,14 +1,6 @@
-use crate::exchange::response_base::Response;
-
-#[derive(Clone)]
-pub struct RestUtils {
-}
+pub struct RestUtils {}
 
 impl RestUtils {
-    pub fn new() -> RestUtils {
-        RestUtils { }
-    }
-    
     pub fn parse_params_to_str(parameters: String) -> String {
         let mut params_str = String::from("");
         let parsed_json: serde_json::Value = serde_json::from_str(&parameters).unwrap();
@@ -19,39 +11,13 @@ impl RestUtils {
                     serde_json::Value::String(s) => s.clone(),
                     _ => value.to_string()
                 };
-                
+
                 let str = format!("{}={}", key, formatted_value);
                 let format_str = format!("{}{}{}", params_str, (if params_str.len() > 0 { "&" } else { "" }), str);
                 params_str = format_str;
             }
         }
-        
-        params_str.to_string()
-    }
-    
-    pub fn res_data_analysis(result: Result<Response, reqwest::Error>) -> Response {
-        match result {
-            Ok(res_data) => {
-                if res_data.code != 0 {
-                    res_data
-                } else {
-                    let json_value= res_data.data;
 
-                    let code = json_value["code"].as_str().unwrap();
-                    let data = serde_json::to_string(&json_value["data"]).unwrap();
-                    let msg = json_value["msg"].as_str().unwrap();
-
-                    let success = Response::new("".to_string(),
-                                                    code.parse().unwrap(),
-                                                    msg.parse().unwrap(),
-                                                    data.parse().unwrap());
-                    success
-                }
-            }
-            Err(err) => {
-                let error = Response::error("".to_string(),format!("json 解析失败:{}", err));
-                error
-            }
-        }
+        params_str.to_string()
     }
 }

+ 2 - 1
src/ws_manager.rs

@@ -8,7 +8,6 @@ use tracing::{error, info};
 use crate::data_manager::DataManager;
 use crate::exchange::mexc_spot_ws::{MexcSpotWs, MexcSpotWsSubscribeType, MexcSpotWsType};
 use crate::exchange::response_base::Response;
-use crate::utils::log_setup::setup_logging;
 
 pub struct WsManager {
     pub symbols: Vec<String>,
@@ -37,6 +36,8 @@ impl WsManager {
                 error!("{}", serde_json::to_string_pretty(&response.data).unwrap());
             }
 
+            // info!("{}", serde_json::to_string_pretty(&response.data).unwrap());
+
             async move {}
         };