-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): use ticker format for addpair
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
Showing
1 changed file
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; |