From 4a563e4e90e75e06cef96480b01067b4addc4728 Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Thu, 28 May 2026 07:41:12 +0000 Subject: [PATCH] fix: correct match handler to update order sizes properly (closes #278) --- cbpro/order_book.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cbpro/order_book.py b/cbpro/order_book.py index 1a8525e5..173f0405 100644 --- a/cbpro/order_book.py +++ b/cbpro/order_book.py @@ -120,6 +120,32 @@ def remove(self, order): def match(self, order): size = Decimal(order['size']) price = Decimal(order['price']) + if order['side'] == 'buy': + bids = self.get_bids(price) + if bids is not None: + for bid in bids: + if bid['id'] == order['maker_order_id']: + bid['size'] -= size + if bid['size'] <= 0: + bids.remove(bid) + break + if len(bids) > 0: + self.set_bids(price, bids) + else: + self.remove_bids(price) + else: + asks = self.get_asks(price) + if asks is not None: + for ask in asks: + if ask['id'] == order['maker_order_id']: + ask['size'] -= size + if ask['size'] <= 0: + asks.remove(ask) + break + if len(asks) > 0: + self.set_asks(price, asks) + else: + self.remove_asks(price) Decimal(order['price']) if order['side'] == 'buy': bids = self.get_bids(price)