Browse Source

持仓y轴信息

skyffire 9 months ago
parent
commit
65cf4016bc
2 changed files with 50 additions and 28 deletions
  1. 45 24
      strategy/src/predictor.rs
  2. 5 4
      strategy/src/utils.rs

+ 45 - 24
strategy/src/predictor.rs

@@ -220,6 +220,7 @@ impl Predictor {
             return;
         }
 
+        let prev_pos_amount = self.pos_amount;
         self.pos_amount = pos_amount.clone();
         self.pos_avg_price = pos_avg_price.clone();
         self.inventory = (pos_amount / (min_amount_value / self.mid_price)).trunc();
@@ -232,7 +233,9 @@ impl Predictor {
             };
         }
 
-        self.processor(update_time, true).await;
+        if prev_pos_amount != self.pos_amount {
+            self.processor(update_time, true).await;
+        }
     }
 
     pub async fn on_balance(&mut self, balance: Decimal) {
@@ -385,10 +388,6 @@ impl Predictor {
 
         self.update_delta();
 
-        if !self.inventory.is_zero() {
-            info!(?data_time, is_hard_update)
-        }
-
         // let cci_arc = self.cci_arc.clone();
         let now = data_time;
         let mid_price = self.mid_price;
@@ -424,25 +423,47 @@ impl Predictor {
         }
         let pos_avg_price = self.pos_avg_price;
 
-        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,
-            fair_price,
-            pos_avg_price
-        ]).unwrap();
+        if is_hard_update {
+            self.debug_sender.unbounded_send(vec![
+                now,
+                if pos_avg_price.is_zero() { Self::DONT_VIEW } else { pos_avg_price },
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                inventory,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                Self::DONT_VIEW,
+                pos_avg_price
+            ]).unwrap();
+        } else {
+            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,
+                fair_price,
+                pos_avg_price
+            ]).unwrap();
+        }
     }
 
     // #[instrument(skip(self, ref_ticker_map), level="TRACE")]

+ 5 - 4
strategy/src/utils.rs

@@ -225,7 +225,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Option<Decimal>>>) -> String {
           let color = "";
           if(item > 0) color = "#F2495E"
           if(item < 0) color = "#13BF86"
-          inventoryList.push({ name: "inventory",itemStyle:{color: color}, value: item, xAxis: index, yAxis: data[16][index] });
+          inventoryList.push({ name: "inventory",itemStyle:{color: color}, value: item, xAxis: index, yAxis: data[16][index] === "0" ? data[1][index] : data[16][index] });
         }
       });
       return {
@@ -261,7 +261,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Option<Decimal>>>) -> String {
         },
         legend: [
           {
-            data: ["mid_price", "fair0", "fair1", "optimal_ask_price", "optimal_bid_price", "fair_price"],
+            data: ["mid_price", "fair0", "fair1", "optimal_ask_price", "optimal_bid_price"],
             top: "230px",
           },
           {
@@ -414,7 +414,8 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Option<Decimal>>>) -> String {
             name: "fair_price",
             type: "line",
             showSymbol: false,
-            data: data[15],
+            // data: data[15],
+            data: []
           },
 
           {
@@ -483,7 +484,7 @@ pub fn build_html_file(data_c: &Vec<VecDeque<Option<Decimal>>>) -> String {
           let color = "";
           if(item > 0) color = "#F2495E"
           if(item < 0) color = "#13BF86"
-          inventoryList.push({ name: "inventory",itemStyle:{color: color}, value: item, xAxis: index, yAxis: data[1][index] });
+          inventoryList.push({ name: "inventory",itemStyle:{color: color}, value: item, xAxis: index, yAxis: data[16][index] === "0" ? data[1][index] : data[16][index] });
         }
       });
       return {