|
@@ -1,81 +1,89 @@
|
|
|
-use std::collections::{BTreeMap, HashSet};
|
|
|
|
|
-use std::str::FromStr;
|
|
|
|
|
|
|
+use std::collections::{BTreeMap};
|
|
|
use chrono::NaiveDateTime;
|
|
use chrono::NaiveDateTime;
|
|
|
-
|
|
|
|
|
use tracing::info;
|
|
use tracing::info;
|
|
|
|
|
+use crate::{export_template};
|
|
|
|
|
+use crate::swap_gate::gate_swap_rest_utils::GateSwapRest;
|
|
|
|
|
+use crate::utils::utils::BalanceConfigInfo;
|
|
|
|
|
|
|
|
-use crate::{export, utils};
|
|
|
|
|
-use crate::gate_swap::gate_swap_rest_utils::GateSwapRest;
|
|
|
|
|
-
|
|
|
|
|
-pub async fn creation_account_book_html(start_time: i64) {
|
|
|
|
|
- let config = utils::utils::get_config_info("./config.toml");
|
|
|
|
|
-
|
|
|
|
|
|
|
+pub async fn export_balance(config_info: BalanceConfigInfo) {
|
|
|
|
|
+ let config_info_clone = config_info.clone();
|
|
|
|
|
+ let start_time = NaiveDateTime::parse_from_str(&config_info.range_time[0].clone(), "%Y-%m-%d %H:%M:%S").unwrap().timestamp() - 8 * 3600;
|
|
|
|
|
+ let end_time = NaiveDateTime::parse_from_str(&config_info.range_time[1].clone(), "%Y-%m-%d %H:%M:%S").unwrap().timestamp() - 8 * 3600;
|
|
|
|
|
|
|
|
//获取不同账号的数据
|
|
//获取不同账号的数据
|
|
|
- let mut acc_array: Vec<BTreeMap<String, String>> = vec![];
|
|
|
|
|
let mut acc_all_data: BTreeMap<String, Vec<Vec<String>>> = BTreeMap::new();
|
|
let mut acc_all_data: BTreeMap<String, Vec<Vec<String>>> = BTreeMap::new();
|
|
|
- let mut acc_all_data_clone: BTreeMap<String, Vec<Vec<String>>> = BTreeMap::new();
|
|
|
|
|
let mut data_array_all: Vec<Vec<String>> = vec![];
|
|
let mut data_array_all: Vec<Vec<String>> = vec![];
|
|
|
- let mut acc_name_all: Vec<String> = vec![];
|
|
|
|
|
- let mut time_all: Vec<i64> = vec![];
|
|
|
|
|
|
|
+ let mut account_name_list: Vec<String> = vec![];
|
|
|
loop {
|
|
loop {
|
|
|
- let mut gate60: BTreeMap<String, String> = BTreeMap::new();
|
|
|
|
|
- gate60.insert("acc_name".to_string(), String::from(""));
|
|
|
|
|
- gate60.insert("access_key".to_string(), String::from(""));
|
|
|
|
|
- gate60.insert("secret_key".to_string(), String::from(""));
|
|
|
|
|
- acc_array.push(gate60);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if acc_array.len() == 0 {
|
|
|
|
|
|
|
+ if config_info_clone.account_list.len() == 0 {
|
|
|
info!("没有账号信息");
|
|
info!("没有账号信息");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ for account in config_info_clone.account_list.clone() {
|
|
|
|
|
+ let mut account_info: BTreeMap<String, String> = BTreeMap::new();
|
|
|
|
|
+ account_info.insert("account_name".to_string(), account[0].clone());
|
|
|
|
|
+ account_info.insert("access_key".to_string(), account[1].clone());
|
|
|
|
|
+ account_info.insert("secret_key".to_string(), account[2].clone());
|
|
|
|
|
|
|
|
- for acc in acc_array {
|
|
|
|
|
- let mut gate_exc = GateSwapRest::new(false, acc.clone());
|
|
|
|
|
- let data = gate_exc.account_book("usdt".to_string(),start_time).await;
|
|
|
|
|
- info!("请求完成{:?}",data.clone());
|
|
|
|
|
|
|
+ let mut gate_exc = GateSwapRest::new(false, account_info.clone());
|
|
|
|
|
+ let data = gate_exc.account_book("usdt".to_string()).await;
|
|
|
|
|
+ // info!("请求完成{:?}",data.clone());
|
|
|
if data.code.as_str() == "200" {
|
|
if data.code.as_str() == "200" {
|
|
|
- let acc_name = acc.get("acc_name").unwrap().clone();
|
|
|
|
|
- acc_name_all.push(acc_name.clone());
|
|
|
|
|
|
|
+ let account_name = account_info.get("account_name").unwrap();
|
|
|
|
|
+ account_name_list.push(account_name.clone());
|
|
|
|
|
|
|
|
//账号
|
|
//账号
|
|
|
let json_value: serde_json::Value = serde_json::from_str(&data.data).unwrap();
|
|
let json_value: serde_json::Value = serde_json::from_str(&data.data).unwrap();
|
|
|
if let serde_json::Value::Array(array) = json_value {
|
|
if let serde_json::Value::Array(array) = json_value {
|
|
|
let mut name_data_all: Vec<Vec<String>> = vec![];
|
|
let mut name_data_all: Vec<Vec<String>> = vec![];
|
|
|
- let mut name_data_all_clone: Vec<Vec<String>> = vec![];
|
|
|
|
|
let mut times = 0;
|
|
let mut times = 0;
|
|
|
|
|
|
|
|
for item in array {
|
|
for item in array {
|
|
|
let time = item["time"].as_i64().unwrap();//秒级
|
|
let time = item["time"].as_i64().unwrap();//秒级
|
|
|
- if time == times{ continue;}
|
|
|
|
|
|
|
+ if time == times { continue; }
|
|
|
times = time;
|
|
times = time;
|
|
|
|
|
|
|
|
- time_all.push(time);
|
|
|
|
|
- // let time_str = NaiveDateTime::from_timestamp_millis((time + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
|
|
- // info!("{:?}数据时间解析:{:?}",acc_name.clone(),time_str);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
let change = item["change"].as_str().unwrap();
|
|
let change = item["change"].as_str().unwrap();
|
|
|
|
|
|
|
|
let balance = item["balance"].as_str().unwrap();
|
|
let balance = item["balance"].as_str().unwrap();
|
|
|
let type_str = match item["type"].as_str().unwrap() {
|
|
let type_str = match item["type"].as_str().unwrap() {
|
|
|
- "dnw" => { "转入转出" ;continue; }
|
|
|
|
|
|
|
+ "dnw" => {
|
|
|
|
|
+ "转入转出";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
"pnl" => { "减仓盈亏" }
|
|
"pnl" => { "减仓盈亏" }
|
|
|
- "fee" => { "交易手续费";continue; }
|
|
|
|
|
- "refr" => { "推荐人返佣" ;continue;}
|
|
|
|
|
- "fund" => { "资金费用";continue; }
|
|
|
|
|
- "point_dnw" => { "点卡转入转出" ;continue;}
|
|
|
|
|
- "point_fee" => { "点卡交易手续费" ;continue;}
|
|
|
|
|
- "point_refr" => { "点卡推荐人返佣";continue; }
|
|
|
|
|
|
|
+ "fee" => {
|
|
|
|
|
+ "交易手续费";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ "refr" => {
|
|
|
|
|
+ "推荐人返佣";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ "fund" => {
|
|
|
|
|
+ "资金费用";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ "point_dnw" => {
|
|
|
|
|
+ "点卡转入转出";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ "point_fee" => {
|
|
|
|
|
+ "点卡交易手续费";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ "point_refr" => {
|
|
|
|
|
+ "点卡推荐人返佣";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
_ => {
|
|
_ => {
|
|
|
- "未知-变更类型";continue;
|
|
|
|
|
|
|
+ "未知-变更类型";
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
let text = item["text"].as_str().unwrap();
|
|
let text = item["text"].as_str().unwrap();
|
|
|
let contract = item["contract"].as_str().unwrap();
|
|
let contract = item["contract"].as_str().unwrap();
|
|
|
let trade_id = item["trade_id"].as_str().unwrap();
|
|
let trade_id = item["trade_id"].as_str().unwrap();
|
|
@@ -91,7 +99,7 @@ pub async fn creation_account_book_html(start_time: i64) {
|
|
|
|
|
|
|
|
name_data_all.push(name_data_array.clone());
|
|
name_data_all.push(name_data_array.clone());
|
|
|
}
|
|
}
|
|
|
- acc_all_data.insert(acc_name.clone(), name_data_all.clone());
|
|
|
|
|
|
|
+ acc_all_data.insert(account_name.clone(), name_data_all.clone());
|
|
|
} else {
|
|
} else {
|
|
|
info!("不是数组 检查数据");
|
|
info!("不是数组 检查数据");
|
|
|
}
|
|
}
|
|
@@ -100,16 +108,20 @@ pub async fn creation_account_book_html(start_time: i64) {
|
|
|
}
|
|
}
|
|
|
break;//这里是为了 代码收纳,用了loop来放置代码
|
|
break;//这里是为了 代码收纳,用了loop来放置代码
|
|
|
}
|
|
}
|
|
|
- // info!("数据如下:{:?}",acc_all_data);
|
|
|
|
|
|
|
|
|
|
- //1. 生成时间片
|
|
|
|
|
- let mut unique = HashSet::new();
|
|
|
|
|
- time_all.retain(|e| unique.insert(*e));
|
|
|
|
|
- time_all.sort_by(|a, b| a.cmp(&b));
|
|
|
|
|
- // info!("数据如下1:{:?}",time_all);
|
|
|
|
|
|
|
+ // 按小时取时间片
|
|
|
|
|
+ let mut last_timestamp: i64 = -1;
|
|
|
|
|
+ let mut export_time_list: Vec<i64> = vec![];
|
|
|
|
|
+ for item in start_time..end_time {
|
|
|
|
|
+ if item / 3600 != last_timestamp / 3600 {
|
|
|
|
|
+ last_timestamp = item;
|
|
|
|
|
+ export_time_list.push(last_timestamp);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ export_time_list.push(end_time);
|
|
|
|
|
|
|
|
//2. 数据根据时间片 补全数据
|
|
//2. 数据根据时间片 补全数据
|
|
|
- for time in &time_all {
|
|
|
|
|
|
|
+ for time in &export_time_list {
|
|
|
// 根据时间片去拿数据 ,如果有添加没有,手动添加
|
|
// 根据时间片去拿数据 ,如果有添加没有,手动添加
|
|
|
let mut sum_pr: f64 = 0 as f64;
|
|
let mut sum_pr: f64 = 0 as f64;
|
|
|
for (key, vale) in acc_all_data.clone() {
|
|
for (key, vale) in acc_all_data.clone() {
|
|
@@ -130,7 +142,6 @@ pub async fn creation_account_book_html(start_time: i64) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // info!("数据如下2:{:?}",time_all);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//如果匹配到时间片,直接使用,没有则创建
|
|
//如果匹配到时间片,直接使用,没有则创建
|
|
@@ -150,7 +161,6 @@ pub async fn creation_account_book_html(start_time: i64) {
|
|
|
let mut acc_balance = "0".to_string();
|
|
let mut acc_balance = "0".to_string();
|
|
|
let acc_type = "填补数据类型".to_string();
|
|
let acc_type = "填补数据类型".to_string();
|
|
|
let mut acc_contract = "填补数据类型".to_string();
|
|
let mut acc_contract = "填补数据类型".to_string();
|
|
|
- let acc_text = "填补数据类型".to_string();
|
|
|
|
|
|
|
|
|
|
if filter_arrya.len() > 0 {
|
|
if filter_arrya.len() > 0 {
|
|
|
// info!("{:?}--{}--{:?}",acc_name, time, filter_arrya[filter_arrya.len() - 1].clone());
|
|
// info!("{:?}--{}--{:?}",acc_name, time, filter_arrya[filter_arrya.len() - 1].clone());
|
|
@@ -178,7 +188,7 @@ pub async fn creation_account_book_html(start_time: i64) {
|
|
|
row
|
|
row
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
- let time_str = NaiveDateTime::from_timestamp_millis((new_d[1].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((new_d[1].clone().parse::<i64>().unwrap() + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
// info!("{:?}----时间片:{:?}",new_d[0].clone(),time_str);
|
|
// info!("{:?}----时间片:{:?}",new_d[0].clone(),time_str);
|
|
|
// info!("计算3333:---{:?}",time_str);
|
|
// info!("计算3333:---{:?}",time_str);
|
|
|
// info!("{:?}=----pr:{:?}",key.clone().to_string(),new_d[4].clone());
|
|
// info!("{:?}=----pr:{:?}",key.clone().to_string(),new_d[4].clone());
|
|
@@ -195,30 +205,15 @@ pub async fn creation_account_book_html(start_time: i64) {
|
|
|
sum_row.push("".to_string());
|
|
sum_row.push("".to_string());
|
|
|
sum_row.push("".to_string());
|
|
sum_row.push("".to_string());
|
|
|
data_array_all.push(sum_row.clone());
|
|
data_array_all.push(sum_row.clone());
|
|
|
- let time_str2 = NaiveDateTime::from_timestamp_millis((time + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
|
|
- // info!("------------------计算111:-----{:?}",time_str2);
|
|
|
|
|
}
|
|
}
|
|
|
- // println!("数据如下:{:?}", data_array_all);
|
|
|
|
|
|
|
|
|
|
- // info!("时间片:{:?}",time_all.clone());
|
|
|
|
|
- // info!("时间片长度:{:?}---数据节点长度{:?}", time_all.clone().len(),data_array_all.clone().len());
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //限制时间之外的数据过滤
|
|
|
|
|
- let start_time_str = NaiveDateTime::from_timestamp_millis((start_time + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
|
|
- let time_all_array: Vec<i64> = time_all.clone().into_iter().filter(|s| {
|
|
|
|
|
- s >= &start_time
|
|
|
|
|
|
|
+ let data_array_all_array: Vec<Vec<String>> = data_array_all.clone().into_iter().filter(|value| {
|
|
|
|
|
+ let t = value[1].clone().parse::<i64>().unwrap();
|
|
|
|
|
+ t >= start_time && t <= end_time
|
|
|
}).collect();
|
|
}).collect();
|
|
|
- time_all = time_all_array;
|
|
|
|
|
-
|
|
|
|
|
- let time_all_array: Vec<Vec<String>> = data_array_all.clone().into_iter().filter(|s| {
|
|
|
|
|
- let t = s[1].clone().parse::<i64>().unwrap();
|
|
|
|
|
- t >= start_time
|
|
|
|
|
- }).collect();
|
|
|
|
|
- data_array_all = time_all_array;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ data_array_all = data_array_all_array;
|
|
|
|
|
|
|
|
//生成 html
|
|
//生成 html
|
|
|
- acc_name_all.push("sum_acc".to_string());
|
|
|
|
|
- export::htmlzz::export_html(config.clone(), &acc_name_all, &time_all, &data_array_all);
|
|
|
|
|
|
|
+ account_name_list.push("sum_acc".to_string());
|
|
|
|
|
+ export_template::template_balance::export_html(config_info_clone.clone(), &account_name_list, &export_time_list, &data_array_all);
|
|
|
}
|
|
}
|