cleanup of TrailingStop update_stop_percentage helper function
This commit is contained in:
parent
1948b0f032
commit
9be8c2e6ff
@ -119,28 +119,22 @@ impl TrailingStop {
|
||||
fn update_stop_percentage(&mut self, position: &Position) {
|
||||
if let Some(profit_state) = position.profit_state() {
|
||||
let profit_state_delta = match profit_state {
|
||||
PositionProfitState::MinimumProfit => Some(self.min_profit_trailing_delta),
|
||||
PositionProfitState::Profit => Some(self.good_profit_trailing_delta),
|
||||
_ => None,
|
||||
PositionProfitState::MinimumProfit => self.min_profit_trailing_delta,
|
||||
PositionProfitState::Profit => self.good_profit_trailing_delta,
|
||||
_ => return
|
||||
};
|
||||
|
||||
if let Some(profit_state_delta) = profit_state_delta {
|
||||
let current_stop_percentage = position.pl_perc() - profit_state_delta;
|
||||
let current_trailing_delta = position.pl_perc() - profit_state_delta;
|
||||
|
||||
if let PositionProfitState::MinimumProfit | PositionProfitState::Profit =
|
||||
profit_state
|
||||
{
|
||||
match self.stop_percentages.get(&position.id()) {
|
||||
None => {
|
||||
self.stop_percentages
|
||||
.insert(position.id(), current_stop_percentage);
|
||||
}
|
||||
Some(existing_threshold) => {
|
||||
if existing_threshold < ¤t_stop_percentage {
|
||||
self.stop_percentages
|
||||
.insert(position.id(), current_stop_percentage);
|
||||
}
|
||||
}
|
||||
match self.stop_percentages.get(&position.id()) {
|
||||
None => {
|
||||
self.stop_percentages
|
||||
.insert(position.id(), current_trailing_delta);
|
||||
}
|
||||
Some(existing_threshold) => {
|
||||
if existing_threshold < ¤t_trailing_delta {
|
||||
self.stop_percentages
|
||||
.insert(position.id(), current_trailing_delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user