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
Here is how you can get all the historical price data for a symbol using the yahoo-finance2 package in JavaScript:
const YahooFinance = require('yahoo-finance2').default; const symbol = 'AAPL'; YahooFinance.historical({ symbol, from: '2010-01-01', to: new Date() }).then(data => { // data contains the historical price data const prices = data.map(quote => quote.close); console.log(prices); }).catch(err => { console.log(err); });The key things to note:
- Require the
yahoo-finance2package - Specify the
symbolyou want data for - Set a
fromdate to start from - Set
toto the current date to get all historical data - The promise resolves with an array of quotes, containing the closing price each day
- Require the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.