|
|
@@ -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())
|
|
|
}
|