Skip to content

Commit

Permalink
Rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Oct 20, 2020
2 parents 8f28b63 + c958e86 commit e2ff8c2
Show file tree
Hide file tree
Showing 12 changed files with 986 additions and 266 deletions.
29 changes: 29 additions & 0 deletions docs/api.md

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

29 changes: 29 additions & 0 deletions lib/cli/commands/removeallorders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Arguments, Argv } from 'yargs';
import { RemoveAllOrdersRequest, RemoveAllOrdersResponse } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';

export const command = 'removeallorders';

export const describe = 'removes all orders';

export const builder = (argv: Argv) => argv
.example('$0 removeallorders', describe);

const formatOutput = (response: RemoveAllOrdersResponse.AsObject) => {
if (response.removedOrderIdsList.length <= 0 && response.onHoldOrderIdsList.length <= 0) {
console.log('No orders found');
return;
}

if (response.removedOrderIdsList.length) {
response.removedOrderIdsList.forEach((removedOrder => console.log(`Removed order with id ${removedOrder}`)));
}
if (response.onHoldOrderIdsList.length) {
response.onHoldOrderIdsList.forEach((id => console.log(`Order with id ${id} has a hold for a pending swap and will be removed afterwards`)));
}

};

export const handler = async (argv: Arguments<any>) => {
(await loadXudClient(argv)).removeAllOrders(new RemoveAllOrdersRequest(), callback(argv, formatOutput));
};
20 changes: 20 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ class GrpcService {
}
}

/**
* See [[Service.removeAllOrders]]
*/
public removeAllOrders: grpc.handleUnaryCall<xudrpc.RemoveAllOrdersRequest, xudrpc.RemoveAllOrdersResponse> = async (_, callback) => {
if (!this.isReady(this.service, callback)) {
return;
}
try {
const { removedOrderLocalIds, onHoldOrderLocalIds } = await this.service.removeAllOrders();

const response = new xudrpc.RemoveAllOrdersResponse();
response.setRemovedOrderIdsList(removedOrderLocalIds);
response.setOnHoldOrderIdsList(onHoldOrderLocalIds);

callback(null, response);
} catch (err) {
callback(getGrpcError(err), null);
}
}

/**
* See [[Service.getBalance]]
*/
Expand Down
16 changes: 16 additions & 0 deletions lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,22 @@ class OrderBook extends EventEmitter {
return order;
}

public removeOwnOrders = () => {
const removedOrderLocalIds = [];
const onHoldOrderLocalIds = [];

for (const localId of this.localIdMap.keys()) {
const onHoldIndicator = this.removeOwnOrderByLocalId(localId, true);
if (onHoldIndicator === 0) {
removedOrderLocalIds.push(localId);
} else {
onHoldOrderLocalIds.push(localId);
}
}

return { removedOrderLocalIds, onHoldOrderLocalIds };
}

/**
* Removes all or part of an order from the order book by its local id. Throws an error if the
* specified pairId is not supported or if the order to cancel could not be found.
Expand Down
49 changes: 49 additions & 0 deletions lib/proto/xudrpc.swagger.json

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

17 changes: 17 additions & 0 deletions lib/proto/xudrpc_grpc_pb.d.ts

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

37 changes: 37 additions & 0 deletions lib/proto/xudrpc_grpc_pb.js

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

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

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

Loading

0 comments on commit e2ff8c2

Please sign in to comment.