|
|
@@ -176,10 +176,10 @@ impl Predictor {
|
|
|
fair_price: Default::default(),
|
|
|
fair_price_ema_short: Default::default(),
|
|
|
fair_price_ema_long: Default::default(),
|
|
|
- mid_rate_signal_open: Self::DONT_VIEW,
|
|
|
+ mid_rate_signal_open: Decimal::ZERO,
|
|
|
mid_price_focus_cancel: Self::DONT_VIEW,
|
|
|
mid_price_focus_stop_loss: Self::DONT_VIEW,
|
|
|
- mid_rate_signal_close: Self::DONT_VIEW,
|
|
|
+ mid_rate_signal_close: Decimal::ZERO,
|
|
|
|
|
|
price_times_avg: Default::default(),
|
|
|
|
|
|
@@ -310,6 +310,9 @@ impl Predictor {
|
|
|
// 重置fair数据,用于重新计算幅度
|
|
|
if prev_inventory != self.inventory {
|
|
|
self.fair_price_time_vec.deque.clear();
|
|
|
+ self.mid_price_time_vec.deque.clear();
|
|
|
+ self.mid_price_long_time_vec.deque.clear();
|
|
|
+ self.mid_price_trend_time_vec.deque.clear();
|
|
|
}
|
|
|
|
|
|
// 重置资金流计算
|
|
|
@@ -386,7 +389,7 @@ impl Predictor {
|
|
|
self.fair_price_ema_short * dec!(0.999) + self.fair_price * dec!(0.001)
|
|
|
};
|
|
|
|
|
|
- if self.fair_price_time_vec.len() < 2 {
|
|
|
+ if self.mid_price_time_vec.len() < 2 || self.mid_price_long_time_vec.len() < 2 || self.mid_price_trend_time_vec.len() < 2 {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -402,26 +405,26 @@ impl Predictor {
|
|
|
mid_trend_rate.rescale(8);
|
|
|
|
|
|
// 重置开仓焦点,条件1
|
|
|
- if self.mid_rate_signal_open != Self::DONT_VIEW && !self.inventory.is_zero() {
|
|
|
- self.mid_rate_signal_open = Self::DONT_VIEW;
|
|
|
+ if !self.mid_rate_signal_open.is_zero() && !self.inventory.is_zero() {
|
|
|
+ self.mid_rate_signal_open = Decimal::ZERO;
|
|
|
self.mid_price_focus_cancel = Self::DONT_VIEW;
|
|
|
}
|
|
|
// 重置开仓焦点,条件2
|
|
|
- if self.mid_price_focus_cancel != Self::DONT_VIEW {
|
|
|
+ if !self.mid_rate_signal_open.is_zero() {
|
|
|
if self.mid_rate_signal_open > Decimal::ZERO && self.mid_price > self.mid_price_focus_cancel {
|
|
|
- self.mid_rate_signal_open = Self::DONT_VIEW;
|
|
|
+ self.mid_rate_signal_open = Decimal::ZERO;
|
|
|
self.mid_price_focus_cancel = Self::DONT_VIEW;
|
|
|
self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
}
|
|
|
if self.mid_rate_signal_open < Decimal::ZERO && self.mid_price < self.mid_price_focus_cancel {
|
|
|
- self.mid_rate_signal_open = Self::DONT_VIEW;
|
|
|
+ self.mid_rate_signal_open = Decimal::ZERO;
|
|
|
self.mid_price_focus_cancel = Self::DONT_VIEW;
|
|
|
self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
}
|
|
|
}
|
|
|
// 更新程序关注的开仓焦点
|
|
|
- if self.mid_rate_signal_open == Self::DONT_VIEW && self.inventory.is_zero() {
|
|
|
- self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
+ if self.mid_rate_signal_open.is_zero() && self.inventory.is_zero() {
|
|
|
+ // self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
// 是同起点
|
|
|
// let mut is_cross = fair_rate.abs() > self.params.open_activate;
|
|
|
// is_cross = is_cross && mid_rate.abs() > self.params.open_activate;
|
|
|
@@ -453,8 +456,8 @@ impl Predictor {
|
|
|
// 大于0:当前价格在均线之上
|
|
|
// 小于0:当前价格在均线之下
|
|
|
// 重置平仓焦点,条件1
|
|
|
- if self.mid_rate_signal_close != Self::DONT_VIEW && self.inventory.is_zero() {
|
|
|
- self.mid_rate_signal_close = Self::DONT_VIEW;
|
|
|
+ if !self.mid_rate_signal_close.is_zero() && self.inventory.is_zero() {
|
|
|
+ self.mid_rate_signal_close = Decimal::ZERO;
|
|
|
}
|
|
|
// // 重置平仓焦点,条件2
|
|
|
// if !self.fair_rate_focus_close.is_zero() && self.fair_rate_focus_close > dec!(-0.1) {
|
|
|
@@ -470,7 +473,7 @@ impl Predictor {
|
|
|
// }
|
|
|
// 更新程序关注的平仓焦点
|
|
|
let close_activate = self.params.open_activate;
|
|
|
- if self.mid_rate_signal_close == Self::DONT_VIEW && !self.inventory.is_zero() && mid_rate.abs() > close_activate {
|
|
|
+ if self.mid_rate_signal_close.is_zero() && !self.inventory.is_zero() && mid_rate.abs() > close_activate {
|
|
|
// 多单平仓逻辑
|
|
|
if self.inventory > Decimal::ZERO && mid_rate > Decimal::ZERO {
|
|
|
if self.profit_point > Decimal::ZERO {
|
|
|
@@ -516,7 +519,7 @@ impl Predictor {
|
|
|
// info!("----------------------------------------");
|
|
|
// }
|
|
|
// ============================ 平仓特殊逻辑处理2 =======================
|
|
|
- if self.mid_rate_signal_close == Self::DONT_VIEW && !self.inventory.is_zero() && self.profit_point_vec.len() > 1 {
|
|
|
+ if self.mid_rate_signal_close.is_zero() && !self.inventory.is_zero() && self.profit_point_vec.len() > 1 {
|
|
|
let prev_profit_point = self.profit_point_vec[self.profit_point_vec.len() - 2];
|
|
|
let profit_point = self.profit_point_vec[self.profit_point_vec.len() - 1];
|
|
|
|
|
|
@@ -529,7 +532,7 @@ impl Predictor {
|
|
|
}
|
|
|
}
|
|
|
// ============================ 平仓特殊逻辑处理3 =======================
|
|
|
- if self.mid_rate_signal_close == Self::DONT_VIEW && !self.inventory.is_zero() {
|
|
|
+ if self.mid_rate_signal_close.is_zero() && !self.inventory.is_zero() {
|
|
|
if self.inventory > Decimal::ZERO && self.mid_price < self.mid_price_focus_stop_loss * dec!(0.9995) {
|
|
|
self.mid_rate_signal_close = dec!(-0.13);
|
|
|
|
|
|
@@ -593,8 +596,8 @@ impl Predictor {
|
|
|
// let is_open_long = self.spread_sma_1000 - self.spread_sma > self.params.open && self.fair_price > self.mid_price;
|
|
|
// let is_open_short = self.spread_sma_1000 - self.spread_sma < self.params.open * Decimal::NEGATIVE_ONE && self.fair_price < self.mid_price;
|
|
|
// 可能是接针
|
|
|
- let is_open_long = self.mid_rate_signal_open > Decimal::ZERO;
|
|
|
- let is_open_short = self.mid_rate_signal_open < Decimal::ZERO;
|
|
|
+ let is_open_long = self.mid_rate_signal_open == dec!(0.01);
|
|
|
+ let is_open_short = self.mid_rate_signal_open == dec!(-0.01);
|
|
|
let is_close_long = self.inventory > Decimal::ZERO && (self.mid_rate_signal_close > Decimal::ZERO || self.mid_rate_signal_close < dec!(-0.1));
|
|
|
let is_close_short = self.inventory < Decimal::ZERO && (self.mid_rate_signal_close < Decimal::ZERO || self.mid_rate_signal_close < dec!(-0.1));
|
|
|
|
|
|
@@ -628,7 +631,8 @@ impl Predictor {
|
|
|
// dec!(0)
|
|
|
// };
|
|
|
|
|
|
- self.bid_delta = self.params.open * self.mid_price;
|
|
|
+ self.bid_delta = dec!(-1)
|
|
|
+ // self.bid_delta = self.params.open * self.mid_price;
|
|
|
} else if is_open_short {
|
|
|
// let is_open_short_market = self.spread_sma_1000 - self.spread_sma < self.params.open_market * Decimal::NEGATIVE_ONE;
|
|
|
// self.ask_delta = if is_open_short_market {
|
|
|
@@ -637,7 +641,8 @@ impl Predictor {
|
|
|
// dec!(0)
|
|
|
// }
|
|
|
|
|
|
- self.ask_delta = self.params.open * self.mid_price;
|
|
|
+ self.ask_delta = dec!(-1)
|
|
|
+ // self.ask_delta = self.params.open * self.mid_price;
|
|
|
}
|
|
|
}
|
|
|
|