Last active
January 9, 2018 15:32
-
-
Save AlexSJ/5647cffac7d1ec3023aaf4bccb182f2c to your computer and use it in GitHub Desktop.
Valores em BTC e USD da Binance
This file contains hidden or 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 api = require('binance'); | |
const binanceRest = new api.BinanceRest({ | |
//key: 'api-key', // Get this from your account on binance.com | |
//secret: 'api-secret', // Same for this | |
timeout: 15000, // Optional, defaults to 15000, is the request time out in milliseconds | |
recvWindow: 10000, // Optional, defaults to 5000, increase if you're getting timestamp errors | |
disableBeautification: false | |
}); | |
var time = new Date(); | |
console.log(time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()); | |
binanceRest.ticker24hr({ | |
symbol: 'BTCUSDT' | |
}).then((resBtc) => { | |
let valor_btc_to_usd = resBtc['lastPrice']; | |
binanceRest.allPrices() | |
.then((resAll) => { | |
let totalEmBTC = 0, | |
coins = ['ENGBTC', 'DNTBTC', 'CNDBTC', 'TNBBTC', 'POEBTC', 'FUELBTC', 'MANABTC'], | |
coisQtn = [22, 666, 599, 599, 499, 499, 399]; | |
for (var i = resAll.length - 1; i >= 0; i--) { | |
let position = coins.indexOf(resAll[i].symbol); | |
if (position >= 0) { | |
totalEmBTC += Number(resAll[i].price * coisQtn[position]); | |
let emBtc = Number(resAll[i].price * coisQtn[position]).toFixed(8); | |
console.log(resAll[i].symbol + " / Total: " + coisQtn[position] + " / Em BTC: " + emBtc + " / Em USD: " + Number(emBtc * valor_btc_to_usd).toFixed(2) + " / Em USD por Unidade: " + Number(Number(emBtc * valor_btc_to_usd).toFixed(2) / coisQtn[position]).toFixed(5)); | |
} | |
} | |
console.log("Total em BTC: " + totalEmBTC.toFixed(8)); | |
console.log("Total em USD: " + Number(totalEmBTC * valor_btc_to_usd).toFixed(2)); | |
}); | |
}); |
This file contains hidden or 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
{ | |
"name": "binance-api", | |
"version": "1.0.0", | |
"description": "API Binance", | |
"main": "index.js", | |
"scripts": { | |
"start": "node index.js", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"binance": "^1.1.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment