Created
April 27, 2013 11:43
-
-
Save ralphtheninja/5472811 to your computer and use it in GitHub Desktop.
Simple cli ticker that fetches data from MtGox. Run with node, no extra modules needed.
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/env node | |
| var http = require('http') | |
| var options = { | |
| hostname: 'data.mtgox.com' | |
| , path: '/api/2/BTCUSD/money/ticker' | |
| , method: 'GET' | |
| } | |
| var req = http.request(options, function (res) { | |
| var result = '' | |
| res.on('data', function (data) { | |
| result += data | |
| }) | |
| res.on('end', function () { | |
| var data = JSON.parse(result) | |
| if (data.result && data.result == 'success') { | |
| data = data.data | |
| var maxLength = maxElementLength(Object.keys(data)) | |
| Object.keys(data).forEach(function (key) { | |
| var value = data[key] | |
| if ('object' === typeof value && value.value) { | |
| console.log(key + separator(key, maxLength) + value.value) | |
| } | |
| }) | |
| } | |
| }) | |
| function maxElementLength(array) { | |
| array = array.map(function (el) { return el.length }) | |
| return Math.max.apply(null, array) | |
| } | |
| function separator(key, max) { | |
| var result = ': ' | |
| for (var i = 0; i < max - key.length; ++i) { | |
| result += ' ' | |
| } | |
| return result | |
| } | |
| }) | |
| req.end() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/ralphtheninja/goxtick/blob/master/index.js version 0.0.1 on npm, only supports USD for now.