Last active
October 25, 2017 05:32
-
-
Save kebman/6a6fb04e55b803841b8c8397240ca113 to your computer and use it in GitHub Desktop.
Get Bitcoin BTC/USD quotes from Bitstamp.net using Node.js
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
/* | |
* Small Node.js script that gets BTC/USD quotes from www.bitstamp.net | |
* from https://www.bitstamp.net/api/v2/ticker/BTCUSD/ | |
*/ | |
const https = require('https'); // because the URL is https | |
const quoteOptions = { | |
host: 'www.bitstamp.net', | |
port: 443, // because https default | |
path: '/api/v2/ticker/BTCUSD/', | |
method: 'GET', | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
} | |
https.get(quoteOptions, function (response) { | |
response.on('data', function (data) { | |
/* | |
* The response data contains the following keys: | |
* high, last, timestamp (UNIX), bid, vwap (volume weighted average), volume, low, ask, and open | |
*/ | |
let quote = JSON.parse(data); | |
// example: | |
console.log("\u02431 = $"+quote.last, "on "+Date(quote.timestamp)); // or pass it to a web page | |
// \u0243 is the BTC symbol | |
}); | |
}).on('error', function (e) { | |
console.log(e.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment