Last active
April 6, 2017 18:46
-
-
Save renie/71b42769cd0ae762a5621ffee497e99e to your computer and use it in GitHub Desktop.
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
#!/usr/bin/nodejs | |
var DEFAULT_CURRENCY_PAIR = 'USDT_DASH'; | |
var DEFAULT_CURRENCY_PROPERTY = 'last'; | |
/*============================================*/ | |
/*============================================*/ | |
/*============================================*/ | |
var http = require('https'); | |
var options = { | |
host: 'poloniex.com', | |
path: '/public?command=returnTicker' | |
}; | |
var req = http.request(options, callback); | |
var currency = process.argv[2] || DEFAULT_CURRENCY_PAIR; | |
var prop = process.argv[3] || DEFAULT_CURRENCY_PROPERTY; | |
req.on('error', function(e) { | |
console.error(e); | |
}); | |
req.end(); | |
function callback(response) { | |
var str = ''; | |
response.on('data', function (chunk) { | |
str += chunk; | |
}); | |
response.on('end', function () { | |
if (parseInt(response.statusCode) > 400) { | |
console.log('An error occured on request. HTTP ERROR CODE:' + response.statusCode); | |
return false; | |
} | |
console.log(JSON.parse(str)[currency][prop]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment