Skip to content

Commit

Permalink
fix(orderbook): add back fully matched orders
Browse files Browse the repository at this point in the history
This fixes the functionality of non-strict mode to add peer orders back
to the order book after they were matched but failed to swap. Previously
we would only add back orders that were partially matched, by removing
the remaining order from the order book, adding the partially matched
quantity back to it, and then adding it back to the order book.

This also adds back orders that were fully matched and removed from the
order book during matching after they fail to swap.

Closes #1816.
  • Loading branch information
sangaman committed Aug 23, 2020
1 parent dc6de05 commit c982bef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,13 @@ class OrderBook extends EventEmitter {
removedOrder.quantity += portion.quantity;
failedMakerOrders.push(removedOrder);
} catch (err) {
if (err.code !== errorCodes.ORDER_NOT_FOUND) {
if (err.code === errorCodes.ORDER_NOT_FOUND) {
// if the order has already been removed, either it was removed fully during
// matching or it's been invalidated by a peer or filled by a separate order
// we can safely ignore this exception, otherwise we throw
// in this case we want to add back the order removed during matching
failedMakerOrders.push(maker);
} else {
// for other errors we throw
throw err;
}
}
Expand Down

0 comments on commit c982bef

Please sign in to comment.