Jelajahi Sumber

回滚coinex至3.5.0

JiahengHe 1 tahun lalu
induk
melakukan
8ffd7ddff2
2 mengubah file dengan 49 tambahan dan 45 penghapusan
  1. 29 21
      exchanges/src/coinex_swap_rest.rs
  2. 20 24
      standard/src/coinex_swap.rs

+ 29 - 21
exchanges/src/coinex_swap_rest.rs

@@ -10,7 +10,7 @@ use serde_json::Value;
 use crate::http_tool::RestTool;
 use crate::response_base::ResponseData;
 use sha2::{Digest, Sha256};
-use tracing::error;
+use tracing::{error};
 
 #[derive(Clone)]
 pub struct CoinexSwapRest {
@@ -628,29 +628,37 @@ impl CoinexSwapRest {
         };
 
         // 读取响应的内容
-        let response = request_builder.send().await.unwrap();
-        // 原始响应数据
-        let res_json = format!("url: {}, response: {:?}", url, response);
-        // info!("url: {}, http响应:response: {:?}", url, response);
-        let is_success = response.status().is_success(); // 先检查状态码
-
-        let text = response.text().await.unwrap();
-
-        let data_json_str: Result<Value, serde_json::Error> = serde_json::from_str(text.as_str());
-        match data_json_str {
-            Ok(data_json) => {
-                return if is_success && data_json["code"].to_string() == "0" {
-                    self.on_success_data(data_json["data"].clone())
-                } else {
-                    // 3103 是订单不存在
-                    if data_json["code"].to_string() != "3103" {
-                        error!("请求成功,code码异常。原始http 响应数据:{}, text: {}", res_json, text);
+        let res = request_builder.send().await;
+        match res {
+            Ok(response) => {
+                let is_success = response.status().is_success(); // 先检查状态码
+                let text_result = response.text().await;
+                match text_result {
+                    Ok(text) => {
+                        let data_json_str: Result<Value, serde_json::Error> = serde_json::from_str(text.as_str());
+                        match data_json_str {
+                            Ok(data_json) => {
+                                return if is_success && data_json["code"].to_string() == "0" {
+                                    self.on_success_data(data_json["data"].clone())
+                                } else {
+                                    self.on_error_data(&text, &url, &body)
+                                }
+                            }
+                            Err(e) => {
+                                error!("{} 请求完成,解析响应内容JSON失败 {} {}", url, text.as_str(), e);
+                                self.on_error_data(&e.to_string(), &url, &body)
+                            }
+                        }
+                    }
+                    Err(e) => {
+                        error!("{} 请求完成,解析响应内容失败 {}", url, e);
+                        self.on_error_data(&e.to_string(), &url, &body)
                     }
-                    self.on_error_data(&text, &url, &body)
-                };
+                }
             }
             Err(e) => {
-                error!("请求成功,响应数据异常。原始http 响应数据:{}, text: {}", res_json, text);
+                // 异常情况
+                error!("{} 请求失败,网络错误 {}", url, e);
                 self.on_error_data(&e.to_string(), &url, &body)
             }
         }

+ 20 - 24
standard/src/coinex_swap.rs

@@ -604,32 +604,28 @@ impl Platform for CoinexSwap {
             let handle = spawn(async move {
                 // info!("数量 {},方向 {},价格 {},c_id {}", amount, side, price, cid);
                 ts.on_before_send();
-                let mut result = self_clone.take_order(&cid, &side, price, amount).await.unwrap();
+                let result = self_clone.take_order(&cid, &side, price, amount).await;
                 ts.on_after_send();
 
-                result.trace_stack = ts;
-                // info!("数量 {},方向 {},价格 {},c_id {}", amount, side, price, cid);
-                self_clone.order_sender.send(result).await.unwrap();
-
-                // match result {
-                //     Ok(mut result) => {
-                //         result.trace_stack = ts;
-                //         // info!("数量 {},方向 {},价格 {},c_id {}", amount, side, price, cid);
-                //         self_clone.order_sender.send(result).await.unwrap();
-                //     }
-                //     Err(error) => {
-                //         let mut err_order = Order::new();
-                //         err_order.custom_id = cid.clone();
-                //         err_order.status = "REMOVE".to_string();
-                //         info!("coinex下单error 数量: {},方向: {},价格: {},c_id: {}, err: {}", amount, side, price, cid, error);
-                //         self_clone.order_sender.send(err_order).await.unwrap();
-                //         self_clone.error_sender.send(error).await.unwrap();
-                //         // 触发限频
-                //         // if error_info.to_string().contains("213:Please don't try too frequently") {
-                //         //     Err(Error::new(ErrorKind::Other, "触发限频, 请调整下单频率"))
-                //         // }
-                //     }
-                // }
+                match result {
+                    Ok(mut result) => {
+                        result.trace_stack = ts;
+                        // info!("数量 {},方向 {},价格 {},c_id {}", amount, side, price, cid);
+                        self_clone.order_sender.send(result).await.unwrap();
+                    }
+                    Err(error) => {
+                        let mut err_order = Order::new();
+                        err_order.custom_id = cid.clone();
+                        err_order.status = "REMOVE".to_string();
+                        // info!("coinex下单error 数量: {},方向: {},价格: {},c_id: {}, err: {}", amount, side, price, cid, error);
+                        self_clone.order_sender.send(err_order).await.unwrap();
+                        self_clone.error_sender.send(error).await.unwrap();
+                        // 触发限频
+                        // if error_info.to_string().contains("213:Please don't try too frequently") {
+                        //     Err(Error::new(ErrorKind::Other, "触发限频, 请调整下单频率"))
+                        // }
+                    }
+                }
             });
             handles.push(handle)
         }