Skip to content

Commit b7fa00a

Browse files
committed
feat(orderbook): better replace order hold message
This returns a clearer error message when the user attempts to replace an order that is on hold via rpc, which is not allowed.
1 parent 1b397db commit b7fa00a

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

Diff for: lib/grpc/getGrpcError.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const getGrpcError = (err: any) => {
4949
case orderErrorCodes.MARKET_ORDERS_NOT_ALLOWED:
5050
case serviceErrorCodes.NOMATCHING_MODE_IS_REQUIRED:
5151
case orderErrorCodes.INSUFFICIENT_OUTBOUND_BALANCE:
52+
case orderErrorCodes.QUANTITY_ON_HOLD:
5253
case swapErrorCodes.SWAP_CLIENT_NOT_FOUND:
5354
case swapErrorCodes.SWAP_CLIENT_MISCONFIGURED:
5455
code = status.FAILED_PRECONDITION;

Diff for: lib/orderbook/OrderBook.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,10 @@ class OrderBook extends EventEmitter {
480480
}
481481
}
482482

483-
assert(!(replaceOrderId && discardRemaining), 'can not replace order and discard remaining order');
484483
let replacedOrderIdentifier: OrderIdentifier | undefined;
485484
if (replaceOrderId) {
485+
assert(!discardRemaining, 'can not replace order and discard remaining order');
486+
486487
// put the order we are replacing on hold while we place the new order
487488
replacedOrderIdentifier = this.localIdMap.get(replaceOrderId);
488489
if (!replacedOrderIdentifier) {

Diff for: lib/orderbook/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const errors = {
7272
code: errorCodes.MIN_QUANTITY_VIOLATED,
7373
}),
7474
QUANTITY_ON_HOLD: (localId: string, holdQuantity: number) => ({
75-
message: `order with local id ${localId} has a quantity of ${holdQuantity} on hold`,
75+
message: `order with local id ${localId} has a quantity of ${holdQuantity} satoshis on hold, try again later`,
7676
code: errorCodes.QUANTITY_DOES_NOT_MATCH,
7777
}),
7878
};

0 commit comments

Comments
 (0)