Yahoo Finance 2 API Client

3.14.0 · active · verified Tue Apr 21

yahoo-finance2 is an actively maintained JavaScript and TypeScript client library for accessing the unofficial Yahoo Finance API. Currently at stable version 3.14.0, it provides programmatic access to various financial data points including historical prices, real-time quotes, company fundamentals, and search capabilities. The project maintains a regular release cadence, with multiple minor and patch updates occurring monthly, ensuring responsiveness to changes in Yahoo Finance's underlying API. Key differentiators include its comprehensive TypeScript support, broad runtime compatibility (Node.js v20+, Bun, Deno, Cloudflare Workers), and a command-line interface for quick data retrieval. As an unofficial API client, it does not come with guarantees from Yahoo Inc., emphasizing its community-driven nature and the importance of using it at one's own risk for financial applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates instantiating the YahooFinance client and using both instance methods (search) and directly imported functions (quote, historical) to fetch financial data.

import YahooFinance, { quote, historical } from 'yahoo-finance2';

async function runFinanceExamples() {
  // Option 1: Using the default class export for a client instance
  const yahooFinance = new YahooFinance();
  console.log('--- Searching for Apple ---');
  const searchResults = await yahooFinance.search('Apple');
  console.log('Top search result:', searchResults.quotes[0]?.symbol, searchResults.quotes[0]?.longname);

  // Option 2: Using named exports directly for individual functions (stateless)
  console.log('\n--- Getting Apple (AAPL) current quote ---');
  const aaplQuote = await quote('AAPL');
  const { regularMarketPrice: price, currency } = aaplQuote;
  console.log(`Apple (AAPL) current price: ${price} ${currency}`);

  console.log('\n--- Getting historical data for Microsoft (MSFT) ---');
  const msftHistorical = await historical('MSFT', {
    period1: '2025-01-01',
    period2: '2025-01-07',
    interval: '1d'
  });
  console.log(`Historical data for MSFT (2025-01-01 to 2025-01-07):`, msftHistorical.map(d => ({ date: d.date.toISOString().split('T')[0], close: d.close })));
}

runFinanceExamples().catch(console.error);

view raw JSON →