Created
August 3, 2017 14:56
-
-
Save rebers/d7d80f4b5549c583e1e431e1836e4f97 to your computer and use it in GitHub Desktop.
A badly written node script that calculates how much your altcoins are worth on the Bittrex exchange.
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
const crypto = require('crypto'); | |
const http = require('request'); | |
const apiKey= ''; | |
const apiSecret = ''; | |
const hash = crypto.createHmac('sha512', apiSecret) | |
let nonce = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5); | |
let url = `https://bittrex.com/api/v1.1/account/getbalances?apikey=${apiKey}&nonce=${nonce}`; | |
hash.update(url); | |
let apiSign = hash.digest('hex'); | |
const options = { | |
url, | |
headers: { | |
'apisign': apiSign, | |
} | |
}; | |
http.get(options, (error, response, body) => { | |
const balances = JSON.parse(body).result; | |
const btcBalances = {}; | |
http.get('https://bittrex.com/api/v1.1/public/getmarketsummaries', (error, response, body) => { | |
const marketSummaries = JSON.parse(body).result; | |
const USDT = marketSummaries.find((item) => { | |
return item.MarketName === 'USDT-BTC'; | |
}); | |
balances.forEach((balanceItem) => { | |
if (['USDT', 'BTC', 'ETH'].includes(balanceItem.Currency) === true) { | |
// Ignore very low balances and base currencies | |
return; | |
} | |
const market = marketSummaries.find((marketItem) => { | |
return marketItem.MarketName === `BTC-${balanceItem.Currency}`; | |
}); | |
btcBalances[balanceItem.Currency] = balanceItem.Balance * market.Ask; | |
}); | |
const sumBtc = balances.find((balanceItem) => balanceItem.Currency === 'BTC').Balance; | |
const sumBtcAlts = Object.keys(btcBalances).reduce((acc, value) => acc + btcBalances[value], 0); | |
const totalBtc = sumBtc + sumBtcAlts; | |
console.log('Bitcoin: ', sumBtc); | |
console.log('Alts: ', sumBtcAlts); | |
console.log('Total Value in BTC:', totalBtc); | |
process.exit(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment