ソースを参照

Merge branch 'framework_3.0' of http://git.skyfffire.com/skyfffire/as-rust into framework_3.0

JiahengHe 1 年間 前
コミット
2a69ae8198
2 ファイル変更45 行追加49 行削除
  1. 21 29
      exchanges/src/coinex_swap_rest.rs
  2. 24 20
      standard/src/coinex_swap.rs

+ 21 - 29
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,37 +628,29 @@ 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)
+        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);
                     }
-                }
+                    self.on_error_data(&text, &url, &body)
+                };
             }
             Err(e) => {
-                // 异常情况
-                error!("{} 请求失败,网络错误 {}", url, e);
+                error!("请求成功,响应数据异常。原始http 响应数据:{}, text: {}", res_json, text);
                 self.on_error_data(&e.to_string(), &url, &body)
             }
         }

+ 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!("err 数量 {},方向 {},价格 {},c_id {}", amount, side, price, cid);
-                        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)
         }