Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart method to yahoo-finance #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/chart.js
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exports.historical = require('./historical');
exports.snapshot = require('./snapshot').default;
exports.quote = require('./quote').default;
exports.chart = require('./chart').default;