diff --git a/commands/_codemap.js b/commands/_codemap.js index 2a1b634491..2f16f627d5 100644 --- a/commands/_codemap.js +++ b/commands/_codemap.js @@ -6,6 +6,7 @@ module.exports = { 'list-strategies': require('./list-strategies'), 'backfill': require('./backfill'), 'sim': require('./sim'), + 'balance': require('./balance'), 'trade': require('./trade'), 'buy': require('./buy'), 'sell': require('./sell'), @@ -14,7 +15,8 @@ module.exports = { 'list[30]': '#commands.list-strategies', 'list[50]': '#commands.backfill', 'list[60]': '#commands.sim', + 'list[65]': '#commands.balance', 'list[70]': '#commands.trade', 'list[80]': '#commands.buy', 'list[90]': '#commands.sell' -} \ No newline at end of file +} diff --git a/commands/balance.js b/commands/balance.js new file mode 100644 index 0000000000..a613db0b6d --- /dev/null +++ b/commands/balance.js @@ -0,0 +1,41 @@ +var minimist = require('minimist') + , n = require('numbro') + , colors = require('colors') + +module.exports = function container (get, set, clear) { + var c = get('conf') + return function (program) { + program + .command('balance [selector]') + .allowUnknownOption() + .description('get asset and currency balance from the exchange') + //.option('--all', 'output all balances') + .option('--debug', 'output detailed debug info') + .action(function (selector, cmd) { + var s = {options: minimist(process.argv)} + s.selector = get('lib.normalize-selector')(selector || c.selector) + var exch = s.selector.split('.')[0] + s.exchange = get('exchanges.' + exch) + s.product_id = s.selector.split('.')[1] + s.asset = s.product_id.split('-')[0] + s.currency = s.product_id.split('-')[1] + var so = s.options + delete so._ + Object.keys(c).forEach(function (k) { + if (typeof cmd[k] !== 'undefined') { + so[k] = cmd[k] + } + }) + so.debug = cmd.debug + function balance () { + s.exchange.getBalance(s, function (err, balance) { + if (err) return cb(err) + var bal = s.product_id + ' Asset: ' + balance.asset + ' Currency: ' + balance.currency + console.log(bal) + process.exit() + }) + } + balance() + }) + } +}