Skip to content

Commit

Permalink
Merge pull request #1985 from ExchangeUnion/revert-1958-feature/remov…
Browse files Browse the repository at this point in the history
…eorder-output-#1526

Revert "feat: removeorder output changed to a more meaningful message (#1526)"
  • Loading branch information
Karl Ranna authored Nov 10, 2020
2 parents 0218553 + 1eabf6d commit 1105151
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 438 deletions.
3 changes: 0 additions & 3 deletions docs/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 3 additions & 15 deletions lib/cli/commands/removeorder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Arguments, Argv } from 'yargs';
import { RemoveOrderRequest, RemoveOrderResponse } from '../../proto/xudrpc_pb';
import { RemoveOrderRequest } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';
import { coinsToSats, satsToCoinsStr } from '../utils';
import { coinsToSats } from '../utils';

export const command = 'removeorder <order_id> [quantity]';

Expand All @@ -18,23 +18,11 @@ export const builder = (argv: Argv) => argv
.example('$0 removeorder 79d2cd30-8a26-11ea-90cf-439fb244cf44', 'remove an order by id')
.example('$0 removeorder 79d2cd30-8a26-11ea-90cf-439fb244cf44 0.1', 'remove 0.1 quantity from an order by id');

const displayOutput = (orderId: string, removeOrderResponse: RemoveOrderResponse.AsObject) => {
const removedCurrency = removeOrderResponse.pairId.split('/')[0];
if (removeOrderResponse.quantityOnHold === 0 && removeOrderResponse.remainingQuantity === 0) {
console.log(`Order ${orderId} successfully removed.`);
} else {
console.log(`
Order ${orderId} partially removed, remaining quantity: \
${satsToCoinsStr(removeOrderResponse.remainingQuantity)} ${removedCurrency}, \
on hold: ${satsToCoinsStr(removeOrderResponse.quantityOnHold)} ${removedCurrency}`);
}
};

export const handler = async (argv: Arguments<any>) => {
const request = new RemoveOrderRequest();
request.setOrderId(argv.order_id);
if (argv.quantity) {
request.setQuantity(coinsToSats(argv.quantity));
}
(await loadXudClient(argv)).removeOrder(request, callback(argv, displayOutput.bind(undefined, argv.order_id)));
(await loadXudClient(argv)).removeOrder(request, callback(argv));
};
7 changes: 2 additions & 5 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,9 @@ class GrpcService {
return;
}
try {
const { removedQuantity, remainingQuantity, onHoldQuantity, pairId } = this.service.removeOrder(call.request.toObject());
const quantityOnHold = this.service.removeOrder(call.request.toObject());
const response = new xudrpc.RemoveOrderResponse();
response.setQuantityOnHold(onHoldQuantity);
response.setRemainingQuantity(remainingQuantity);
response.setRemovedQuantity(removedQuantity);
response.setPairId(pairId);
response.setQuantityOnHold(quantityOnHold);
callback(null, response);
} catch (err) {
callback(getGrpcError(err), null);
Expand Down
19 changes: 3 additions & 16 deletions lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,8 @@ class OrderBook extends EventEmitter {
const onHoldOrderLocalIds = [];

for (const localId of this.localIdMap.keys()) {
const { onHoldQuantity } = this.removeOwnOrderByLocalId(localId, true);
if (onHoldQuantity === 0) {
const onHoldIndicator = this.removeOwnOrderByLocalId(localId, true);
if (onHoldIndicator === 0) {
removedOrderLocalIds.push(localId);
} else {
onHoldOrderLocalIds.push(localId);
Expand All @@ -863,9 +863,6 @@ class OrderBook extends EventEmitter {
const order = this.getOwnOrderByLocalId(localId);

let remainingQuantityToRemove = quantityToRemove || order.quantity;
const orderQuantity = order.quantity;
let onHoldQuantity = order.hold;
let removedQuantity = 0;

if (remainingQuantityToRemove > order.quantity) {
// quantity to be removed can't be higher than order's quantity.
Expand All @@ -879,7 +876,6 @@ class OrderBook extends EventEmitter {
pairId: order.pairId,
quantityToRemove: remainingQuantityToRemove,
});
removedQuantity += remainingQuantityToRemove;
remainingQuantityToRemove = 0;
} else {
// we can't immediately remove the entire quantity because of a hold on the order.
Expand All @@ -894,7 +890,6 @@ class OrderBook extends EventEmitter {
pairId: order.pairId,
quantityToRemove: removableQuantity,
});
removedQuantity += removableQuantity;
remainingQuantityToRemove -= removableQuantity;
}

Expand All @@ -920,8 +915,6 @@ class OrderBook extends EventEmitter {

const cleanup = (quantity: number) => {
remainingQuantityToRemove -= quantity;
removedQuantity += quantity;
onHoldQuantity -= quantity;
this.logger.debug(`removed hold of ${quantity} on local order ${localId}, ${remainingQuantityToRemove} remaining`);
if (remainingQuantityToRemove === 0) {
// we can stop listening for swaps once all holds are cleared
Expand All @@ -934,13 +927,7 @@ class OrderBook extends EventEmitter {
this.swaps.on('swap.paid', paidHandler);
}

const remainingFromOrder = orderQuantity - removedQuantity;
return {
removedQuantity,
onHoldQuantity,
pairId: order.pairId,
remainingQuantity: remainingFromOrder > onHoldQuantity ? remainingFromOrder : 0,
};
return remainingQuantityToRemove;
}

private addOrderHold = (orderId: string, pairId: string, holdAmount?: number) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/annotations_grpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/proto/xudp2p_grpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions lib/proto/xudrpc.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions lib/proto/xudrpc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 1 addition & 82 deletions lib/proto/xudrpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions proto/xudrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,6 @@ message RemoveOrderResponse {
// Any portion of the order that was on hold due to ongoing swaps at the time of the request
// and could not be removed until after the swaps finish.
uint64 quantity_on_hold = 1 [json_name = "hold"];
// Remaining portion of the order if it was a partial removal.
uint64 remaining_quantity = 2 [json_name = "remaining_quantity"];
// Successfully removed portion of the order.
uint64 removed_quantity = 3 [json_name = "removed_quantity"];
// Removed order's pairId. (e.g. ETH/BTC)
string pair_id = 4 [json_name = "pair_id"];
}

message RemoveAllOrdersRequest {}
Expand Down
Loading

0 comments on commit 1105151

Please sign in to comment.