|
|
@@ -1,9 +1,10 @@
|
|
|
+use std::cmp::min;
|
|
|
use std::collections::{BTreeMap};
|
|
|
use std::str::FromStr;
|
|
|
use chrono::NaiveDateTime;
|
|
|
use rust_decimal::Decimal;
|
|
|
use rust_decimal_macros::dec;
|
|
|
-use tracing::info;
|
|
|
+use tracing::{error, info};
|
|
|
use crate::{export_template};
|
|
|
use crate::swap_gate::gate_swap_rest_utils::GateSwapRest;
|
|
|
use crate::utils::utils::BalanceConfigInfo;
|
|
|
@@ -128,18 +129,22 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
|
|
|
|
|
|
// 根据小时填充
|
|
|
let mut last_timestamp: i64 = -1;
|
|
|
- let mut export_time_list: Vec<i64> = vec![];
|
|
|
+ let mut hour_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);
|
|
|
+ hour_time_list.push(last_timestamp);
|
|
|
}
|
|
|
}
|
|
|
- export_time_list.push(end_time);
|
|
|
- let all_balance_info: Vec<Vec<String>> = supply_balance(all_account_balance_info.clone(), export_time_list.clone());
|
|
|
+ hour_time_list.push(end_time);
|
|
|
+ let all_balance_info: Vec<Vec<String>> = supply_balance(all_account_balance_info.clone(), hour_time_list.clone());
|
|
|
|
|
|
account_name_list.push("total_balance".to_string());
|
|
|
- export_template::template_balance::export_html(config_info_clone.clone(), &account_name_list, &export_time_list, &all_balance_info, statistic_result);
|
|
|
+ match config_info_clone.export_mode {
|
|
|
+ 1 => export_template::template_balance::export_html(config_info, &account_name_list, &hour_time_list, &all_balance_info, statistic_result),
|
|
|
+ 2 => export_template::template_balance::export_html(config_info, &account_name_list, &count_time_list, &count_balance_info, statistic_result),
|
|
|
+ _ => error!("导出模式错误,请检查导出模式!")
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -155,25 +160,34 @@ pub fn statistic_balance(balance_info: Vec<Vec<String>>, count_start_time: i64,
|
|
|
balance_info_map.insert(info[0].clone(), default_info);
|
|
|
}
|
|
|
for (account_name, balance_info) in balance_info_map.clone() {
|
|
|
+ let mut max_price = dec!(0);
|
|
|
+ let mut min_price = dec!(0);
|
|
|
+ let mut withdrawal = dec!(0);
|
|
|
for (index, info) in balance_info.iter().enumerate() {
|
|
|
- if index == 0 { continue; }
|
|
|
- let present = Decimal::from_str(&info[4]).unwrap();
|
|
|
- let past = Decimal::from_str(&balance_info[index - 1][4]).unwrap();
|
|
|
- let withdrawal = ((Decimal::ONE - (present / past)) * dec!(100)).round_dp(2);
|
|
|
- if account_name != "total_balance" {
|
|
|
- if max_withdrawal < withdrawal { max_withdrawal = withdrawal }
|
|
|
- } else {
|
|
|
- if max_total_withdrawal < withdrawal { max_total_withdrawal = withdrawal }
|
|
|
+ let present_price = Decimal::from_str(&info[4]).unwrap();
|
|
|
+ if index == 0 || max_price < present_price {
|
|
|
+ max_price = present_price;
|
|
|
+ min_price = present_price;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ let present_withdrawal = ((Decimal::ONE - (min_price / max_price)) * dec!(100)).round_dp(2);
|
|
|
+ if present_withdrawal > withdrawal { withdrawal = present_withdrawal }
|
|
|
+
|
|
|
+ if max_price > present_price && present_price < min_price {
|
|
|
+ min_price = present_price;
|
|
|
}
|
|
|
}
|
|
|
- if account_name == "total_balance" {
|
|
|
+ if account_name != "total_balance" {
|
|
|
+ if max_withdrawal < withdrawal { max_withdrawal = withdrawal }
|
|
|
+ } else {
|
|
|
+ max_total_withdrawal = withdrawal;
|
|
|
let present = Decimal::from_str(&balance_info[0][4]).unwrap();
|
|
|
let past = Decimal::from_str(&balance_info[balance_info.len() - 1][4]).unwrap();
|
|
|
total_income = (((past / present) - Decimal::ONE) * dec!(100)).round_dp(2);
|
|
|
}
|
|
|
}
|
|
|
- let start_time = NaiveDateTime::from_timestamp_millis((count_start_time + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d日%H点").to_string();
|
|
|
- let end_time = NaiveDateTime::from_timestamp_millis((end_start_time + 8 * 3600) * 1000).unwrap().format("%Y-%m-%d日%H点").to_string();
|
|
|
+ let start_time = NaiveDateTime::from_timestamp_millis((count_start_time + 8 * 3600) * 1000).unwrap().format("%d日%H点").to_string();
|
|
|
+ let end_time = NaiveDateTime::from_timestamp_millis((end_start_time + 8 * 3600) * 1000).unwrap().format("%d日%H点").to_string();
|
|
|
format!("{}到{},总收益约为{}%,最大回撤约为{}%,其中单个账号最大回撤约为{}%。", start_time, end_time, total_income, max_total_withdrawal, max_withdrawal)
|
|
|
}
|
|
|
|