asx-data
Version:
Australian Securities Exchange Data API Wrapper
61 lines (49 loc) • 1.26 kB
JavaScript
var http = require("http");
var data = function (options, result, error) {
options = options || {};
options.interval = options.interval || 'daily';
options.count = options.count || 1;
if (!(this instanceof data)) {
return new data({
code: options.code,
interval: options.interval,
count: options.count
}, result, error);
}
var path =
'/data/1/share/' + options.code +
'/prices?interval=' + options.interval +
'&count=' + options.count;
var httpOptions = {
host: 'data.asx.com.au',
port: 80,
path: path,
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
var req = http.request(httpOptions, function(res)
{
var output = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', function() {
var obj = JSON.parse(output);
result(res.statusCode, obj);
});
});
req.on('error', function(err) {
error(err);
});
req.end();
};
/**
* @module
* @type {data}
*/
module.exports = {
data: data
};