瀏覽代碼

同时也要兼顾depth的实时性。

skyffire 9 月之前
父節點
當前提交
7e0de7b14f
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      strategy/src/predictor.rs

+ 6 - 3
strategy/src/predictor.rs

@@ -215,6 +215,9 @@ impl Predictor {
             }
             }
         } else {
         } else {
             self.depth_vec[index] = depth.clone();
             self.depth_vec[index] = depth.clone();
+
+            let latest_price = (depth.asks[0].price + depth.bids[0].price) / Decimal::TWO;
+            self.update_fair_price(&latest_price, index).await;
         }
         }
 
 
         if self.mid_price.is_zero() {
         if self.mid_price.is_zero() {
@@ -236,7 +239,7 @@ impl Predictor {
             self.trade_233_vec.push_back(trade.clone());
             self.trade_233_vec.push_back(trade.clone());
         } else {
         } else {
             if trade.value > Decimal::ONE_HUNDRED {
             if trade.value > Decimal::ONE_HUNDRED {
-                self.update_fair_price(trade, index).await;
+                self.update_fair_price(&trade.price, index).await;
                 self.processor(trade.time, false).await;
                 self.processor(trade.time, false).await;
             }
             }
 
 
@@ -291,7 +294,7 @@ impl Predictor {
         }
         }
     }
     }
 
 
-    pub async fn update_fair_price(&mut self, trade: &Trade, index: usize) {
+    pub async fn update_fair_price(&mut self, latest_price: &Decimal, index: usize) {
         if self.mid_price.is_zero() {
         if self.mid_price.is_zero() {
             return;
             return;
         }
         }
@@ -301,7 +304,7 @@ impl Predictor {
         // let fair_price = (a1.price + b1.price) / Decimal::TWO;
         // let fair_price = (a1.price + b1.price) / Decimal::TWO;
 
 
         // self.fair_price_vec[index] = a1.price * b1.value / total + b1.price * a1.value / total;
         // self.fair_price_vec[index] = a1.price * b1.value / total + b1.price * a1.value / total;
-        let mut mp = trade.price;
+        let mut mp = latest_price.clone();
         mp.rescale(self.mid_price.scale());
         mp.rescale(self.mid_price.scale());
         self.mid_price_vec[index] = mp;
         self.mid_price_vec[index] = mp;