From 551ca054c616091b1ba67d8c3fae9ba59681ea24 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 22 Feb 2021 00:25:21 +0000 Subject: [PATCH] extracted status printing method in HiddenTrailingStop strategy. added leverage to stop order in HiddenTrailingStop strategy. --- src/strategy.rs | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/strategy.rs b/src/strategy.rs index 16efa99..043a4c5 100644 --- a/src/strategy.rs +++ b/src/strategy.rs @@ -88,6 +88,30 @@ pub struct HiddenTrailingStop { impl HiddenTrailingStop { + fn print_status(&self, position: &Position) { + match self.stop_percentages.get(&position.id()) { + None => { + info!( + "\tState: {:?} | PL: {:0.2}{} ({:0.2}%)", + position.profit_state().unwrap(), + position.pl(), + position.pair().quote(), + position.pl_perc() + ); + } + Some(stop_percentage) => { + info!( + "\tState: {:?} | PL: {:0.2}{} ({:0.2}%) | Stop: {:0.2}", + position.profit_state().unwrap(), + position.pl(), + position.pair().quote(), + position.pl_perc(), + stop_percentage + ); + } + } + } + fn update_stop_percentage(&mut self, position: &Position) { if let Some(profit_state) = position.profit_state() { let profit_state_delta = match profit_state { @@ -116,15 +140,6 @@ impl HiddenTrailingStop { } } } - - info!( - "\tState: {:?} | PL: {:0.2}{} ({:0.2}%) | Stop: {:0.2}", - position.profit_state().unwrap(), - position.pl(), - position.pair().quote(), - position.pl_perc(), - self.stop_percentages.get(&position.id()).unwrap_or(&0.0) - ); } } } @@ -135,7 +150,7 @@ impl Default for HiddenTrailingStop { // in percentage let capital_max_loss = 15.0; - let capital_min_profit = 9.0; + let capital_min_profit = 1.0; let capital_good_profit = capital_min_profit * 2.0; let weighted_min_profit = capital_min_profit / leverage; @@ -253,6 +268,8 @@ impl PositionStrategy for HiddenTrailingStop { _: &HashMap, fees: &Vec, ) -> (Position, Option>, Option>) { + self.print_status(&position); + let taker_fee = fees .iter() .filter_map(|x| match x { @@ -282,6 +299,7 @@ impl PositionStrategy for HiddenTrailingStop { OrderKind::Stop { price: stop_loss_price }, position.platform(), position.amount().neg()) + .with_leverage(Some(self.leverage)) .with_metadata(Some(OrderMetadata::new().with_position_id(Some(position.id())))) }; let stop_loss_set = *self.stop_loss_flags.entry(position.id()).or_insert(false);