|
|
@@ -960,6 +960,26 @@ impl Core {
|
|
|
self.exit_msg = exit_msg;
|
|
|
self.stop().await;
|
|
|
}
|
|
|
+ // 回撤风控3,加浮亏的回撤风控
|
|
|
+ let floating_profit = if !self.local_position.long_pos.is_zero() {
|
|
|
+ let profit_price = self.strategy.mp - self.local_position.long_avg;
|
|
|
+
|
|
|
+ profit_price * self.local_position.long_pos
|
|
|
+ } else if !self.local_position.short_pos.is_zero() {
|
|
|
+ let profit_price = self.local_position.short_pos - self.strategy.mp;
|
|
|
+
|
|
|
+ profit_price * self.local_position.short_pos
|
|
|
+ } else {
|
|
|
+ Decimal::ZERO
|
|
|
+ };
|
|
|
+ let floating_draw_back = floating_profit / self.strategy.start_equity;
|
|
|
+ if floating_draw_back < -self.stop_loss {
|
|
|
+ let exit_msg = format!("{} 浮动亏损太大,准备停机。", self.params.account_name);
|
|
|
+ warn!(exit_msg);
|
|
|
+ self.exit_msg = exit_msg;
|
|
|
+ self.stop().await;
|
|
|
+ }
|
|
|
+
|
|
|
// 报单延迟风控,平均延迟允许上限5000ms
|
|
|
if self.ready == 1 && self.platform_rest.get_request_avg_delay() > dec!(5000) {
|
|
|
let exit_msg = format!("{} 延迟爆表 触发风控 准备停机。", self.params.account_name);
|