|
|
@@ -51,6 +51,7 @@ pub struct Predictor {
|
|
|
pub fair_price_vec: Vec<Decimal>, // 公平价格列表,0表示做市所,1表示参考所
|
|
|
pub fair_price: Decimal, // 预定价格
|
|
|
pub fair_rate_focus: Decimal, // 变化幅度焦点
|
|
|
+ pub fair_price_focus: Decimal, // 观测焦点时的价格
|
|
|
pub fair_price_when_ordering: Decimal, // 下单时的预定价格
|
|
|
pub price_times_avg: Decimal, // 公平所与做市所的价格倍率的平均值
|
|
|
pub is_regressed: bool, // 做市所的价格是否已经回归
|
|
|
@@ -91,6 +92,7 @@ impl Predictor {
|
|
|
// 创建一个无界通道
|
|
|
let (tx, mut rx) = futures_channel::mpsc::unbounded::<Vec<Decimal>>();
|
|
|
|
|
|
+ let account_name = params.account_name.clone();
|
|
|
tokio::spawn(async move {
|
|
|
let len = 16usize;
|
|
|
let mut prev_save_time = Decimal::from(Utc::now().timestamp_millis());
|
|
|
@@ -123,7 +125,8 @@ impl Predictor {
|
|
|
utils::build_html_file(&debugs_clone)
|
|
|
}).await.unwrap();
|
|
|
|
|
|
- utils::write_to_file(&temp_html_str, "./db/db.html".to_string()).await;
|
|
|
+ let path = format!("./db/{}.html", account_name);
|
|
|
+ utils::write_to_file(&temp_html_str, path).await;
|
|
|
prev_save_time = Decimal::from(Utc::now().timestamp_millis());
|
|
|
}
|
|
|
});
|
|
|
@@ -160,6 +163,7 @@ impl Predictor {
|
|
|
mid_price_time_vec: FixedTimeRangeDeque::new(100_000),
|
|
|
fair_price: Default::default(),
|
|
|
fair_rate_focus: Default::default(),
|
|
|
+ fair_price_focus: Default::default(),
|
|
|
fair_price_when_ordering: Default::default(),
|
|
|
|
|
|
price_times_avg: Default::default(),
|
|
|
@@ -325,8 +329,16 @@ impl Predictor {
|
|
|
self.fair_rate_focus = Decimal::ZERO;
|
|
|
}
|
|
|
// 重置焦点,条件3
|
|
|
- if !self.fair_rate_focus.is_zero() && rate.abs() > self.params.open {
|
|
|
- self.fair_rate_focus = Decimal::ZERO;
|
|
|
+ if !self.fair_price_focus.is_zero() {
|
|
|
+ let focus_rate = (self.fair_price - self.fair_price_focus) / self.fair_price_focus;
|
|
|
+
|
|
|
+ if self.fair_rate_focus > Decimal::ZERO && focus_rate > self.params.open / Decimal::TWO {
|
|
|
+ self.fair_rate_focus = Decimal::ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.fair_rate_focus < Decimal::ZERO && focus_rate < Decimal::NEGATIVE_ONE * self.params.open / Decimal::TWO {
|
|
|
+ self.fair_rate_focus = Decimal::ZERO;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 更新程序关注的变化幅度焦点
|
|
|
@@ -336,11 +348,13 @@ impl Predictor {
|
|
|
// 向上涨,并且fair下穿mid,视为观测阶段开始
|
|
|
if rate > Decimal::ZERO && self.spread_sma_1000 > Decimal::ZERO {
|
|
|
self.fair_rate_focus = rate;
|
|
|
+ self.fair_price_focus = self.fair_price;
|
|
|
}
|
|
|
|
|
|
// 向下跌,并且fair上穿mid,视为观测阶段开始
|
|
|
if rate < Decimal::ZERO && self.spread_sma_1000 < Decimal::ZERO {
|
|
|
self.fair_rate_focus = rate;
|
|
|
+ self.fair_price_focus = self.fair_price;
|
|
|
}
|
|
|
}
|
|
|
}
|