UNPKG

bitx-cli

Version:

Call the BitX API from the command line.

42 lines (34 loc) 990 B
var optimist = require('optimist'), path = require('path'), handlers = require(path.join(__dirname, 'handlers')); module.exports = function() { var argv = optimist .usage('\nAccess the BitX API from the command line.\n\nUsage: bitx [options] [endpoint]') .demand(1) .describe('i', 'BitX API key id') .alias('i', 'key-id') .string('i') .describe('s', 'BitX API key secret') .alias('s', 'key-secret') .string('s') .describe('a', 'Asset type e.g. XBT') .alias('a', 'asset-type') .default('a', 'XBT') .argv; var command = argv._[0]; var handler = handlers(argv.i, argv.s)[command]; if (!handler) { console.log('No endpoint configured for \'%s\'.', command); return; } if (command === 'balance') { handler = handler.bind(this, argv.a); } handler(function(err, result) { if (err) { console.error(err); return; } console.log(JSON.stringify(result)); }); }