Selaa lähdekoodia

debug 信息优化

skyfffire 11 kuukautta sitten
vanhempi
commit
146ec324e3
2 muutettua tiedostoa jossa 38 lisäystä ja 34 poistoa
  1. 31 27
      strategy/src/predictor.rs
  2. 7 7
      strategy/src/utils.rs

+ 31 - 27
strategy/src/predictor.rs

@@ -59,7 +59,6 @@ pub struct Predictor {
     pub price_times_avg: Decimal,                                               // 公平所与做市所的价格倍率的平均值
 
     pub cci_arc: Arc<Mutex<CentralControlInfo>>,                                // 中控信息
-    pub debugs: Vec<Vec<Decimal>>,                                              // debug数据等
 
     pub is_ready: bool,
     pub prev_trade_time: i64,                                                   // 上次交易时间,也就是t
@@ -95,12 +94,16 @@ impl Predictor {
         tokio::spawn(async move {
             let len = 16usize;
             let mut prev_save_time = Decimal::from(Utc::now().timestamp_millis());
-            let mut debugs: Vec<VecDeque<Decimal>> = vec![VecDeque::new(); len];
+            let mut debugs: Vec<VecDeque<Option<Decimal>>> = vec![VecDeque::new(); len];
 
             while let Some(value) = rx.next().await {
                 // 数据填充到对应位置
                 for i in 0..len {
-                    debugs[i].push_back(value[i]);
+                    if value[i] == dec!(14142135623730951) {
+                        debugs[i].push_back(None);
+                    } else {
+                        debugs[i].push_back(Some(value[i]));
+                    }
                 }
 
                 // 长度限制
@@ -162,7 +165,6 @@ impl Predictor {
             price_times_avg: Default::default(),
             cci_arc,
 
-            debugs: vec![],
             is_ready: false,
             prev_trade_time: Utc::now().timestamp_micros(),
             close_price: Default::default(),
@@ -493,7 +495,7 @@ impl Predictor {
         self.optimal_ask_price = if self.ask_delta == dec!(-1) {
             self.bid_price
         } else if self.ask_delta == dec!(-2) {
-            self.fair_price + self.mid_price * self.params.open * Decimal::PI
+            dec!(14142135623730951)
         } else {
             max(self.ask_price + self.ask_delta, self.bid_price)
         };
@@ -501,7 +503,7 @@ impl Predictor {
         self.optimal_bid_price = if self.bid_delta == dec!(-1) {
             self.ask_price
         } else if self.bid_delta == dec!(-2) {
-            self.fair_price - self.mid_price * self.params.open * Decimal::PI
+            dec!(14142135623730951)
         } else {
             min(self.bid_price - self.bid_delta, self.ask_price)
         };
@@ -615,9 +617,9 @@ impl Predictor {
         let bid_price = self.bid_price;
         let last_price = self.last_price;
 
-        let spread = self.spread;
-        let spread_max = self.spread_max;
-        let spread_min = self.spread_max * Decimal::NEGATIVE_ONE;
+        let spread = self.mid_price;
+        let spread_max = self.optimal_ask_price;
+        let spread_min = self.optimal_bid_price;
         // let spread = self.price_times_avg;
         // let spread_max = self.fair_price_vec[1] / self.fair_price_vec[0];
         // let spread_min = self.fair_price / self.mid_price;
@@ -638,24 +640,26 @@ impl Predictor {
             return;
         }
 
-        self.debug_sender.unbounded_send(vec![
-            now,
-            mid_price,
-            ask_price,
-            bid_price,
-            last_price,
-            spread,
-            spread_max,
-            spread_min,
-            optimal_ask_price,
-            optimal_bid_price,
-            inventory,
-            sigma_square,
-            gamma,
-            kappa,
-            flow_ratio,
-            ref_price
-        ]).unwrap();
+        for _ in 0..100 {
+            self.debug_sender.unbounded_send(vec![
+                now,
+                mid_price,
+                ask_price,
+                bid_price,
+                last_price,
+                spread,
+                spread_max,
+                spread_min,
+                optimal_ask_price,
+                optimal_bid_price,
+                inventory,
+                sigma_square,
+                gamma,
+                kappa,
+                flow_ratio,
+                ref_price
+            ]).unwrap();
+        }
 
         self.prev_insert_time = Decimal::from(Utc::now().timestamp_millis())
     }

+ 7 - 7
strategy/src/utils.rs

@@ -160,7 +160,7 @@ pub async fn write_to_file(json_data: &String, file_path: String) {
     }
 }
 
-pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
+pub fn build_html_file(data_c: &Vec<VecDeque<Option<Decimal>>>) -> String {
     let temp_json_str = serde_json::to_string(&data_c).unwrap();
 
     let str1 = r##"
@@ -265,7 +265,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
             top: "230px",
           },
           {
-            data: ["spread", "spread_max", "spread_min"],
+            data: ["mp", "ap", "bp"],
             top: "480px",
           },
           {
@@ -273,7 +273,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
             top: "630px",
           },
           {
-            data: ["gamma"],
+            data: ["delay"],
             top: "780px",
           },
           {
@@ -418,7 +418,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
           },
 
           {
-            name: "spread",
+            name: "mp",
             type: "line",
             xAxisIndex: 1,
             yAxisIndex: 1,
@@ -426,7 +426,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
             data: data[5],
           },
           {
-            name: "spread_max",
+            name: "ap",
             type: "line",
             xAxisIndex: 1,
             yAxisIndex: 1,
@@ -434,7 +434,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
             data:  data[6],
           },
           {
-            name: "spread_min",
+            name: "bp",
             type: "line",
             xAxisIndex: 1,
             yAxisIndex: 1,
@@ -452,7 +452,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Decimal>>) -> String {
           },
 
           {
-            name: "gamma",
+            name: "delay",
             type: "line",
             xAxisIndex: 3,
             yAxisIndex: 3,