From 1948b0f0321a5820374d74f82dc4bfd0f369bda6 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Thu, 25 Feb 2021 19:30:06 +0000 Subject: [PATCH] Update stop percentage and print before checking for existing stop percentage --- src/strategy.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/strategy.rs b/src/strategy.rs index d4c7893..6f8945c 100644 --- a/src/strategy.rs +++ b/src/strategy.rs @@ -171,6 +171,7 @@ impl Default for TrailingStop { TrailingStop { stop_percentages: Default::default(), stop_loss_flags: Default::default(), + trail_set_flags: Default::default(), capital_max_loss, capital_min_profit, capital_good_profit, @@ -272,8 +273,6 @@ impl PositionStrategy for TrailingStop { _: &HashMap, fees: &Vec, ) -> (Position, Option>, Option>) { - self.print_status(&position); - let taker_fee = fees .iter() .filter_map(|x| match x { @@ -335,6 +334,9 @@ impl PositionStrategy for TrailingStop { self.stop_loss_flags.insert(position.id(), false); } + self.update_stop_percentage(&position); + self.print_status(&position); + // let's check if we surpassed an existing stop percentage if let Some(existing_stop_percentage) = self.stop_percentages.get(&position.id()) { if &position.pl_perc() <= existing_stop_percentage { @@ -344,8 +346,6 @@ impl PositionStrategy for TrailingStop { } } - self.update_stop_percentage(&position); - (position, None, Some(messages)) } }