|
|
@@ -1,8 +1,10 @@
|
|
|
use std::fs::File;
|
|
|
use std::io::Write;
|
|
|
use std::str::FromStr;
|
|
|
+use chrono::NaiveDateTime;
|
|
|
use handlebars::Handlebars;
|
|
|
use rust_decimal::Decimal;
|
|
|
+use rust_decimal::prelude::ToPrimitive;
|
|
|
use rust_decimal_macros::dec;
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
use tracing::info;
|
|
|
@@ -24,16 +26,19 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
for exchange_info in export_info.clone().into_iter() {
|
|
|
name_list.push(format!("'{}'", exchange_info.name));
|
|
|
}
|
|
|
- let start_time = Decimal::from_str(start_at).unwrap() * dec!(1000);
|
|
|
- let end_time = Decimal::from_str(end_at).unwrap() * dec!(1000);
|
|
|
+
|
|
|
+ let start_time_d = Decimal::from_str(start_at).unwrap() * dec!(1000);
|
|
|
+ let end_time_d = Decimal::from_str(end_at).unwrap() * dec!(1000);
|
|
|
+ let start_time = NaiveDateTime::from_timestamp_millis(start_time_d.to_i64().unwrap()).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
+ let end_time = NaiveDateTime::from_timestamp_millis(end_time_d.to_i64().unwrap()).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
|
|
|
let data = serde_json::json!({
|
|
|
"chart_title": format!("{} Ticker数据", name_list.join("、").replace("'","")),
|
|
|
"legend_data": format!("[{}]", name_list.join(", ")),
|
|
|
"export_info": export_info.clone(),
|
|
|
- "symbol": symbol,
|
|
|
- "start_at": NaiveDateTime::from_timestamp_millis(start_time.to_i64().unwrap()).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string(),
|
|
|
- "end_at": NaiveDateTime::from_timestamp_millis(end_time.to_i64().unwrap()).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string()
|
|
|
+ "symbol": symbol.to_uppercase(),
|
|
|
+ "start_at": start_time,
|
|
|
+ "end_at": end_time
|
|
|
});
|
|
|
// HTML 模板
|
|
|
let template = r#"
|
|
|
@@ -46,9 +51,14 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.10/dayjs.min.js"></script>
|
|
|
|
|
|
<style>
|
|
|
- #main{
|
|
|
- width:1200px;
|
|
|
- height: 500px;
|
|
|
+ * {
|
|
|
+ margin: 0;
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+ #main {
|
|
|
+ margin: 50px auto 0;
|
|
|
+ width: calc(100vw - 100px);
|
|
|
+ height: calc(100vh - 100px);
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
@@ -77,6 +87,7 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
formatter: function (params) {
|
|
|
if (params.value.length > 1) {
|
|
|
var time = dayjs(params.value[0]).format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
|
+ var side = params.value[2] > 0 ? "Buy" : "Sell"
|
|
|
return (
|
|
|
params.seriesName +
|
|
|
' :<br/>' +
|
|
|
@@ -84,7 +95,13 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
time +
|
|
|
' <br/>' +
|
|
|
'价格: ' +
|
|
|
- params.value[1]
|
|
|
+ params.value[1] +
|
|
|
+ ' <br/>' +
|
|
|
+ '数量: ' +
|
|
|
+ params.value[2] +
|
|
|
+ ' <br/>' +
|
|
|
+ '买卖方向: ' +
|
|
|
+ side
|
|
|
);
|
|
|
}
|
|
|
},
|
|
|
@@ -101,7 +118,7 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
feature: {
|
|
|
dataZoom: {},
|
|
|
brush: {
|
|
|
- type: ['rect', 'polygon', 'clear']
|
|
|
+ type: ['rect', 'clear']
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
@@ -132,9 +149,6 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
scale: true,
|
|
|
axisLabel: {
|
|
|
formatter: '{value}'
|
|
|
- },
|
|
|
- splitLine: {
|
|
|
- show: false
|
|
|
}
|
|
|
}
|
|
|
],
|
|
|
@@ -148,7 +162,7 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
},
|
|
|
data:[
|
|
|
{{#each ticker_info}}
|
|
|
- [{{create_time}},{{price}}],
|
|
|
+ [{{create_time}},{{price}},{{size}}],
|
|
|
{{/each}}
|
|
|
],
|
|
|
markArea: {
|