Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
New command "zenbot balance <selector>" (#243)
Browse files Browse the repository at this point in the history
* Add files via upload

* Delete exchanges.md

* Create exchanges.md

* Delete exchanges.md

* Create developers.md

* Update developers.md

* Update developers.md

* New command "zenbot balance <selector>"

Introduces a new comand:
"zenbot balance <selector>"
Sample output: 
BTC-USD Asset: 9.87654321. Currency: 1.23

* New command "zenbot balance <selector>"
  • Loading branch information
tuxitor authored and DeviaVir committed Jun 9, 2017
1 parent 6534aad commit eb14db9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion commands/_codemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'
}
}
41 changes: 41 additions & 0 deletions commands/balance.js
Original file line number Diff line number Diff line change
@@ -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()
})
}
}

0 comments on commit eb14db9

Please sign in to comment.