|
@@ -78,6 +78,8 @@ pub struct Core {
|
|
|
pub position_check_series: Vec<i8>,
|
|
pub position_check_series: Vec<i8>,
|
|
|
// 止损大小
|
|
// 止损大小
|
|
|
pub stop_loss: Decimal,
|
|
pub stop_loss: Decimal,
|
|
|
|
|
+ // 浮动盈亏止损比例
|
|
|
|
|
+ pub fluctuation_stop_loss: Decimal,
|
|
|
// 资金使用率
|
|
// 资金使用率
|
|
|
pub used_pct: Decimal,
|
|
pub used_pct: Decimal,
|
|
|
// 启停信号 0 表示运行 大于1开始倒计时 1时停机
|
|
// 启停信号 0 表示运行 大于1开始倒计时 1时停机
|
|
@@ -171,6 +173,7 @@ impl Core {
|
|
|
exit_msg: "正常退出".to_string(),
|
|
exit_msg: "正常退出".to_string(),
|
|
|
position_check_series: Default::default(),
|
|
position_check_series: Default::default(),
|
|
|
stop_loss: params.stop_loss,
|
|
stop_loss: params.stop_loss,
|
|
|
|
|
+ fluctuation_stop_loss: params.fluctuation_stop_loss,
|
|
|
used_pct: dec!(0.95),
|
|
used_pct: dec!(0.95),
|
|
|
mode_signal: 0,
|
|
mode_signal: 0,
|
|
|
trade_order_update_time: Utc::now().timestamp_millis(),
|
|
trade_order_update_time: Utc::now().timestamp_millis(),
|
|
@@ -975,11 +978,11 @@ impl Core {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 不是现货执行的回撤风控0
|
|
|
|
|
|
|
+ // 不是现货执行的回撤风控0(市价盈亏)
|
|
|
if !self.exchange.contains("spot") { // 市场价盈亏风控
|
|
if !self.exchange.contains("spot") { // 市场价盈亏风控
|
|
|
let draw_back = Decimal::ONE - self.local_cash_including_unrealized / self.max_local_cash_including_unrealized;
|
|
let draw_back = Decimal::ONE - self.local_cash_including_unrealized / self.max_local_cash_including_unrealized;
|
|
|
|
|
|
|
|
- if draw_back > self.stop_loss {
|
|
|
|
|
|
|
+ if draw_back > self.fluctuation_stop_loss {
|
|
|
let exit_msg = format!("{} 总资金吊灯回撤(市价风控) {}。当前值:{}, 最高净值{},触发止损,准备停机。",
|
|
let exit_msg = format!("{} 总资金吊灯回撤(市价风控) {}。当前值:{}, 最高净值{},触发止损,准备停机。",
|
|
|
self.params.account_name, draw_back, self.local_cash_including_unrealized, self.max_local_cash_including_unrealized);
|
|
self.params.account_name, draw_back, self.local_cash_including_unrealized, self.max_local_cash_including_unrealized);
|
|
|
warn!(exit_msg);
|
|
warn!(exit_msg);
|
|
@@ -987,9 +990,9 @@ impl Core {
|
|
|
self.stop().await;
|
|
self.stop().await;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // // 市场价盈亏风控
|
|
|
|
|
|
|
+ // // 市场价盈亏风控(市价盈亏)
|
|
|
let draw_back = self.local_cash_including_unrealized / self.strategy.start_equity;
|
|
let draw_back = self.local_cash_including_unrealized / self.strategy.start_equity;
|
|
|
- if draw_back < -self.stop_loss {
|
|
|
|
|
|
|
+ if draw_back < -self.fluctuation_stop_loss {
|
|
|
let exit_msg = format!("{} 交易亏损,触发止损,准备停机(市价风控)。", self.params.account_name);
|
|
let exit_msg = format!("{} 交易亏损,触发止损,准备停机(市价风控)。", self.params.account_name);
|
|
|
warn!(exit_msg);
|
|
warn!(exit_msg);
|
|
|
self.exit_msg = exit_msg;
|
|
self.exit_msg = exit_msg;
|