|
|
@@ -11,7 +11,7 @@ use tracing::{info, error, warn};
|
|
|
use tokio::time::Instant;
|
|
|
use global::params::Params;
|
|
|
use standard::{OrderCommand};
|
|
|
-use crate::avellaneda_stoikov::AvellanedaStoikov;
|
|
|
+use crate::predictor::Predictor;
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
pub struct Strategy {
|
|
|
@@ -465,7 +465,7 @@ impl Strategy {
|
|
|
|
|
|
// 修复挂单价格,不然单子打不出去
|
|
|
// #[instrument(skip(self), level="TRACE")]
|
|
|
- pub fn fix_price(&mut self, predictor: &mut AvellanedaStoikov) {
|
|
|
+ pub fn fix_price(&mut self, predictor: &mut Predictor) {
|
|
|
predictor.optimal_ask_price = utils::fix_price(predictor.optimal_ask_price, self.tick_size);
|
|
|
predictor.optimal_bid_price = utils::fix_price(predictor.optimal_bid_price, self.tick_size);
|
|
|
|
|
|
@@ -833,7 +833,7 @@ impl Strategy {
|
|
|
|
|
|
// 平仓订单处理命令
|
|
|
// #[instrument(skip(self, command), level="TRACE")]
|
|
|
- pub fn _post_close(&self, command: &mut OrderCommand, local_orders: &HashMap<String, OrderInfo>, predictor: &mut AvellanedaStoikov) {
|
|
|
+ pub fn _post_close(&self, command: &mut OrderCommand, local_orders: &HashMap<String, OrderInfo>, predictor: &mut Predictor) {
|
|
|
// debug!(?command);
|
|
|
|
|
|
let mut pd_amount = Decimal::ZERO;
|
|
|
@@ -890,7 +890,7 @@ impl Strategy {
|
|
|
// }
|
|
|
// // debug!(?command);
|
|
|
|
|
|
- if predictor.inventory > Decimal::ZERO {
|
|
|
+ if predictor.inventory > Decimal::ZERO && predictor.ask_delta != Decimal::NEGATIVE_ONE {
|
|
|
if pd_order_num == 0 {
|
|
|
let mut price = (short_lower + short_upper) * dec!(0.5);
|
|
|
// 不限制大小
|
|
|
@@ -910,7 +910,7 @@ impl Strategy {
|
|
|
// debug!(?command);
|
|
|
}
|
|
|
}
|
|
|
- if predictor.inventory < Decimal::ZERO {
|
|
|
+ if predictor.inventory < Decimal::ZERO && predictor.bid_delta != Decimal::NEGATIVE_ONE {
|
|
|
if pk_order_num == 0 {
|
|
|
let mut price = (long_upper + long_lower) * dec!(0.5);
|
|
|
// 不限制大小
|
|
|
@@ -1014,7 +1014,7 @@ impl Strategy {
|
|
|
|
|
|
// 开单指令生成逻辑
|
|
|
// #[instrument(skip(self, command), level="TRACE")]
|
|
|
- pub fn _post_open(&mut self, command: &mut OrderCommand, local_orders: &HashMap<String, OrderInfo>, predictor: &mut AvellanedaStoikov) {
|
|
|
+ pub fn _post_open(&mut self, command: &mut OrderCommand, local_orders: &HashMap<String, OrderInfo>, predictor: &mut Predictor) {
|
|
|
// 开仓逻辑检测,主要是检测整点开仓逻辑
|
|
|
if !self.check_allow_post_open() {
|
|
|
return;
|
|
|
@@ -1062,7 +1062,7 @@ impl Strategy {
|
|
|
// let one_hand_long_value = dec!(0.99) * (self.max_long_value / self.grid);
|
|
|
// let one_hand_short_value = dec!(0.99) * (self.max_short_value / self.grid);
|
|
|
// 挂多单
|
|
|
- if self.post_side >= 0 && buy_value == Decimal::ZERO && predictor.inventory.is_zero() {
|
|
|
+ if self.post_side >= 0 && buy_value == Decimal::ZERO && predictor.inventory.is_zero() && predictor.bid_delta != Decimal::NEGATIVE_ONE {
|
|
|
let mut target_buy_price = predictor.optimal_bid_price;
|
|
|
// target_buy_price = utils::clip(target_buy_price, self.bp * dec!(0.97), self.ap * dec!(1.0005));
|
|
|
target_buy_price = utils::fix_price(target_buy_price, self.tick_size);
|
|
|
@@ -1105,7 +1105,7 @@ impl Strategy {
|
|
|
}
|
|
|
}
|
|
|
// 挂空单
|
|
|
- if self.post_side <= 0 && sell_value == Decimal::ZERO && predictor.inventory.is_zero() {
|
|
|
+ if self.post_side <= 0 && sell_value == Decimal::ZERO && predictor.inventory.is_zero() && predictor.ask_delta != Decimal::NEGATIVE_ONE {
|
|
|
let mut target_sell_price = predictor.optimal_ask_price;
|
|
|
// target_sell_price = utils::clip(target_sell_price, self.bp * dec!(0.9995), self.ap * dec!(1.03));
|
|
|
// 取消大小限制
|
|
|
@@ -1202,7 +1202,7 @@ impl Strategy {
|
|
|
return command;
|
|
|
}
|
|
|
|
|
|
- pub fn do_strategy(&mut self, predictor: &mut AvellanedaStoikov, local_orders: &HashMap<String, OrderInfo>, local_coin: &Decimal, local_cash: &Decimal) -> OrderCommand {
|
|
|
+ pub fn do_strategy(&mut self, predictor: &mut Predictor, local_orders: &HashMap<String, OrderInfo>, local_coin: &Decimal, local_cash: &Decimal) -> OrderCommand {
|
|
|
// 更新当前账户余额
|
|
|
self.coin = local_coin.clone();
|
|
|
self.cash = local_cash.clone();
|