Skip to content

Commit

Permalink
feat(cli): use ticker format for addpair
Browse files Browse the repository at this point in the history
This modifies the `addpair` command to use the trading pair ticker
format such as LTC/BTC used in different commands, while keeping the
ability to specify currencies separately.

Related issue #1521.
  • Loading branch information
sangaman committed May 7, 2020
1 parent e1bbf5e commit b8b0f9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
33 changes: 21 additions & 12 deletions lib/cli/commands/addpair.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import { Arguments } from 'yargs';
import { callback, loadXudClient } from '../command';
import { Arguments, Argv } from 'yargs';
import { AddPairRequest } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';

export const command = 'addpair <base_currency> <quote_currency>';
export const command = 'addpair <pair_id|base_currency> [quote_currency]';

export const describe = 'add a trading pair';

export const builder = {
base_currency: {
description: 'the currency bought and sold for this trading pair',
export const builder = (argv: Argv) => argv
.positional('pair_id', {
description: 'the pair ticker id or base currency',
type: 'string',
},
quote_currency: {
})
.positional('quote_currency', {
description: 'the currency used to quote a price',
type: 'string',
},
};
})
.example('$0 addpair LTC/BTC', 'add the LTC/BTC trading pair by ticker id')
.example('$0 addpair LTC BTC', 'add the LTC/BTC trading pair by currencies');

export const handler = async (argv: Arguments<any>) => {
const request = new AddPairRequest();
request.setBaseCurrency(argv.base_currency.toUpperCase());
request.setQuoteCurrency(argv.quote_currency.toUpperCase());
let baseCurrency: string;
let quoteCurrency: string;
if (argv.base_currency && argv.quote_currency) {
baseCurrency = argv.base_currency;
quoteCurrency = argv.quote_currency;
} else {
[baseCurrency, quoteCurrency] = argv.pair_id.split('/');
}
request.setBaseCurrency(baseCurrency.toUpperCase());
request.setQuoteCurrency(quoteCurrency.toUpperCase());
(await loadXudClient(argv)).addPair(request, callback(argv));
};
4 changes: 2 additions & 2 deletions lib/cli/commands/openchannel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arguments } from 'yargs';
import { Arguments, CommandBuilder } from 'yargs';
import { callback, loadXudClient } from '../command';
import { OpenChannelRequest } from '../../proto/xudrpc_pb';
import { coinsToSats } from '../utils';
Expand All @@ -7,7 +7,7 @@ export const command = 'openchannel <currency> <amount> [node_identifier] [push_

export const describe = 'open a payment channel with a peer';

export const builder = {
export const builder: CommandBuilder = {
node_identifier: {
description: 'the node key or alias of the connected peer to open the channel with',
type: 'string',
Expand Down

0 comments on commit b8b0f9b

Please sign in to comment.