Created
September 29, 2016 07:31
-
-
Save vega113/00840178bd8024f4df4eba0e711fde05 to your computer and use it in GitHub Desktop.
Check balances in bittrex
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
var bittrex = require('./node.bittrex.api.js'); | |
bittrex.options({ | |
'apikey': '', | |
'apisecret': '', | |
'stream': false, | |
'verbose': false, | |
'cleartext': false | |
}); | |
var total = 0; | |
function checkRate(tickerData) { | |
var ticker = {}; | |
ticker.currency = tickerData.Currency; | |
ticker.balance = tickerData.Balance; | |
if (tickerData.Currency == "BTC") { | |
total += tickerData.Balance; | |
console.log(ticker.currency + ": " + ticker.balance ) | |
console.log("-------total in BTC: " + total + " -------------"); | |
} | |
else { | |
var url = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-" + tickerData.Currency; | |
bittrex.sendCustomRequest(url, function (marketData) { | |
if (marketData.result == null) { | |
console.log("no market data for " + tickerData.Currency); | |
} | |
var rate = marketData.result.Last; | |
ticker.btcValue = tickerData.Balance * rate; | |
total += ticker.btcValue; | |
console.log(ticker.currency + ": " + ticker.balance + ", rate: " + rate + ", total btc: " + ticker.btcValue) | |
console.log("-------total in BTC: " + total + " -------------"); | |
}); | |
} | |
} | |
bittrex.getbalances(function (data) { | |
data.result.forEach(function (tickerData) { | |
if (tickerData.Balance > 0) { | |
checkRate(tickerData); | |
} | |
}); | |
}); |
FYI this errors out for USDT (marketData.result) - because the market is USDT-BTC, rather than BTC-USDT.
Pretty easy fix though, thanks for sharing!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@akshayjadhav382011 https://github.com/dparlevliet/node.bittrex.api