Explorar el Código

添加机器人查询数据

gepangpang hace 1 año
padre
commit
2b56d1fb75

+ 2 - 0
config.toml.sample

@@ -14,6 +14,8 @@ recall_max_count = 1000
 short_volume_rate = 0.55
 # 主动性涨比率(0.01代表1%)
 long_volume_rate = 0.55
+# 策略机器人名称
+robot_name = "gate49"
 # 导出路径(不填则为默认路径"./")
 export_path = ""
 # 导出文件名字(不填则为默认名字"export")

+ 2 - 1
src/binance_swap/binance_swap_standard.rs

@@ -66,7 +66,8 @@ pub async fn standard_trades(symbol: &str, limit: &str, trade_id: &str) -> Resul
         let result = trades_list.iter().map(|item| {
             Trades {
                 id: item.id.to_string(),
-                data_type: "ticker".to_string(),
+                data_type: "ticker_binance".to_string(),
+                classify: "ticker".to_string(),
                 symbol: symbol.to_string(),
                 create_time: item.time.to_string(),
                 size: if item.is_buyer_maker { item.qty.to_string() } else { format!("-{}", item.qty.to_string()) },

+ 21 - 5
src/export/html.rs

@@ -26,7 +26,7 @@ pub struct SeriesInfo {
     pub data: Vec<Trades>,
 }
 
-pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, start_at: &str, end_at: &str, config: ConfigInfo) {
+pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, start_at: &str, end_at: &str, config: ConfigInfo, robot_info: Vec<Trades>) {
     info!("正在生成网页,请稍后!");
     let export_path = if config.export_path == "" { "./" } else { config.export_path.as_str() };
     let export_name = if config.export_name == "" { "export" } else { config.export_name.as_str() };
@@ -70,21 +70,22 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, start_at: &str, e
         let long_volume_bool = long_volume / sum_volume >= config.long_volume_rate;
         let short_volume_bool = short_volume / sum_volume >= config.short_volume_rate;
 
-        if (long_volume_bool && last_bool != "long") || (short_volume_bool && last_bool != "short") || (!long_volume_bool && !short_volume_bool && last_bool != "none") {
+        if (long_volume_bool && last_bool != "initiative_long") || (short_volume_bool && last_bool != "initiative_short") || (!long_volume_bool && !short_volume_bool && last_bool != "initiative_none") {
             // 新增订单流主动性数据
             let max_price = max_price * dec!(1.005);
             if long_volume_bool {
-                last_bool = "long";
+                last_bool = "initiative_long";
             }
             if short_volume_bool {
-                last_bool = "short";
+                last_bool = "initiative_short";
             }
             if !long_volume_bool && !short_volume_bool {
-                last_bool = "none";
+                last_bool = "initiative_none";
             }
             ticker_info.push(Trades {
                 id: Uuid::new_v4().to_string()[0..8].to_string(),
                 data_type: last_bool.to_string(),
+                classify: "initiative".to_string(),
                 symbol: trades.symbol,
                 create_time: trades.create_time,
                 size: volume.to_string(),
@@ -114,6 +115,9 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, start_at: &str, e
     let mut name_list: Vec<String> = vec![];
     let mut legend_list: Vec<String> = vec![];
     let mut series_info: Vec<SeriesInfo> = vec![];
+
+    let ref_robot_info: Vec<Trades> = robot_info.iter().filter(|trades| trades.data_type == "robot_ref_price").cloned().collect();
+
     for item in export_info.clone() {
         name_list.push(format!("'{}'", item.name));
         series_info.push(SeriesInfo {
@@ -122,9 +126,21 @@ pub fn export_html(export_info: Vec<ExportExchangeTickerInfo>, start_at: &str, e
         })
     }
     series_info.push(initiative_info);
+
+    series_info.push(SeriesInfo {
+        name: "预定价格".to_string(),
+        data: ref_robot_info.clone(),
+    });
+    let reg_robot_info: Vec<Trades> = robot_info.iter().filter(|trades| trades.data_type == "robot_reg_price").cloned().collect();
+    series_info.push(SeriesInfo {
+        name: "挂单价格".to_string(),
+        data: reg_robot_info.clone(),
+    });
+
     for item in series_info.clone() {
         legend_list.push(format!("'{}'", item.name));
     }
+
     let data = serde_json::json!({
         "chart_title": format!("{} Ticker数据", name_list.join("、").replace("'","")),
         "legend_data": format!("[{}]", legend_list.join(", ")),

+ 2 - 1
src/gate_swap/gate_swap_standard.rs

@@ -28,7 +28,8 @@ pub(crate) async fn standard_trades(symbol: &str, start_at: &str, end_at: &str,
         let result = trades_list.iter().map(|item| {
             Trades {
                 id: item.id.to_string(),
-                data_type: "ticker".to_string(),
+                data_type: "ticker_gate".to_string(),
+                classify: "ticker".to_string(),
                 symbol: item.contract.clone(),
                 create_time: (item.create_time_ms * 1000.0).to_string(),
                 size: (item.size * ct_val.unwrap_or(Decimal::ONE)).to_string(),

+ 9 - 2
src/handle_ticker.rs

@@ -8,6 +8,7 @@ use tracing::{error, info};
 use crate::binance_swap::binance_swap_standard;
 use crate::gate_swap::gate_swap_standard;
 use crate::okx_swap::okx_swap_standard;
+use crate::robot_data;
 use crate::struct_standard::{AggTrades, Trades};
 
 pub async fn get_gate_ticker_info(symbol: &str, start_at: &str, end_at: &str) -> Vec<Trades> {
@@ -72,7 +73,8 @@ pub async fn get_binance_ticker_info(symbol: &str, start_at: &str, end_at: &str)
     for agg_trades in agg_ticker_info_list.clone() {
         ticker_info_list.push(Trades {
             id: agg_trades.start_id,
-            data_type: "ticker".to_string(),
+            data_type: "ticker_binance".to_string(),
+            classify: "ticker".to_string(),
             symbol: agg_trades.symbol,
             create_time: agg_trades.create_time,
             size: agg_trades.size,
@@ -97,7 +99,7 @@ pub async fn get_binance_ticker_info(symbol: &str, start_at: &str, end_at: &str)
     ticker_info_list.iter().filter(|trades| trades.is_effect).cloned().collect()
 }
 
-pub(crate) async fn get_okx_ticker_info(symbol: &str, start_at: &str, end_at: &str) -> Vec<Trades> {
+pub async fn get_okx_ticker_info(symbol: &str, start_at: &str, end_at: &str) -> Vec<Trades> {
     let ct_val = okx_swap_standard::standard_ct_val(symbol).await;
 
     let start_at_d = Decimal::from_str(start_at).unwrap();
@@ -165,4 +167,9 @@ pub(crate) async fn get_okx_ticker_info(symbol: &str, start_at: &str, end_at: &s
     //     })
     // }
     // ticker_info_list
+}
+
+pub async fn get_robot_info(symbol: &str, robot_name: &str, start_at: &str, end_at: &str) -> Vec<Trades> {
+    let robot_info = robot_data::robot_data_standard::standard_robot_info(&symbol, robot_name, start_at, end_at).await.unwrap();
+    robot_info
 }

+ 2 - 2
src/main.rs

@@ -26,7 +26,6 @@ async fn main() {
     if http::proxy::ParsingDetail::http_enable_proxy(config_clone.proxy_address) {
         info!("检测有代理配置,配置走代理");
     }
-    // robot_data::robot_data_standard::standard_robot_info("localhost_test_account_fresh", "1702010000", "1702031000").await;
     let symbol = config_clone.symbol;
     let start_at = NaiveDateTime::parse_from_str(&config.range_time[0].clone(), "%Y-%m-%d %H:%M:%S").unwrap().timestamp() - 8 * 3600;
     let end_at = NaiveDateTime::parse_from_str(&config.range_time[1].clone(), "%Y-%m-%d %H:%M:%S").unwrap().timestamp() - 8 * 3600;
@@ -93,5 +92,6 @@ async fn main() {
         exchange_list.push(exchange_result);
     }
 
-    export::html::export_html(exchange_list, &start_at.to_string(), &end_at.to_string(), config.clone());
+    let robot_info = handle_ticker::get_robot_info(&symbol, &config_clone.robot_name, &start_at.to_string(), &end_at.to_string()).await;
+    export::html::export_html(exchange_list, &start_at.to_string(), &end_at.to_string(), config.clone(), robot_info);
 }

+ 2 - 1
src/okx_swap/okx_swap_standard.rs

@@ -47,7 +47,8 @@ pub(crate) async fn standard_history_candles(symbol: &str, start_at: &str, end_a
 
                 Trades {
                     id: item.trade_id.to_string(),
-                    data_type: "ticker".to_string(),
+                    data_type: "ticker_okx".to_string(),
+                    classify: "ticker".to_string(),
                     symbol: symbol.to_string(),
                     create_time: item.ts.to_string(),
                     size: (size_i * ct_val).to_string(),

+ 24 - 7
src/robot_data/robot_data_standard.rs

@@ -18,7 +18,7 @@ struct RefPrice {
     id: i64,
     ref_price: String,
     num: String,
-    trigger_time: String,
+    trigger_time: i64,
     robot_name: String,
     side: String,
 }
@@ -29,26 +29,43 @@ struct RegPrice {
     id: i64,
     reg_price: String,
     num: String,
-    trigger_time: String,
+    trigger_time: i64,
     robot_name: String,
     side: String,
 }
 
-pub async fn standard_robot_info(robot_name: &str, start_at: &str, end_at: &str) -> Result<Vec<Trades>, Error> {
+pub async fn standard_robot_info(symbol: &str, robot_name: &str, start_at: &str, end_at: &str) -> Result<Vec<Trades>, Error> {
     let res_data = get_robot_info(robot_name, start_at, end_at).await;
     if res_data.code == "200" {
         let robot_info: RobotInfo = serde_json::from_str(&res_data.data).unwrap();
-        let result = robot_info.ref_price.iter().map(|item| {
+
+        let ref_price_list: Vec<Trades> = robot_info.ref_price.iter().map(|item| {
             Trades {
                 id: item.id.to_string(),
-                data_type: "robot".to_string(),
-                symbol: "".to_string(),
-                create_time: item.trigger_time.clone(),
+                data_type: "robot_ref_price".to_string(),
+                classify: "robot".to_string(),
+                symbol: symbol.to_string(),
+                create_time: item.trigger_time.to_string(),
                 size: item.num.clone(),
                 price: item.ref_price.clone(),
                 is_effect: true,
             }
         }).collect();
+        let reg_price_list: Vec<Trades> = robot_info.reg_price.iter().map(|item| {
+            Trades {
+                id: item.id.to_string(),
+                data_type: "robot_reg_price".to_string(),
+                classify: "robot".to_string(),
+                symbol: symbol.to_string(),
+                create_time: item.trigger_time.to_string(),
+                size: item.num.clone(),
+                price: item.reg_price.clone(),
+                is_effect: true,
+            }
+        }).collect();
+        let mut result = vec![];
+        result.extend(ref_price_list);
+        result.extend(reg_price_list);
         Ok(result)
     } else {
         Err(Error::new(ErrorKind::Other, res_data.to_string()))

+ 1 - 0
src/struct_standard.rs

@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
 pub struct Trades {
     pub id: String,
     pub data_type: String,
+    pub classify: String,
     pub symbol: String,
     pub create_time: String,
     pub size: String,

+ 2 - 0
src/utils/utils.rs

@@ -22,6 +22,7 @@ pub struct ConfigInfo {
     pub recall_max_count: Decimal,
     pub short_volume_rate: Decimal,
     pub long_volume_rate: Decimal,
+    pub robot_name: String,
     pub export_path: String,
     pub export_name: String,
 }
@@ -37,6 +38,7 @@ impl ConfigInfo {
             recall_max_count: Decimal::ZERO,
             short_volume_rate: Decimal::ZERO,
             long_volume_rate: Decimal::ZERO,
+            robot_name: "".to_string(),
             export_path: "".to_string(),
             export_name: "".to_string(),
         }