added slippage when submitting stop order
This commit is contained in:
		
							parent
							
								
									0df1511a59
								
							
						
					
					
						commit
						4df9e38569
					
				@ -280,13 +280,18 @@ impl PositionStrategy for HiddenTrailingStop {
 | 
				
			|||||||
            })
 | 
					            })
 | 
				
			||||||
            .next().map_or_else(|| 0.0, |&x| x);
 | 
					            .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 = {
 | 
					        let stop_loss_price = {
 | 
				
			||||||
            if position.is_short() {
 | 
					            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 {
 | 
					            } 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 {
 | 
					        let close_position_orders_msg = ActionMessage::ClosePositionOrders {
 | 
				
			||||||
            position_id: position.id(),
 | 
					            position_id: position.id(),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user