How to get all historical price data of a symbol with yahoo-finance2 in JavaScript?
- User
How to get all historical price data of a symbol with yahoo-finance2 in JavaScript?
Assistant
You can use the yahoo-finance2 library in JavaScript to get historical price data for a stock symbol like this:
const YahooFinance = require('yahoo-finance2'); const symbol = 'AAPL'; YahooFinance.historical({ symbol, from: '2000-01-01', to: '2020-12-31', period: 'd' }, (err, quotes) => { if (err) throw err; quotes.forEach(quote => { console.log(quote.date, quote.open, quote.high, quote.low, quote.close, quote.volume); }); });This will:
- Use the yahoo-finance2 library
- Get historical data for the AAPL stock symbol
- Request daily data from January 1, 2000 to December 31, 2020
- The callback will receive an array of quote objects, one for each day
- We log the date, open, high, low, close, and volume for each day
So this gives you the full historical daily price data for the given stock symbol from Yahoo Finance. Let me know if you have any other questions!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.