Browse Source

tocker 的数据分析按照100毫秒聚合数据

hl 1 year ago
parent
commit
ea2fd5adb3
2 changed files with 41 additions and 16 deletions
  1. 37 11
      src/hl_pr_utile.rs
  2. 4 5
      src/main.rs

+ 37 - 11
src/hl_pr_utile.rs

@@ -15,7 +15,7 @@ use crate::struct_standard::Trades;
 use crate::swap_okx::okx_swap_standard::SwapTrades;
 use crate::utils::utils::TickerConfigInfo;
 
-pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
+pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str, time_interval: i64) {
 
     //从今天算起
     let time_this = Utc::now().timestamp_millis();
@@ -37,6 +37,14 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
             name_html = "1小时";
             (1000 * 60 * 60 * 1)
         }
+        "2H" => {
+            name_html = "2小时";
+            (1000 * 60 * 60 * 2)
+        }
+        "3H" => {
+            name_html = "3小时";
+            (1000 * 60 * 60 * 3)
+        }
         "4H" => {
             name_html = "4小时";
             (1000 * 60 * 60 * 4)
@@ -88,7 +96,7 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
         "GATE" => {
             let mut start_at_ti = start_at;
             loop {
-                let end_at_ti = start_at_ti + (20 * 60);
+                let end_at_ti = start_at_ti + time_interval;
                 if start_at_ti > end_at {
                     break;
                 }
@@ -116,8 +124,22 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
                             // {"contract": String("XRP_USDT"), "create_time": Number(1703146260.4), "create_time_ms": Number(1703146260.4), "id": Number(24663517), "price": String("0.6163"), "size": Number(132)}
                             // info!("数据:{:?}",row.clone());
                             let row_c = row.clone();
-                            let create_time = format!("{:?}", row["create_time"].as_f64().unwrap().to_i64().unwrap_or(0)).clone();
-                            let k = create_time.as_str();
+                            // let create_time = format!("{:?}", row["create_time"].as_f64().unwrap().to_i64().unwrap_or(0)).clone();
+                            // let k = create_time.as_str();
+
+                            let create_time = format!("{:?}", row["create_time"].as_f64().unwrap_or(0.0)).clone();
+                            let time_ttttt = create_time.clone();
+                            let parts: Vec<&str> = time_ttttt.split('.').collect();
+                            let seconds = parts[0].parse::<i64>().unwrap(); // 获取秒
+                            let milliseconds = if parts.len() > 1 {
+                                parts[1].parse::<u32>().unwrap_or(0) / 100
+                            } else {
+                                0
+                            };
+                            let timestamp_millis_i64 = seconds * 1000 + (milliseconds as i64) *100;
+                            let timestamp_millis_i64_string = timestamp_millis_i64.to_string(); // This is now owned and will live long enough.
+                            let k = timestamp_millis_i64_string.as_str();
+
 
                             let mut def: Vec<Value> = vec![];
                             if exchange_list.contains_key(k) {
@@ -136,7 +158,7 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
                     info!("数据请求错误:");
                     return;
                 }
-                start_at_ti = start_at_ti + (20 * 60);
+                start_at_ti = start_at_ti + time_interval ;
             }
 
             // info!("数据:{:?}",exchange_list);
@@ -146,13 +168,17 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
             let mut keys: Vec<String> = exchange_list.keys().cloned().collect();
             keys.sort_by(|&(ref a), &(ref b)| a.len().cmp(&b.len()));
             for k in keys.clone() {
-                let time_str = NaiveDateTime::from_timestamp_millis((k.clone().parse::<i64>().unwrap() + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
+                let time_str = NaiveDateTime::from_timestamp_millis(k.clone().parse::<i64>().unwrap() + 8 * 3600 * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
                 let data = exchange_list.get(k.clone().as_str()).unwrap();
                 let mut str_array = vec![""];
+                let mut ti_str = vec![""];
                 for d in data.clone() {
                     str_array.push(" - ");
+                    // ti_str.push(d.clone());
+                    info!("数据: {:?} ",d);
                 }
-                // info!("数据总数: {:?}: {:?}",time_str,str_array);
+
+                info!("数据总数: {:?}: {:?}",time_str,str_array);
 
 
                 let mut def: Vec<Value> = vec![];
@@ -196,7 +222,7 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
                 let mut initiative_ticker_info = vec![];
                 for d in data {
                     let create_time = format!("{:?}", d["create_time"].as_f64().unwrap().to_i64().unwrap_or(0)).clone();
-                    let time_str = NaiveDateTime::from_timestamp_millis((create_time.clone().parse::<i64>().unwrap() + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
+                    let time_str = NaiveDateTime::from_timestamp_millis(create_time.clone().parse::<i64>().unwrap() * 1000 + 8 * 3600 * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
 
                     initiative_ticker_info.push(time_str);
                 };
@@ -225,10 +251,10 @@ pub async fn export_ticker(symbol: &str, exchange: &str, time_str: &str) {
                     for row in rows {
                         let price = row["price"].as_str().unwrap().parse::<f64>().unwrap();
                         // info!("price:{:?} " ,price);
-                        if max_v == 0.0{
-                            max_v =   price
+                        if max_v == 0.0 {
+                            max_v = price
                         }
-                        if min_v == 0.0{
+                        if min_v == 0.0 {
                             min_v = price
                         }
 

+ 4 - 5
src/main.rs

@@ -43,13 +43,11 @@ async fn main() {
     //     let config_clone = config_obj.balance_info.clone();
     //     if http::proxy::ParsingDetail::http_enable_proxy(config_clone.proxy_address.clone()) {
     //         info!("检测有代理配置,配置走代理");
-    // }
+    //     }
     //     export_balance::export_balance(config_clone).await;
     // }
 
-
-    //根据帧 来查看数据,规则:根据当前币对选择 时间范围,的秒级 ticker 数量
-    if config_obj.ticker_info.is_export {
+    if true {
         info!("----------正在导出Ticker信息----------");
         let config_clone = config_obj.ticker_info.clone();
         if http::proxy::ParsingDetail::http_enable_proxy(config_clone.proxy_address.clone()) {
@@ -70,6 +68,7 @@ async fn main() {
         // "4Z" => (1000 * 60 * 60 * 24 * 7 * 4),
         // 提示: 1. 代码颗粒度为秒级,100毫秒与999毫秒都归纳于1秒之内,
         //       2. 不同币对成交量可能存在差异,当前查询是1000条已经是最大值,但是有点币对交易量只有几百,但是有的可能好几千,这个需要酌情调整
-        hl_pr_utile::export_ticker("XRP_USDT","GATE","30M").await;
+        //time_interval -数据请求的时间间隔 毫秒级
+        hl_pr_utile::export_ticker("BAKE_USDT", "GATE", "3H", (1 * 60)).await;
     }
 }