Skip to content

Instantly share code, notes, and snippets.

@alexb4a
Created August 25, 2023 19:03
Show Gist options
  • Save alexb4a/e98a71b030ca26d2ae5bdf6654dc1c1e to your computer and use it in GitHub Desktop.
Save alexb4a/e98a71b030ca26d2ae5bdf6654dc1c1e to your computer and use it in GitHub Desktop.
import sp500CompaniesAsJSON from 'sp500-companies-as-json';
import yahooFinance from 'yahoo-finance2';
async function run(){
const companies = await sp500CompaniesAsJSON();
let counter = 0;
for (let i = 0; i < companies.length; i ++){
counter ++;
console.log("Consulting company " + companies[i].ticker + " (" + counter + " of " + companies.length + ")");
const queryOptions = { modules: ['price', 'summaryDetail', 'recommendationTrend'] }; // defaults
const quoteSummary = await yahooFinance.quoteSummary(companies[i].ticker, queryOptions);
if (quoteSummary) {
console.log(JSON.stringify(quoteSummary));
}
}
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment