diff --git a/lib/chart.js b/lib/chart.js new file mode 100644 index 0000000..9497c49 --- /dev/null +++ b/lib/chart.js @@ -0,0 +1,28 @@ +var request = require('request'); + +/** + * Method for getting chart data via yahoo API + * @param {string} symbol + */ +function chart(symbol) { + return new Promise((resolve, reject) => { + if (!symbol) { + return reject('Symbol must not be falsey value'); + } + + var url = `https://query1.finance.yahoo.com/v8/finance/chart/${symbol}?region=US&lang=en-US&includePrePost=false&interval=2m&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance`; + + request.get(url, function (err, res, body) { + if (err) { + return reject(err); + } else if (body) { + return resolve(body); + } else { + return reject('Yahoo finance response not as expected'); + } + }); + }); +} + +exports.__esModule = true; +exports.default = chart; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index a10e438..63f5cd5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,4 @@ exports.historical = require('./historical'); exports.snapshot = require('./snapshot').default; exports.quote = require('./quote').default; +exports.chart = require('./chart').default;