875428575@qq.com 2 年 前
コミット
d0207a3d78
3 ファイル変更25 行追加17 行削除
  1. 1 1
      exchanges/Cargo.toml
  2. 18 10
      exchanges/src/okx_swap_ws.rs
  3. 6 6
      exchanges/tests/test.rs

+ 1 - 1
exchanges/Cargo.toml

@@ -30,4 +30,4 @@ tokio-tungstenite = "0.14"
 ##日志
 global = { path="../global" }
 tracing = "0.1"
-tracing-subscriber = "0.3.17"
+tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

+ 18 - 10
exchanges/src/okx_swap_ws.rs

@@ -53,18 +53,18 @@ impl OkxSwapWs {
     /*******************************************************************************************************/
     /*****************************************获取一个对象****************************************************/
     /*******************************************************************************************************/
-    pub  fn new(is_colo: bool,
-                     login_param: BTreeMap<String, String>,
-                     ws_type: OkxWsType,
-                     sender: Sender<ResponseData>,
+    pub fn new(is_colo: bool,
+               login_param: BTreeMap<String, String>,
+               ws_type: OkxWsType,
+               sender: Sender<ResponseData>,
     ) -> OkxSwapWs
     {
         return OkxSwapWs::new_label("default-OkxSwapWs".to_string(), is_colo, login_param, ws_type, sender);
     }
-    pub  fn new_label(label: String, is_colo: bool,
-                           login_param: BTreeMap<String, String>,
-                           ws_type: OkxWsType,
-                           sender: Sender<ResponseData>,
+    pub fn new_label(label: String, is_colo: bool,
+                     login_param: BTreeMap<String, String>,
+                     ws_type: OkxWsType,
+                     sender: Sender<ResponseData>,
     ) -> OkxSwapWs
     {
         if is_colo {
@@ -309,7 +309,7 @@ impl OkxSwapWs {
 
     //非代理
     async fn subscription(&self, mut web_socket: WebSocket<AutoStream>,
-                    subscription: String)
+                          subscription: String)
     {
         let lable = self.label.clone();
         /*****订阅***/
@@ -350,6 +350,8 @@ impl OkxSwapWs {
     //数据解析
     pub fn ok_text(lable: String, text: String) -> ResponseData
     {
+
+        println!("?????{}",text);
         let mut res_data = ResponseData::new(lable, "200".to_string(), "success".to_string(), "".to_string());
         let json_value: serde_json::Value = serde_json::from_str(&text).unwrap();
         if json_value.get("event").is_some() {//订阅返回
@@ -363,7 +365,13 @@ impl OkxSwapWs {
                 res_data.data = text
             }
         } else {
-            res_data.data = text
+            if json_value.get("arg").is_some() && json_value.get("data").is_some() {
+                res_data.channel = json_value["arg"]["channel"].to_string();
+                res_data.data = json_value["data"].to_string();
+            }else{
+                res_data.data = text;
+                res_data.channel = "未知频道".to_string();
+            }
         }
         res_data
     }

+ 6 - 6
exchanges/tests/test.rs

@@ -58,7 +58,7 @@ async fn test_import() {
     //okx - Business 频道
     // demo_ws_okx_bu().await;
     //okx - public 频道
-    // demo_ws_okx_pu().await;
+    demo_ws_okx_pu().await;
 
 
     // demo_so();
@@ -66,8 +66,8 @@ async fn test_import() {
 
 async fn demo_ws_gate() {
     let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
-    btree_map.insert("access_key".to_string(), "4181c882718a95e72122ac1d52c88533".to_string());
-    btree_map.insert("secret_key".to_string(), "de82d1507b843ff08d81a0e9b878b721359f274937216b307834b570b676fa3c".to_string());
+    btree_map.insert("access_key".to_string(), "".to_string());
+    btree_map.insert("secret_key".to_string(), "".to_string());
     let (tx, mut rx) = channel(1024);
 
     let mut gate_ws = GateSwapWs::new(false, btree_map,
@@ -188,9 +188,9 @@ async fn demo_ws_okx_bu() {
 
 async fn demo_ws_kucoin_pr() {
     let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
-    btree_map.insert("access_key".to_string(), "6393f3565f0d4500011f846b".to_string());
-    btree_map.insert("secret_key".to_string(), "9c0df8b7-daaa-493e-a53a-82703067f7dd".to_string());
-    btree_map.insert("pass_key".to_string(), "b87d055f".to_string());
+    btree_map.insert("access_key".to_string(), "".to_string());
+    btree_map.insert("secret_key".to_string(), "".to_string());
+    btree_map.insert("pass_key".to_string(), "".to_string());
     trace!("----------------------btree_map{:?}", btree_map.clone());
     let (tx, mut rx) = channel(1024);
     let mut ku_ws = KuconinSwapWs::new(false, btree_map.clone(),