|
|
@@ -215,6 +215,9 @@ impl Predictor {
|
|
|
}
|
|
|
} else {
|
|
|
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() {
|
|
|
@@ -236,7 +239,7 @@ impl Predictor {
|
|
|
self.trade_233_vec.push_back(trade.clone());
|
|
|
} else {
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
@@ -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() {
|
|
|
return;
|
|
|
}
|
|
|
@@ -301,7 +304,7 @@ impl Predictor {
|
|
|
// let fair_price = (a1.price + b1.price) / Decimal::TWO;
|
|
|
|
|
|
// 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());
|
|
|
self.mid_price_vec[index] = mp;
|
|
|
|