-
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
2 changed files
with
23 additions
and
14 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,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)); | ||
}; |
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