added slippage when submitting stop order

This commit is contained in:
Giulio De Pasquale 2021-02-22 10:03:48 +00:00
parent 0df1511a59
commit 4df9e38569

View File

@ -280,13 +280,18 @@ impl PositionStrategy for HiddenTrailingStop {
})
.next().map_or_else(|| 0.0, |&x| x);
// we need to consider possible slippage when executing the stop order
let slippage_percentage = self.max_loss_percentage * 0.05;
// calculating the stop price based on short/long position
let stop_loss_price = {
if position.is_short() {
position.base_price() * (1.0 - (self.max_loss_percentage - taker_fee) / 100.0)
position.base_price() * (1.0 - (self.max_loss_percentage - taker_fee - slippage_percentage) / 100.0)
} else {
position.base_price() * (1.0 + (self.max_loss_percentage - taker_fee) / 100.0)
position.base_price() * (1.0 + (self.max_loss_percentage - taker_fee - slippage_percentage) / 100.0)
}
};
let close_position_orders_msg = ActionMessage::ClosePositionOrders {
position_id: position.id(),
};