|
|
@@ -63,8 +63,6 @@ pub struct Strategy {
|
|
|
pub total_amount: Decimal, //
|
|
|
pub is_ready: bool, // 程序是否已经准备好,ready
|
|
|
pub _is_print: bool, //
|
|
|
- pub _min_amount_value: Decimal, //
|
|
|
- pub _max_amount_value: Decimal, //
|
|
|
|
|
|
pub mp_ema: Decimal, // 原文的mp_ewma
|
|
|
pub mp: Decimal, //
|
|
|
@@ -75,6 +73,8 @@ pub struct Strategy {
|
|
|
pub ref_ap: Decimal, //
|
|
|
pub step_size: Decimal, // 原文的stepSize
|
|
|
pub tick_size: Decimal, // 原文的tickSize
|
|
|
+ pub min_amount_value: Decimal, // 最小下单价值
|
|
|
+ pub max_amount_value: Decimal, // 最大下单价值
|
|
|
|
|
|
pub max_pos_rate: Decimal, // 原文的maxPos,其实是最大持仓比例
|
|
|
pub profit: Decimal, //
|
|
|
@@ -160,8 +160,8 @@ impl Strategy {
|
|
|
total_amount: Default::default(),
|
|
|
is_ready: false,
|
|
|
_is_print: is_print,
|
|
|
- _min_amount_value: dec!(0.01),
|
|
|
- _max_amount_value: dec!(10000.0),
|
|
|
+ min_amount_value: dec!(0.01),
|
|
|
+ max_amount_value: dec!(10000.0),
|
|
|
mp_ema: Default::default(),
|
|
|
mp: Default::default(),
|
|
|
bp: Default::default(),
|
|
|
@@ -756,7 +756,7 @@ impl Strategy {
|
|
|
// debug!(?need_close_long, ?need_close_short);
|
|
|
|
|
|
// 做多仓位平仓
|
|
|
- if need_close_long * self.mp > self._min_amount_value {
|
|
|
+ if need_close_long * self.mp > self.min_amount_value {
|
|
|
let mut amount = need_close_long;
|
|
|
// 现货要对数量精度进行限定处理
|
|
|
if self.exchange.contains("spot") {
|
|
|
@@ -777,7 +777,7 @@ impl Strategy {
|
|
|
}
|
|
|
|
|
|
// 做空仓位平仓
|
|
|
- if need_close_short * self.mp > self._min_amount_value {
|
|
|
+ if need_close_short * self.mp > self.min_amount_value {
|
|
|
let mut amount = need_close_short;
|
|
|
if self.exchange.contains("spot") {
|
|
|
amount = utils::fix_amount(amount, self.step_size);
|
|
|
@@ -953,16 +953,16 @@ impl Strategy {
|
|
|
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);
|
|
|
- let amount = utils::fix_amount(self.step_size, self.step_size);
|
|
|
+ let amount = utils::get_amount_by_min_amount_value(self.min_amount_value, target_buy_price, self.step_size);
|
|
|
// let amount = if predictor.inventory < Decimal::ZERO {
|
|
|
// utils::fix_amount(self.step_size * predictor.inventory.abs(), self.step_size)
|
|
|
// } else {
|
|
|
// utils::fix_amount(self.step_size * (predictor.level + Decimal::ONE), self.step_size)
|
|
|
// };
|
|
|
- let amount_value = amount * predictor.mid_price;
|
|
|
|
|
|
- // 下单价值不能太大,也不能太小
|
|
|
- if amount_value >= self._min_amount_value {
|
|
|
+ // 下单价值判定
|
|
|
+ let amount_value = amount * target_buy_price;
|
|
|
+ if amount_value >= self.min_amount_value {
|
|
|
let client_id = utils::generate_client_id(Some(self.broker_id.clone()));
|
|
|
let order = vec![
|
|
|
amount.to_string(),
|
|
|
@@ -973,6 +973,8 @@ impl Strategy {
|
|
|
|
|
|
// debug!(?order);
|
|
|
command.limits_open.insert(client_id, order);
|
|
|
+ } else {
|
|
|
+ info!("下单价值太小,要求:{},但是价格:{}, 数量:{}", self.min_amount_value, target_buy_price, amount);
|
|
|
}
|
|
|
}
|
|
|
// 挂空单, TODO 如果下单之后没有收到仓位,岂不是会连续下几单?
|
|
|
@@ -981,16 +983,16 @@ impl Strategy {
|
|
|
// target_sell_price = utils::clip(target_sell_price, self.bp * dec!(0.9995), self.ap * dec!(1.03));
|
|
|
// 取消大小限制
|
|
|
target_sell_price = utils::fix_price(target_sell_price, self.tick_size);
|
|
|
- let amount = utils::fix_amount(self.step_size, self.step_size);
|
|
|
+ let amount = utils::get_amount_by_min_amount_value(self.min_amount_value, target_sell_price, self.step_size);
|
|
|
// let amount = if predictor.inventory > Decimal::ZERO {
|
|
|
// utils::fix_amount(self.step_size * predictor.inventory.abs(), self.step_size)
|
|
|
// } else {
|
|
|
// utils::fix_amount(self.step_size * (predictor.level + Decimal::ONE), self.step_size)
|
|
|
// };
|
|
|
- let amount_value = amount * self.mp;
|
|
|
|
|
|
// 下单价值不能太大,也不能太小
|
|
|
- if amount_value >= self._min_amount_value {
|
|
|
+ let amount_value = amount * target_sell_price;
|
|
|
+ if amount_value >= self.min_amount_value {
|
|
|
let client_id = utils::generate_client_id(Some(self.broker_id.clone()));
|
|
|
let order = vec![
|
|
|
amount.to_string(),
|
|
|
@@ -1001,6 +1003,8 @@ impl Strategy {
|
|
|
|
|
|
// debug!(?order);
|
|
|
command.limits_open.insert(client_id, order);
|
|
|
+ } else {
|
|
|
+ info!("下单价值太小,要求:{},但是价格:{}, 数量:{}", self.min_amount_value, target_sell_price, amount);
|
|
|
}
|
|
|
}
|
|
|
}
|