Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions cbpro/order_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down