|
|
@@ -2,6 +2,7 @@ use std::collections::{BTreeMap};
|
|
|
use std::str::FromStr;
|
|
|
use chrono::NaiveDateTime;
|
|
|
use rust_decimal::Decimal;
|
|
|
+use rust_decimal::prelude::ToPrimitive;
|
|
|
use rust_decimal_macros::dec;
|
|
|
use tracing::{error, info};
|
|
|
use crate::{export_template};
|
|
|
@@ -122,7 +123,7 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
|
|
|
|
|
|
let mut bybit_exc = BybitSwapRest::new(false, account_info.clone());
|
|
|
|
|
|
- let data = bybit_exc.get_account_transaction_log(start_time*1000, end_time*1000).await;
|
|
|
+ let data = bybit_exc.get_account_transaction_log(start_time * 1000, end_time * 1000).await;
|
|
|
|
|
|
// info!("请求完成{:?}",data.clone());
|
|
|
if data.code.as_str() == "200" {
|
|
|
@@ -199,7 +200,7 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
|
|
|
count_time_list.insert(0, count_start_time);
|
|
|
count_time_list.push(count_end_time);
|
|
|
let count_balance_info = supply_balance(all_account_balance_info.clone(), count_time_list.clone());
|
|
|
- let statistic_result = statistic_balance(count_balance_info.clone(), count_start_time.clone(), count_end_time.clone());
|
|
|
+ let statistic_result = statistic_balance(count_balance_info.clone(), count_start_time.clone(), count_end_time.clone(), config_info.clone());
|
|
|
|
|
|
// 根据小时填充
|
|
|
let mut last_timestamp: i64 = -1;
|
|
|
@@ -222,7 +223,7 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-pub fn statistic_balance(balance_info: Vec<Vec<String>>, count_start_time: i64, end_start_time: i64) -> String {
|
|
|
+pub fn statistic_balance(balance_info: Vec<Vec<String>>, count_start_time: i64, end_start_time: i64, config: BalanceConfigInfo) -> String {
|
|
|
let mut max_withdrawal = dec!(0);
|
|
|
let mut max_total_withdrawal = dec!(0);
|
|
|
let mut total_income = dec!(0);
|
|
|
@@ -244,7 +245,7 @@ pub fn statistic_balance(balance_info: Vec<Vec<String>>, count_start_time: i64,
|
|
|
min_price = present_price;
|
|
|
continue;
|
|
|
}
|
|
|
- let present_withdrawal = ((Decimal::ONE - (min_price / max_price)) * dec!(100)).round_dp(2);
|
|
|
+ let present_withdrawal = ((max_price - 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 {
|
|
|
@@ -257,12 +258,13 @@ pub fn statistic_balance(balance_info: Vec<Vec<String>>, count_start_time: i64,
|
|
|
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);
|
|
|
+ total_income = ((past - present) / present * dec!(100)).round_dp(2);
|
|
|
}
|
|
|
}
|
|
|
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)
|
|
|
+ let all_income = config.start_earnings + total_income.to_f64().unwrap();
|
|
|
+ format!("总收益约为:{}%<br/>{}到{},总收益约为{}%,最大回撤约为{}%,其中单个账号最大回撤约为{}%。", all_income, start_time, end_time, total_income, max_total_withdrawal, max_withdrawal)
|
|
|
}
|
|
|
|
|
|
pub fn supply_balance(source_balance_info: BTreeMap<String, Vec<Vec<String>>>, time_slicer: Vec<i64>) -> Vec<Vec<String>> {
|