
Security News
Static vs. Runtime Reachability: Insights from Latio’s On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
yfinance-api-package
Advanced tools
Node.js module for fetching historical stock market data from Yahoo Finance and saving it to CSV files.
YahooFinance API Package is a Node.js module for fetching historical stock market data from Yahoo Finance and saving it to CSV files.
Install the package via npm:
npm install yfinance-api-package
const {YahooFinance} = require('yfinance-api-package');
const yahooFinance = new YahooFinance();
async function fetchDataForDate() {
const symbol = 'AAPL'; // Replace with your desired stock symbol
const date = '2023-12-29'; // Replace with your desired date
try {
const dataForDate = await yahooFinance.downloadDataForDate(symbol, date);
if (dataForDate) {
yahooFinance.saveDataToCSV(dataForDate, `${symbol}_${date}.csv`);
console.log(`Data for ${date} saved to ${symbol}_${date}.csv`);
} else {
console.log(`No data available for ${date}`);
}
} catch (error) {
console.error(`Error fetching data for ${date}: ${error.message}`);
}
}
fetchDataForDate();
async function fetchDataForToday() {
const symbol = 'SBIN.NS'; // Replace with your desired stock symbol
try {
const dataForToday = await yahooFinance.downloadDataForToday(symbol);
if (dataForToday) {
const formattedDate = new Date().toISOString().slice(0, 10);
yahooFinance.saveDataToCSV(dataForToday, `${symbol}_today_${formattedDate}.csv`);
console.log(`Today's data (${formattedDate}) saved to ${symbol}_today_${formattedDate}.csv`);
} else {
console.log(`No data available for today`);
}
} catch (error) {
console.error(`Error fetching today's data: ${error.message}`);
}
}
fetchDataForToday();
async function fetchDataForDatesBetween() {
const symbol = 'AAPL'; // Replace with your desired stock symbol
const startDate = '2023-01-01'; // Replace with your desired date
const endDate = '2023-12-29'; // Replace with your desired date
//interval is optional,by default its daily timeframe, you can add if needed.
try {
const dataBetweenDate = await yahooFinance.fetchStockData(symbol, startDate, endDate);
if (dataBetweenDate) {
yahooFinance.saveDataToCSV(dataBetweenDate, `${symbol}_${startDate}_to_${endDate}.csv`);
console.log(`Data from ${startDate} to ${endDate} saved to ${symbol}_${startDate}_to_${endDate}.csv`);
} else {
console.log(`No data available for the period from ${startDate} to ${endDate}`);
}
} catch (error) {
console.error(`Error fetching data for ${date}: ${error.message}`);
}
}
fetchDataForDatesBetween();
If you have fetched data and want to save it to CSV:
const data = 'Date,Open,High,Low,Close,Adj Close,Volume\n2023-12-29,194.14,194.66,193.17,193.58,193.33,34049900\n...';
const filePath = 'AAPL_custom_data.csv'; // Replace with desired file path
yahooFinance.saveDataToCSV(data, filePath);
console.log(`Data saved to ${filePath}`);
fetchStockData(symbol, startDate, endDate, interval = '1d'):
Fetches historical stock data for the specified symbol and date range.
downloadDataForDate(symbol, date):
Fetches historical stock data for a specific date.
downloadDataForToday(symbol):
Fetches today's stock data.
saveDataToCSV(data, filePath):
Saves provided data to a CSV file.
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
This package is created only for study purpose
FAQs
Node.js module for fetching historical stock market data from Yahoo Finance and saving it to CSV files.
The npm package yfinance-api-package receives a total of 55 weekly downloads. As such, yfinance-api-package popularity was classified as not popular.
We found that yfinance-api-package demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.