Building Real-Time Financial Dashboards

Lesson 0 of 2

Getting Real-Time Stock Data with Yahoo Finance

Estimated time: 10 minutes

Getting Real-Time Stock Data with Yahoo Finance

Why Yahoo Finance?

Yahoo Finance provides free, high-quality financial data:

  • Stock prices (real-time + historical)
  • Options data
  • Dividends and splits
  • No authentication required for basic queries
  • High rate limits (1000+ requests/minute for most users)

Setup

Install the yfinance Python library or use the unofficial REST API.

Option 1: Python (Recommended)

npm install yfinance  # Node wrapper
const yfinance = require('yfinance');

const data = await yfinance.quote({
  symbols: ['AAPL', 'GOOGL', 'MSFT'],
  modules: ['price', 'summaryDetail']
});

console.log(data);

Option 2: Direct HTTP

Yahoo Finance has an unofficial REST API:

curl 'https://query1.finance.yahoo.com/v8/finance/chart/AAPL?interval=1d'

Response includes: open, close, high, low, volume, adjusted close.

Handling Rate Limits

Yahoo Finance can temporarily block requests if you make >2000 requests/minute from one IP or have a User-Agent that looks like a bot.

Example: Dashboard Data Pipeline

const fetch = require('node-fetch');

async function getStockPrices(symbols) {
  const results = {};
  
  for (const symbol of symbols) {
    const url = `https://query1.finance.yahoo.com/v8/finance/chart/${symbol}?interval=1d&range=1y`;
    
    try {
      const res = await fetch(url, {
        headers: { 'User-Agent': 'Mozilla/5.0...' }
      });
      const data = await res.json();
      
      const prices = data.chart.result[0].indicators.quote[0];
      results[symbol] = {
        current: prices.close[prices.close.length - 1],
        high: Math.max(...prices.high),
        low: Math.min(...prices.low)
      };
    } catch (e) {
      console.error(`Failed to fetch ${symbol}:`, e);
    }
  }
  
  return results;
}

const prices = await getStockPrices(['CRM', 'SNOW', 'DDOG']);

Caching Strategy

Store data locally to avoid redundant API calls. Keep cache TTL at 1 hour minimum to respect rate limits.

Next Steps

Once you have stock data, combine it with prediction market odds (Polymarket, Kalshi) to build a comparative analysis dashboard.