Created
April 23, 2017 19:10
-
-
Save junajan/d2ba3dc152c5ca7f885dcc38419d262a to your computer and use it in GitHub Desktop.
This file contains 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
==== SCRIPT ==== | |
'use strict'; | |
/** | |
* This will import historical data to Mysql table | |
*/ | |
require('colors'); | |
var async = require("async"); | |
var moment = require("moment"); | |
var config = require("../config"); | |
var yahooFinance = require('yahoo-finance'); | |
var dateFrom = moment('2017-04-01'); | |
var dateTo = moment('2017-04-05'); | |
var tickers = "AAPL,ABBV".split(","); | |
function downloadHistory(ticker, done) { | |
var to = dateTo.format('YYYY-MM-DD') | |
var from = dateFrom.format('YYYY-MM-DD') | |
console.log(("Reading "+ticker+" history data from "+from +" to " + to).yellow); | |
yahooFinance.historical({ | |
symbol: ticker, | |
from: from, | |
to: to | |
}, function(err, res) { | |
if(err) | |
throw err; | |
console.log(res); | |
done(false) | |
}); | |
} | |
async.mapLimit(tickers, 2, downloadHistory, function(err, res) { | |
if(err) | |
console.error('Error:', err); | |
process.exit(0); | |
}); | |
==== OUTPUT ==== | |
node scripts/historyYahoo.js | |
Reading AAPL history data from 2017-04-01 to 2017-04-05 | |
Reading ABBV history data from 2017-04-01 to 2017-04-05 | |
[ { date: Mon Apr 03 2017 00:00:00 GMT+0200 (CEST), | |
open: 65.239998, | |
high: 65.589996, | |
low: 64.879997, | |
close: 65.029999, | |
volume: 5229600, | |
adjClose: 64.389409, | |
symbol: 'ABBV' }, | |
{ date: Tue Apr 04 2017 00:00:00 GMT+0200 (CEST), | |
open: 65.120003, | |
high: 65.300003, | |
low: 64.830002, | |
close: 65.110001, | |
volume: 3457900, | |
adjClose: 64.468623, | |
symbol: 'ABBV' }, | |
{ date: Wed Apr 05 2017 00:00:00 GMT+0200 (CEST), | |
open: 65.230003, | |
high: 65.760002, | |
low: 64.860001, | |
close: 64.959999, | |
volume: 4396300, | |
adjClose: 64.320099, | |
symbol: 'ABBV' } ] | |
[ { date: Mon Apr 03 2017 00:00:00 GMT+0200 (CEST), | |
open: 143.710007, | |
high: 144.119995, | |
low: 143.050003, | |
close: 143.699997, | |
volume: 19985700, | |
adjClose: 143.699997, | |
symbol: 'AAPL' }, | |
{ date: Tue Apr 04 2017 00:00:00 GMT+0200 (CEST), | |
open: 143.25, | |
high: 144.889999, | |
low: 143.169998, | |
close: 144.770004, | |
volume: 19891400, | |
adjClose: 144.770004, | |
symbol: 'AAPL' }, | |
{ date: Wed Apr 05 2017 00:00:00 GMT+0200 (CEST), | |
open: 144.220001, | |
high: 145.460007, | |
low: 143.809998, | |
close: 144.020004, | |
volume: 27717900, | |
adjClose: 144.020004, | |
symbol: 'AAPL' } ] | |
==== DEPENDENCIES ==== | |
yahoo-finance: https://github.com/pilwon/node-yahoo-finance/ | |
- which takes data from these sources: https://github.com/pilwon/node-yahoo-finance/blob/master/lib/constants.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment