diff --git a/rustybot/src/models.rs b/rustybot/src/models.rs index 9c12914..a5fb122 100644 --- a/rustybot/src/models.rs +++ b/rustybot/src/models.rs @@ -384,16 +384,21 @@ impl Position { } pub fn update_profit_loss(&mut self, best_offer: f64, fee_perc: f64) { - let best_offer = best_offer.abs(); - let base_price = self.base_price * (1.0 + fee_perc / 100.0); + let (base_price, delta) = { + if self.is_short() { + let base_price = self.base_price * (1.0 - fee_perc / 100.0); + let delta = base_price - best_offer; - let delta = if self.is_short() { - base_price - best_offer - } else { - best_offer - base_price + (base_price, delta) + } else { + let base_price = self.base_price * (1.0 - fee_perc / 100.0); + let delta = best_offer - base_price; + + (base_price, delta) + } }; - let profit_loss = delta * self.amount; + let profit_loss = delta * self.amount.abs(); let profit_loss_percentage = ((1.0 - (base_price + delta) / base_price) * 100.0).abs() * profit_loss.signum();