Bläddra i källkod

mid_price_ema

skyffire 9 månader sedan
förälder
incheckning
5e2cf97e7a
1 ändrade filer med 9 tillägg och 1 borttagningar
  1. 9 1
      strategy/src/predictor.rs

+ 9 - 1
strategy/src/predictor.rs

@@ -22,6 +22,7 @@ pub struct Predictor {
     pub record_vec: VecDeque<Record>,                                           // 蜡烛队列
 
     pub mid_price: Decimal,                                                     // 中间价
+    pub mid_price_ema: Decimal,
     pub ask_price: Decimal,                                                     // 卖一价
     pub bid_price: Decimal,                                                     // 买一价
     pub last_price: Decimal,                                                    // 最后成交价
@@ -166,6 +167,8 @@ impl Predictor {
             record_vec: VecDeque::new(),
 
             mid_price: Default::default(),
+            mid_price_ema: Default::default(),
+
             ask_price: Default::default(),
             bid_price: Default::default(),
             last_price: Default::default(),
@@ -248,6 +251,11 @@ impl Predictor {
             self.ask_price = depth.asks[0].price;
             self.bid_price = depth.bids[0].price;
             self.mid_price = (self.ask_price + self.bid_price) / Decimal::TWO;
+            self.mid_price_ema = if self.mid_price_ema.is_zero() {
+                self.mid_price
+            } else {
+                self.mid_price_ema * dec!(0.9997) + self.mid_price * dec!(0.0003)
+            };
         }
 
         self.update_fair_price(depth, index).await;
@@ -659,7 +667,7 @@ impl Predictor {
         let ask_price = self.ask_price;
         let bid_price = self.bid_price;
         let last_price = self.last_price;
-        let fair_price = Self::DONT_VIEW;
+        let fair_price = self.mid_price_ema;
 
         let spread = self.spread_ema;
         let spread_max = self.orderbook_imbalance_ema;