Przeglądaj źródła

添加买卖颜色区分颜色

DESKTOP-NE65RNK\Citrus_limon 1 rok temu
rodzic
commit
5f9ae8151c

+ 2 - 1
.gitignore

@@ -3,4 +3,5 @@
 .idea
 ./Cargo.lock
 /logs*
-*.html
+*.html
+/config.toml

+ 2 - 2
config.toml → config.toml.sample

@@ -2,10 +2,10 @@
 proxy_address = "127.0.0.1:7890"
 # 配置币对
 symbol = "doge_usdt"
-# 配置交易所 目前支持["binance", "gate""okx",]
+# 配置交易所 目前支持["binance", "gate", "okx"]
 exchanges = ["binance", "gate", "okx", ]
 # 配置查询时间(格式:2023-12-6 15:00:00)
-range_time = ["2023-12-5 15:00:01", "2023-12-5 15:20:58"]
+range_time = ["2023-12-5 15:00:00", "2023-12-5 15:01:00"]
 # 导出路径(不填则为默认路径"./")
 export_path = ""
 # 导出文件名字(不填则为默认名字"export")

+ 2 - 2
src/binance_swap/binance_swap_standard.rs

@@ -46,7 +46,7 @@ pub(crate) async fn standard_agg_trades(symbol: &str, start_at: &str, end_at: &s
                 end_id: item.l.to_string(),
                 symbol: symbol.to_string(),
                 create_time: item.t.to_string(),
-                size: item.q.to_string(),
+                size: if item.m { format!("-{}", item.q.to_string()) } else { item.q.to_string() },
                 price: item.p.clone(),
             }
         }).collect();
@@ -68,7 +68,7 @@ pub async fn standard_trades(symbol: &str, limit: &str, trade_id: &str) -> Resul
                 id: item.id.to_string(),
                 symbol: symbol.to_string(),
                 create_time: item.time.to_string(),
-                size: item.qty.to_string(),
+                size: if item.is_buyer_maker { item.qty.to_string() } else { format!("-{}", item.qty.to_string()) },
                 price: item.price.clone(),
             }
         }).collect();

+ 27 - 5
src/export/html.rs

@@ -16,6 +16,13 @@ pub struct ExportExchangeTickerInfo {
     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>) {
     info!("正在生成网页,请稍后!");
     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 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!({
         "chart_title": format!("{} Ticker数据", name_list.join("、").replace("'","")),
         "legend_data": format!("[{}]", name_list.join(", ")),
-        "export_info": export_info.clone(),
+        "series_info": series_info.clone(),
         "symbol": symbol.to_uppercase(),
         "start_at": start_time,
-        "end_at": end_time
+        "end_at": end_time,
     });
     // HTML 模板
     let template = r#"
@@ -153,16 +168,23 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, symbol: &str, sta
                 }
               ],
               series: [
-                {{#each export_info}}
+                {{#each series_info}}
                 {
                   name: '{{name}}',
                   type: 'scatter',
+                  symbol: '{{symbol}}',
                   emphasis: {
                     focus: 'series'
                   },
                   data:[
-                    {{#each ticker_info}}
-                        [{{create_time}},{{price}},{{size}}],
+                    {{#each data}}
+                      {
+                        value: [{{create_time}},{{price}},{{size}}],
+                        itemStyle: {
+                         borderColor: {{size}} > 0 ? 'green' : 'red',
+                         borderWidth: 1,
+                        }
+                      },
                     {{/each}}
                   ],
                   markArea: {

+ 5 - 5
src/okx_swap/okx_swap_rest.rs

@@ -1,15 +1,15 @@
 use crate::http::request::{get, Response};
 
-pub async fn get_history_trades(symbol: &str,start_at: &str, end_at: &str) -> Response {
+pub async fn get_history_trades(symbol: &str, start_at: &str, end_at: &str) -> Response {
     let url = "https://www.okx.com/api/v5/market/history-trades";
     let mut params = serde_json::json!({
         "instId":symbol,
         "type":"2"
     });
-    if end_at.len()>0{
+    if end_at.len() > 0 {
         params["after"] = serde_json::Value::from(end_at);
     }
-    if start_at.len()>0{
+    if start_at.len() > 0 {
         params["before"] = serde_json::Value::from(start_at);
     }
     get(url, params.to_string(), None).await
@@ -17,9 +17,9 @@ pub async fn get_history_trades(symbol: &str,start_at: &str, end_at: &str) -> Re
 
 
 //查阅所有交易币对的 基础信息
-pub async fn get_symbol_dateils_all() -> Response {
+pub async fn get_symbol_details_all() -> Response {
     let url = "https://www.okx.com/api/v5/public/instruments";
-    let  params = serde_json::json!({
+    let params = serde_json::json!({
         "instType":"SWAP"
     });
     get(url, params.to_string(), None).await

+ 4 - 4
src/okx_swap/okx_swap_standard.rs

@@ -2,7 +2,7 @@ use std::io::{Error, ErrorKind};
 
 use serde::{Deserialize, Serialize};
 
-use crate::okx_swap::okx_swap_rest::{get_history_trades, get_symbol_dateils_all};
+use crate::okx_swap::okx_swap_rest::{get_history_trades, get_symbol_details_all};
 use crate::struct_standard::Trades;
 
 #[derive(Debug, Deserialize, Serialize)]
@@ -139,14 +139,14 @@ pub struct SwapSymbolDateils {
     maxStopSz: String,//     合约或现货止盈止损市价委托的单笔最大委托数量,   合约的数量单位是“张”,现货的数量单位是“USDT”
 }
 
-pub(crate) async fn standard_symbol_dateils(symbol: &str) -> Result<Option<SwapSymbolDateils>, Error> {
+pub(crate) async fn standard_symbol_details(symbol: &str) -> Result<Option<SwapSymbolDateils>, Error> {
     let mut symbol_fmt = symbol.replace("_", "-").clone();
     symbol_fmt = symbol_fmt.to_uppercase();
     let ct_val_ccy_array: Vec<&str> = symbol_fmt.split("-").collect();
     let symbol_name = ct_val_ccy_array[0];
 
 
-    let res_data = get_symbol_dateils_all().await;
+    let res_data = get_symbol_details_all().await;
     if res_data.code == "200" {
         let res_data_str = res_data.data;
         let json_value: serde_json::Value = serde_json::from_str(&res_data_str).unwrap();
@@ -169,7 +169,7 @@ pub(crate) async fn standard_symbol_dateils(symbol: &str) -> Result<Option<SwapS
 }
 
 pub async fn standard_ct_val(symbol: &str) -> i64 {
-    match standard_symbol_dateils(symbol).await.unwrap() {
+    match standard_symbol_details(symbol).await.unwrap() {
         None => {
             1
         }