|
|
@@ -88,12 +88,26 @@ impl Predictor {
|
|
|
|
|
|
while let Some(value) = rx.next().await {
|
|
|
// 数据填充到对应位置
|
|
|
- for i in 0..len {
|
|
|
- if value[i] == Self::DONT_VIEW {
|
|
|
- debugs[i].push_back(None);
|
|
|
+ // 第一步:获取插入位置
|
|
|
+ let target_ts = value[0]; // 时间戳在values[0]
|
|
|
+ let insert_pos = debugs[0]
|
|
|
+ .binary_search_by(|ts| {
|
|
|
+ ts.as_ref() // 解包Option
|
|
|
+ .expect("Timestamp cannot be None")
|
|
|
+ .cmp(&target_ts)
|
|
|
+ })
|
|
|
+ .unwrap_or_else(|e| e);
|
|
|
+
|
|
|
+ // 第二步:执行插入操作
|
|
|
+ for i in 0..debugs.len() {
|
|
|
+ let value = value.get(i).cloned().unwrap_or(Self::DONT_VIEW);
|
|
|
+ // 其他队列按规则插入
|
|
|
+ let elem = if value == Self::DONT_VIEW {
|
|
|
+ None
|
|
|
} else {
|
|
|
- debugs[i].push_back(Some(value[i]));
|
|
|
- }
|
|
|
+ Some(value)
|
|
|
+ };
|
|
|
+ debugs[i].insert(insert_pos, elem);
|
|
|
}
|
|
|
|
|
|
// 长度限制
|
|
|
@@ -190,7 +204,7 @@ impl Predictor {
|
|
|
self.prices[mid_index][1].push_back(mp.clone());
|
|
|
|
|
|
// 长度限制
|
|
|
- if self.prices[mid_index][0].len() > 2000 {
|
|
|
+ if self.prices[mid_index][0].len() > 10000 {
|
|
|
self.prices[mid_index][0].pop_front();
|
|
|
self.prices[mid_index][1].pop_front();
|
|
|
}
|
|
|
@@ -325,7 +339,7 @@ impl Predictor {
|
|
|
spread_abs.rescale(5);
|
|
|
|
|
|
self.spread_vec.push_back(spread_abs);
|
|
|
- if self.spread_vec.len() > 1000 {
|
|
|
+ if self.spread_vec.len() > 3000 {
|
|
|
self.spread_vec.pop_front();
|
|
|
}
|
|
|
|
|
|
@@ -398,6 +412,14 @@ impl Predictor {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if self.optimal_ask_price.is_zero() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.optimal_bid_price.is_zero() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if self.balance.is_zero() {
|
|
|
return;
|
|
|
}
|
|
|
@@ -461,7 +483,7 @@ impl Predictor {
|
|
|
let is_delta_changed = self.update_delta().await;
|
|
|
|
|
|
// let cci_arc = self.cci_arc.clone();
|
|
|
- let now = Decimal::from(Utc::now().timestamp_millis());
|
|
|
+ let now = data_time;
|
|
|
let mid_price = self.mid_price;
|
|
|
let ask_price = if self.params.ref_exchange.len() > 0 {
|
|
|
self.fair_price_std_vec[0]
|
|
|
@@ -487,7 +509,7 @@ impl Predictor {
|
|
|
|
|
|
let inventory = self.inventory;
|
|
|
|
|
|
- let sigma_square = now - data_time;
|
|
|
+ let sigma_square = Decimal::from(Utc::now().timestamp_millis()) - data_time;
|
|
|
|
|
|
let gamma = self.balance;
|
|
|
let kappa = self.params.open;
|