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 6, 2020
1 parent e1bbf5e commit 50a77bc
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/cli/commands/addpair.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
import { Arguments } from 'yargs';
import { callback, loadXudClient } from '../command';
import { Arguments, CommandBuilder } 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>';

export const describe = 'add a trading pair';

export const builder = {
export const builder: CommandBuilder = {
pair: {
description: 'the trading pair in ticker format such as LTC/BTC',
type: 'string',
},
base_currency: {
description: 'the currency bought and sold for this trading pair',
type: 'string',
alias: 'b',
},
quote_currency: {
description: 'the currency used to quote a price',
type: 'string',
alias: 'q',
},
};

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.pair) {
if (argv.base_currency || argv.quote_currency) {
console.error('cannot specify both pair and base or quote currency');
process.exit(1);
}
[baseCurrency, quoteCurrency] = argv.pair.split('/');
} else {
baseCurrency = argv.base_currency;
quoteCurrency = argv.quote_currency;
}
request.setBaseCurrency(baseCurrency.toUpperCase());
request.setQuoteCurrency(quoteCurrency.toUpperCase());
(await loadXudClient(argv)).addPair(request, callback(argv));
};

0 comments on commit 50a77bc

Please sign in to comment.