Ver código fonte

coinex 请求报错直接停机。

请求异常打印原始响应数据
JiahengHe 1 ano atrás
pai
commit
f5d8b02d52
2 arquivos alterados com 40 adições e 55 exclusões
  1. 16 35
      exchanges/src/coinex_swap_rest.rs
  2. 24 20
      standard/src/coinex_swap.rs

+ 16 - 35
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, info};
 
 #[derive(Clone)]
 pub struct CoinexSwapRest {
@@ -628,40 +628,21 @@ impl CoinexSwapRest {
         };
 
         // 读取响应的内容
-        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)
-                    }
-                }
-            }
-            Err(e) => {
-                // 异常情况
-                error!("{} 请求失败,网络错误 {}", url, e);
-                self.on_error_data(&e.to_string(), &url, &body)
-            }
-        }
+        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: Value = serde_json::from_str(text.as_str()).unwrap();
+        return if is_success && data_json["code"].to_string() == "0" {
+            self.on_success_data(data_json["data"].clone())
+        } else {
+            info!("原始http 响应数据:{}", res_json);
+            self.on_error_data(&text, &url, &body)
+        };
     }
 
     pub fn on_success_data(&mut self, text: Value) -> ResponseData {

+ 24 - 20
standard/src/coinex_swap.rs

@@ -604,28 +604,32 @@ impl Platform for CoinexSwap {
             let handle = spawn(async move {
                 // info!("数量 {},方向 {},价格 {},c_id {}", amount, side, price, cid);
                 ts.on_before_send();
-                let result = self_clone.take_order(&cid, &side, price, amount).await;
+                let mut result = self_clone.take_order(&cid, &side, price, amount).await.unwrap();
                 ts.on_after_send();
 
-                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, "触发限频, 请调整下单频率"))
-                        // }
-                    }
-                }
+                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, "触发限频, 请调整下单频率"))
+                //         // }
+                //     }
+                // }
             });
             handles.push(handle)
         }