damn calculations
This commit is contained in:
parent
3a38c20f56
commit
a2eae0ac13
@ -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
|
||||
(base_price, delta)
|
||||
} else {
|
||||
best_offer - base_price
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user