|
@@ -16,6 +16,13 @@ pub struct ExportExchangeTickerInfo {
|
|
|
pub ticker_info: Vec<Trades>,
|
|
pub ticker_info: Vec<Trades>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
|
|
|
+pub struct SeriesInfo {
|
|
|
|
|
+ pub name: String,
|
|
|
|
|
+ pub symbol: String,
|
|
|
|
|
+ pub data: Vec<Trades>,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, start_at: &str, end_at: &str, export_path: Option<&str>, export_name: Option<&str>) {
|
|
pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, start_at: &str, end_at: &str, export_path: Option<&str>, export_name: Option<&str>) {
|
|
|
info!("正在生成网页,请稍后!");
|
|
info!("正在生成网页,请稍后!");
|
|
|
let path = format!("{}/{}.html", export_path.unwrap_or("./"), export_name.unwrap_or("export")).replace("//", "/");
|
|
let path = format!("{}/{}.html", export_path.unwrap_or("./"), export_name.unwrap_or("export")).replace("//", "/");
|
|
@@ -32,13 +39,21 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
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 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 end_time = NaiveDateTime::from_timestamp_millis(end_time_d.to_i64().unwrap()).unwrap().format("%Y-%m-%d %H:%M:%S%.3f").to_string();
|
|
|
|
|
|
|
|
|
|
+ let chart_symbol_list = vec!["circle", "triangle", "roundRect", "diamond", "pin", "arrow"];
|
|
|
|
|
+ let series_info: Vec<_> = export_info.iter().enumerate().map(|(index, item)| {
|
|
|
|
|
+ SeriesInfo {
|
|
|
|
|
+ name: item.name.clone(),
|
|
|
|
|
+ symbol: chart_symbol_list[index].to_string(),
|
|
|
|
|
+ data: item.ticker_info.clone(),
|
|
|
|
|
+ }
|
|
|
|
|
+ }).collect();
|
|
|
let data = serde_json::json!({
|
|
let data = serde_json::json!({
|
|
|
"chart_title": format!("{} Ticker数据", name_list.join("、").replace("'","")),
|
|
"chart_title": format!("{} Ticker数据", name_list.join("、").replace("'","")),
|
|
|
"legend_data": format!("[{}]", name_list.join(", ")),
|
|
"legend_data": format!("[{}]", name_list.join(", ")),
|
|
|
- "export_info": export_info.clone(),
|
|
|
|
|
|
|
+ "series_info": series_info.clone(),
|
|
|
"symbol": symbol.to_uppercase(),
|
|
"symbol": symbol.to_uppercase(),
|
|
|
"start_at": start_time,
|
|
"start_at": start_time,
|
|
|
- "end_at": end_time
|
|
|
|
|
|
|
+ "end_at": end_time,
|
|
|
});
|
|
});
|
|
|
// HTML 模板
|
|
// HTML 模板
|
|
|
let template = r#"
|
|
let template = r#"
|
|
@@ -153,16 +168,23 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
series: [
|
|
series: [
|
|
|
- {{#each export_info}}
|
|
|
|
|
|
|
+ {{#each series_info}}
|
|
|
{
|
|
{
|
|
|
name: '{{name}}',
|
|
name: '{{name}}',
|
|
|
type: 'scatter',
|
|
type: 'scatter',
|
|
|
|
|
+ symbol: '{{symbol}}',
|
|
|
emphasis: {
|
|
emphasis: {
|
|
|
focus: 'series'
|
|
focus: 'series'
|
|
|
},
|
|
},
|
|
|
data:[
|
|
data:[
|
|
|
- {{#each ticker_info}}
|
|
|
|
|
- [{{create_time}},{{price}},{{size}}],
|
|
|
|
|
|
|
+ {{#each data}}
|
|
|
|
|
+ {
|
|
|
|
|
+ value: [{{create_time}},{{price}},{{size}}],
|
|
|
|
|
+ itemStyle: {
|
|
|
|
|
+ borderColor: {{size}} > 0 ? 'green' : 'red',
|
|
|
|
|
+ borderWidth: 1,
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
{{/each}}
|
|
{{/each}}
|
|
|
],
|
|
],
|
|
|
markArea: {
|
|
markArea: {
|