Skip to content

Instantly share code, notes, and snippets.

@mrnejc
Last active October 8, 2015 22:15
Show Gist options
  • Save mrnejc/57620f43bf6b9b3f18bd to your computer and use it in GitHub Desktop.
Save mrnejc/57620f43bf6b9b3f18bd to your computer and use it in GitHub Desktop.
(quick and dirty) Gemini bitcoin exchange order-book listrequires node, run with node gemini.js
var https = require('https');
var options = {
hostname: 'api.gemini.com',
port: 443,
method: 'GET',
path: '/v1/book/btcusd'
};
var rLimit = 10; // number of results
var refresh = 5; // in seconds
var reqCallback = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
var data = JSON.parse(str);
// clear the console
console.log('\033[2J');
console.log(new Date());
console.log();
console.log("ASKS (%d/%d):", rLimit, data.asks.length);
for(var i=0; i<data.asks.length; i++) {
console.log("\t%s\t%s", data.asks[i].price, data.asks[i].amount);
if(i+1==rLimit) {
break;
}
}
console.log("BIDS (%d/%d):", rLimit, data.bids.length);
for(var i=0; i<data.bids.length; i++) {
console.log("\t%s\t%s", data.bids[i].price, data.bids[i].amount);
if(i+1==rLimit) {
break;
}
}
});
}
function doReq() {
var req = https.request(options, reqCallback);
req.on('error', function() {
console.log('error in request');
});
req.end();
}
setInterval(doReq, refresh * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment