skyffire il y a 1 an
Parent
commit
05ecd2a95d
2 fichiers modifiés avec 41 ajouts et 35 suppressions
  1. 37 31
      exchanges/src/socket_tool.rs
  2. 4 4
      global/src/trace_stack.rs

+ 37 - 31
exchanges/src/socket_tool.rs

@@ -13,7 +13,7 @@ use tokio::net::TcpStream;
 use tokio::sync::Mutex;
 use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};
 use tokio_tungstenite::tungstenite::{Error, Message};
-use tracing::{trace};
+use tracing::{info, trace};
 
 use crate::proxy;
 use crate::proxy::{ProxyEnum, ProxyResponseEnum};
@@ -93,9 +93,42 @@ impl AbstractWsMode {
                             let response_data = AbstractWsMode::analysis_message(message, message_text, message_ping, message_pong);
                             // let response_data = func(message);
                             if response_data.is_some() {
-                                let mut data = response_data.unwrap();
-                                data.time = chrono::Utc::now().timestamp_micros();
-                                data.label = lable.clone();
+                                let data = response_data.unwrap();
+
+                                if data.code == "200" {
+                                    let mut data_c = data.clone();
+                                    data_c.time = chrono::Utc::now().timestamp_micros();
+                                    data_c.label = lable.clone();
+
+                                    if data_c.label.contains("gate_usdt_swap") {
+                                        if data_c.channel == "futures.order_book" {
+                                            if read_tx.len() == 0 {
+                                                read_tx.unbounded_send(data_c).unwrap();
+                                            }
+                                        } else {
+                                            read_tx.unbounded_send(data_c).unwrap();
+                                        }
+                                    } else if data_c.label.contains("binance_usdt_swap") {
+                                        if data_c.channel == "bookTicker" {
+                                            if read_tx.len() == 0 {
+                                                read_tx.unbounded_send(data_c).unwrap();
+                                            }
+                                        } else {
+                                            read_tx.unbounded_send(data_c).unwrap();
+                                        }
+                                    } else if data_c.label.contains("bybit_usdt_swap") {
+                                        if data_c.channel == "orderbook" {
+                                            if read_tx.len() == 0 {
+                                                read_tx.unbounded_send(data_c).unwrap();
+                                            }
+                                        } else {
+                                            read_tx.unbounded_send(data_c).unwrap();
+                                        }
+                                    } else {
+                                        read_tx.unbounded_send(data_c).unwrap();
+                                    }
+                                }
+
                                 let code = data.code.clone();
                                 /*
                                     200 -正确返回
@@ -107,33 +140,6 @@ impl AbstractWsMode {
                                 */
                                 match code.as_str() {
                                     "200" => {
-                                        if data.label.contains("gate_usdt_swap") {
-                                            if data.channel == "futures.order_book" {
-                                                if read_tx.is_empty() {
-                                                    read_tx.unbounded_send(data).unwrap();
-                                                }
-                                            } else {
-                                                read_tx.unbounded_send(data).unwrap();
-                                            }
-                                        } else if data.label.contains("binance_usdt_swap") {
-                                            if data.channel == "bookTicker" {
-                                                if read_tx.is_empty() {
-                                                    read_tx.unbounded_send(data).unwrap();
-                                                }
-                                            } else {
-                                                read_tx.unbounded_send(data).unwrap();
-                                            }
-                                        } else if data.label.contains("bybit_usdt_swap") {
-                                            if data.channel == "orderbook" {
-                                                if read_tx.is_empty() {
-                                                    read_tx.unbounded_send(data).unwrap();
-                                                }
-                                            } else {
-                                                read_tx.unbounded_send(data).unwrap();
-                                            }
-                                        } else {
-                                            read_tx.unbounded_send(data).unwrap();
-                                        }
                                     }
                                     "-200" => {
                                         //登录成功

+ 4 - 4
global/src/trace_stack.rs

@@ -97,6 +97,10 @@ impl fmt::Display for TraceStack {
             msg.push_str(format!("订单来源:{} ", self.source).as_str());
         }
 
+        if self.after_network != 0 && self.before_send != 0 {
+            msg.push_str(format!("本地总耗时{}微秒  ", self.before_send - self.after_network).as_str());
+        }
+
         if self.before_network != 0 && self.after_network != 0 {
             msg.push_str(format!("数据生成+到达rust耗时{}毫秒  ", (self.after_network - self.before_network).to_f64().unwrap() / 1000.0).as_str());
         }
@@ -121,10 +125,6 @@ impl fmt::Display for TraceStack {
             msg.push_str(format!("发送订单耗时(发送-服务器处理-响应到本地){}毫秒  ", (self.after_send - self.before_send).to_f64().unwrap() / 1000.0).as_str());
         }
 
-        if self.after_network != 0 && self.before_send != 0 {
-            msg.push_str(format!("本地总耗时{}微秒  ", self.before_send - self.after_network).as_str());
-        }
-
         if self.after_send != 0 && self.after_network != 0 {
             msg.push_str(format!("总共耗时{}毫秒", (self.after_send - self.after_network).to_f64().unwrap() / 1000.0).as_str());
         }