@@ -313,7 +313,7 @@ pub fn calc_next_close_long(
313313 trailing_allocation = 0.0 ;
314314 }
315315 let grid_allocation = round_ (
316- position. size - trailing_allocation,
316+ ( position. size - trailing_allocation) * 1.01 , // add 1% to avoid hitting the threshold exactly
317317 exchange_params. qty_step ,
318318 ) ;
319319 let position_mod = Position {
@@ -340,8 +340,10 @@ pub fn calc_next_close_long(
340340 if grid_allocation < min_entry_qty {
341341 grid_allocation = 0.0 ;
342342 }
343- let trailing_allocation =
344- round_ ( position. size - grid_allocation, exchange_params. qty_step ) ;
343+ let trailing_allocation = round_ (
344+ ( position. size - grid_allocation) * 1.01 ,
345+ exchange_params. qty_step ,
346+ ) ;
345347 let position_mod = Position {
346348 size : f64:: min ( position. size , f64:: max ( trailing_allocation, min_entry_qty) ) ,
347349 price : position. price ,
@@ -632,7 +634,7 @@ pub fn calc_next_close_short(
632634 trailing_allocation = 0.0 ;
633635 }
634636 let grid_allocation = round_ (
635- position_size_abs - trailing_allocation,
637+ ( position_size_abs - trailing_allocation) * 1.01 ,
636638 exchange_params. qty_step ,
637639 ) ;
638640 let position_mod = Position {
@@ -659,7 +661,7 @@ pub fn calc_next_close_short(
659661 grid_allocation = 0.0 ;
660662 }
661663 let trailing_allocation = round_ (
662- position_size_abs - grid_allocation,
664+ ( position_size_abs - grid_allocation) * 1.01 ,
663665 exchange_params. qty_step ,
664666 ) ;
665667 let position_mod = Position {
0 commit comments