google-finance
Advanced tools
Comparing version
@@ -155,7 +155,7 @@ var assert = require('assert'); | ||
}, {concurrency: os.cpus().length}) | ||
.then(function (result) { | ||
.then(function (results) { | ||
if (options.symbols) { | ||
return _.zipObject(symbols, result); | ||
return _.zipObject(symbols, results); | ||
} else { | ||
return result[0]; | ||
return results[0]; | ||
} | ||
@@ -177,28 +177,32 @@ }) | ||
.map(function (symbol) { | ||
return Promise.resolve() | ||
.then(function () { | ||
return _utils.download(_constants.HISTORICAL_URL, { | ||
q: symbol, | ||
startdate: options.from.format('YYYY-MM-DD'), | ||
enddate: options.to.format('YYYY-MM-DD'), | ||
output: 'csv' | ||
}); | ||
return Promise.resolve(_utils.getDateRanges(options.from, options.to)) | ||
.map(function (range) { | ||
return Promise.resolve() | ||
.then(function () { | ||
return _utils.download(_constants.HISTORICAL_URL, { | ||
q: symbol, | ||
startdate: range.from.format('YYYY-MM-DD'), | ||
enddate: range.to.format('YYYY-MM-DD'), | ||
output: 'csv' | ||
}); | ||
}) | ||
.then(_utils.parseCSV) | ||
.then(function (data) { | ||
return _transformHistorical(symbol, data); | ||
}) | ||
.catch(function (err) { | ||
if (options.error) { | ||
throw err; | ||
} else { | ||
return []; | ||
} | ||
}); | ||
}) | ||
.then(_utils.parseCSV) | ||
.then(function (data) { | ||
return _transformHistorical(symbol, data); | ||
}) | ||
.catch(function (err) { | ||
if (options.error) { | ||
throw err; | ||
} else { | ||
return []; | ||
} | ||
}); | ||
.then(_.flatten); | ||
}, {concurrency: os.cpus().length}) | ||
.then(function (result) { | ||
.then(function (results) { | ||
if (options.symbols) { | ||
return _.zipObject(symbols, result); | ||
return _.zipObject(symbols, results); | ||
} else { | ||
return result[0]; | ||
return results[0]; | ||
} | ||
@@ -205,0 +209,0 @@ }) |
@@ -72,2 +72,26 @@ var url = require('url'); | ||
function getDateRanges(from, to) { | ||
var result = []; | ||
var d = from.clone(); | ||
while (true) { | ||
var d2 = d.clone().add(10, 'years').subtract(1, 'days'); | ||
if (d2.isAfter(to)) { | ||
result.push({ | ||
from: d.clone(), | ||
to: to.clone() | ||
}); | ||
break; | ||
} else { | ||
result.push({ | ||
from: d.clone(), | ||
to: d2.clone() | ||
}); | ||
} | ||
d = d2.add(1, 'days'); | ||
} | ||
return result; | ||
} | ||
function parseCSV(text) { | ||
@@ -122,2 +146,3 @@ return S(text).trim().s.split('\n').map(function (line) { | ||
exports.downloadRSS = downloadRSS; | ||
exports.getDateRanges = getDateRanges; | ||
exports.parseCSV = parseCSV; | ||
@@ -124,0 +149,0 @@ exports.toDate = toDate; |
{ | ||
"name": "google-finance", | ||
"description": "Google Finance company news and historical quotes data downloader written in Node.js", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": { |
22309
3.19%331
8.52%