|
|
@@ -3,6 +3,7 @@ use std::str::FromStr;
|
|
|
use actix_web::HttpResponse;
|
|
|
use chrono::Utc;
|
|
|
use rust_decimal::Decimal;
|
|
|
+use rust_decimal_macros::dec;
|
|
|
use serde_json::{json, Value};
|
|
|
use crate::db_connector::{get_records_json, get_symbols_json};
|
|
|
use crate::server::Response;
|
|
|
@@ -33,6 +34,9 @@ fn calc_total_volume(records: Value) -> Decimal {
|
|
|
total_volume = total_volume + Decimal::from_str(record["volume"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
}
|
|
|
|
|
|
+ total_volume = total_volume / dec!(1e6);
|
|
|
+ total_volume.rescale(2);
|
|
|
+
|
|
|
total_volume
|
|
|
}
|
|
|
|
|
|
@@ -69,7 +73,7 @@ pub async fn get_symbols(_mode: &str, exchanges: &Vec<String>, minute_time_range
|
|
|
// 2. 如果是多交易所,则获取所有交易所的交集
|
|
|
let mut symbols: Vec<String> = get_public_symbols(&symbols_map);
|
|
|
// 确保有足够的元素
|
|
|
- let n = 50;
|
|
|
+ let n = 10;
|
|
|
// 获取前20个元素,如果不足20个,则获取全部
|
|
|
let top_symbols = if symbols.len() > n {
|
|
|
&symbols[0..n]
|
|
|
@@ -141,10 +145,16 @@ pub async fn get_symbols(_mode: &str, exchanges: &Vec<String>, minute_time_range
|
|
|
for symbol in &symbols {
|
|
|
let mut rise = json!({});
|
|
|
let mut volume = json!({});
|
|
|
+ let mut total_volume_by_symbol = Decimal::ZERO;
|
|
|
for exchange in exchanges {
|
|
|
rise[exchange] = json!(calc_rise_percentage(records_map[symbol][exchange].clone()));
|
|
|
- volume[exchange] = json!(calc_total_volume(records_map[symbol][exchange].clone()));
|
|
|
+ let volume_by_exchange = calc_total_volume(records_map[symbol][exchange].clone());
|
|
|
+ volume[exchange] = json!(volume_by_exchange);
|
|
|
+
|
|
|
+ total_volume_by_symbol = total_volume_by_symbol + volume_by_exchange;
|
|
|
}
|
|
|
+ volume["total"] = json!(total_volume_by_symbol);
|
|
|
+
|
|
|
let value = json!({
|
|
|
"symbol": symbol.clone(),
|
|
|
"rise": rise,
|