don't crash if no open positions are found

This commit is contained in:
Giulio De Pasquale 2021-01-27 17:12:20 +00:00
parent d445dc137a
commit 7357d48115

View File

@ -415,12 +415,10 @@ impl OrderManager {
let (open_orders, order_book, open_positions) =
(res_open_orders?, res_order_book?, res_open_positions?);
let position = open_positions
.ok_or("No open positions!")?
.into_iter()
.find(|x| x.id() == position_id)
.ok_or("Position #{} not found in open positions.")?;
// if there are open positions
if let Some(open_positions) = open_positions {
// if we find an open position with the ID we are looking for
if let Some(position) = open_positions.into_iter().find(|x| x.id() == position_id) {
let opt_position_order = open_orders
.iter()
.find(|x| x.current_form.amount().neg() == position.amount());
@ -454,6 +452,8 @@ impl OrderManager {
return Err(e);
}
}
}
}
Ok((None, None))
}