From 46d3fe88cae2873797fac0f3ae731e90bf4e402d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 28 Aug 2022 13:05:06 -0400 Subject: [PATCH] Fix sub-slot-remains limiting for -ve sizes In the short case (-ve size) we had a bug where the last sub-slots worth of exit size would never be limited to zero once the allocator limit pos size was hit (i.e. you could keep going more -ve on the pos, exponentially per slot over the limit). It's a simple fix, just a `max()` around the `l_sub_pp` var used in the next-step-size calc. Resolves #392 --- piker/clearing/_allocate.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index 62b8c115..cdb243d6 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -96,7 +96,7 @@ class Allocator(Struct): def next_order_info( self, - # we only need a startup size for exit calcs, we can the + # we only need a startup size for exit calcs, we can then # determine how large slots should be if the initial pp size was # larger then the current live one, and the live one is smaller # then the initial config settings. @@ -137,12 +137,14 @@ class Allocator(Struct): # an entry (adding-to or starting a pp) if ( - action == 'buy' and live_size > 0 or - action == 'sell' and live_size < 0 or live_size == 0 + or (action == 'buy' and live_size > 0) + or action == 'sell' and live_size < 0 ): - - order_size = min(slot_size, l_sub_pp) + order_size = min( + slot_size, + max(l_sub_pp, 0), + ) # an exit (removing-from or going to net-zero pp) else: