Skip to content

ali-azary/yf_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

yfinance API (FastAPI)

A small FastAPI service that exposes commonly used yfinance endpoints (ticker info, history, bulk downloads, financial statements, holders, options, news) as a JSON API.

Features

  • FastAPI + automatic Swagger docs at /docs
  • CORS enabled (default: *) for easy dashboard/browser use
  • Single-ticker and multi-ticker historical data
  • Fundamentals (financial statements, holders), options chain, news

Requirements

  • Python 3.10+ recommended
  • Dependencies are listed in requirements.txt

Run locally

  1. Install deps:
pip install -r requirements.txt
  1. Start dev server:
uvicorn main:app --reload
  1. Open docs:
  • Swagger UI: http://127.0.0.1:8000/docs
  • Root: http://127.0.0.1:8000/

Deploy (Render)

This repo includes render.yaml. Render will:

  • install: pip install -r requirements.txt
  • start: gunicorn main:app

If you deploy manually, use:

gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

API endpoints

Root

  • GET / → welcome message

Ticker data

  • GET /ticker/{ticker}/info
  • GET /ticker/{ticker}/history?period=1y&interval=1d
  • GET /ticker/{ticker}/actions
  • GET /ticker/{ticker}/calendar

Bulk data

  • GET /download/{tickers}?start=2020-01-01&end=2026-01-01&interval=1d
    • tickers is comma-separated (e.g. AAPL,MSFT,GOOGL)

Fundamentals

  • GET /ticker/{ticker}/financials?statement_type=all&frequency=annual
    • statement_type: income | balance_sheet | cashflow | all
    • frequency: annual | quarterly
  • GET /ticker/{ticker}/holders?holder_type=all
    • holder_type: institutional | mutualfund | major | all

Analyst / options / news

  • GET /ticker/{ticker}/recommendations
  • GET /ticker/{ticker}/options
  • GET /ticker/{ticker}/option_chain?date=YYYY-MM-DD
  • GET /ticker/{ticker}/news

Examples (curl)

Ticker info:

curl "http://127.0.0.1:8000/ticker/AAPL/info"

Historical candles:

curl "http://127.0.0.1:8000/ticker/AAPL/history?period=6mo&interval=1d"

Bulk download:

curl "http://127.0.0.1:8000/download/AAPL,MSFT?start=2023-01-01&end=2024-01-01&interval=1d"

Options chain:

curl "http://127.0.0.1:8000/ticker/AAPL/option_chain?date=2026-03-20"

Notes

  • Data quality/availability depends on Yahoo Finance and yfinance; some tickers may not return all fields.
  • The service returns 404 when data is unavailable and 500 on unexpected errors.
  • CORS is currently wide open (allow_origins=["*"]). Restrict it for production if needed.

License

Add a license file if you intend to publish this publicly.

About

A small FastAPI service that exposes commonly used yfinance endpoints

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages