Skip to content

Commit 2f407d0

Browse files
committed
feat(cli): print no more matches on partial mkt
This ensures that a "no more matches" message is printed by the cli when a market order is only partially matched due to no more orders in the order book. It does this by tracking the remaining quantity. Previously, a message would only get printed if the matching ended on a failed swap, but didn't cover the case where there were simply no more orders available in the order book. Closes #1596.
1 parent 116ffc0 commit 2f407d0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Diff for: lib/cli/placeorder.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export const placeOrderHandler = async (argv: Arguments<any>, side: OrderSide) =
4949
const numericPrice = Number(argv.price);
5050
const priceStr = argv.price.toLowerCase();
5151

52-
request.setQuantity(coinsToSats(argv.quantity));
52+
const quantity = coinsToSats(argv.quantity);
53+
request.setQuantity(quantity);
5354
request.setSide(side);
5455
request.setPairId(argv.pair_id.toUpperCase());
5556
request.setImmediateOrCancel(argv.ioc);
@@ -80,7 +81,7 @@ export const placeOrderHandler = async (argv: Arguments<any>, side: OrderSide) =
8081
} else {
8182
const subscription = client.placeOrder(request);
8283
let noMatches = true;
83-
let lastEventIsSwapFailure = false;
84+
let remainingQuantity = quantity;
8485
subscription.on('data', (response: PlaceOrderEvent) => {
8586
if (argv.json) {
8687
console.log(JSON.stringify(response.toObject(), undefined, 2));
@@ -92,30 +93,28 @@ export const placeOrderHandler = async (argv: Arguments<any>, side: OrderSide) =
9293
if (orderMatch) {
9394
noMatches = false;
9495
if (orderMatch.getIsOwnOrder()) {
96+
remainingQuantity -= orderMatch.getQuantity();
9597
formatInternalMatch(orderMatch.toObject());
9698
} else {
9799
formatPeerMatch(orderMatch.toObject());
98100
}
99101
} else if (swapSuccess) {
100102
noMatches = false;
101-
lastEventIsSwapFailure = false;
103+
remainingQuantity -= swapSuccess.getQuantity();
102104
formatSwapSuccess(swapSuccess.toObject());
103105
} else if (remainingOrder) {
104-
lastEventIsSwapFailure = false;
105106
formatRemainingOrder(remainingOrder.toObject());
107+
remainingQuantity = 0;
106108
} else if (swapFailure) {
107-
lastEventIsSwapFailure = true;
108109
formatSwapFailure(swapFailure.toObject());
109110
}
110111
}
111112
});
112113
subscription.on('end', () => {
113114
if (noMatches) {
114115
console.log('no matches found');
115-
} else if (lastEventIsSwapFailure) {
116-
// if we ended on a swap failure, it means we had a market order that
117-
// did not get fully match, we should let user know
118-
console.log('no more matches found');
116+
} else if (remainingQuantity > 0) {
117+
console.log(`no more matches found, ${satsToCoinsStr(remainingQuantity)} qty will be discarded`);
119118
}
120119
});
121120
subscription.on('error', (err) => {

0 commit comments

Comments
 (0)