|
|
@@ -7,7 +7,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
use std::time::Duration;
|
|
|
use chrono::{Utc};
|
|
|
use rust_decimal::{Decimal};
|
|
|
-use rust_decimal::prelude::{ToPrimitive};
|
|
|
+use rust_decimal::prelude::{ToPrimitive, Zero};
|
|
|
use rust_decimal_macros::dec;
|
|
|
use tokio::spawn;
|
|
|
use tokio::sync::mpsc::{Sender};
|
|
|
@@ -961,11 +961,11 @@ impl Core {
|
|
|
self.stop().await;
|
|
|
}
|
|
|
// 回撤风控3,加浮亏的回撤风控
|
|
|
- let floating_profit = if !self.local_position.long_pos.is_zero() {
|
|
|
+ let floating_profit = if !self.local_position.long_pos.is_zero() && !self.local_position.long_avg.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() {
|
|
|
+ } else if !self.local_position.short_pos.is_zero() && !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
|