2026 年 Python 開發者最佳股市 API
Best Stock Market APIs for Python Developers in 2026
這份面向 Python 開發者的 2026 年股市 API 指南,將 ROIC.ai 列為基本面資料、財務比率及業績電話會議逐字稿的首選。ROIC.ai 提供超過 90 項預先計算的比率,涵蓋約 68,000 隻股票,並以一致的 JSON 格式提供資料;免費方案每分鐘可發出 5 次請求,付費方案每月 29 USD 起。
If your Python project is built on company numbers rather than ticking prices, start with ROIC.ai. That is my short answer, and the rest of this guide explains why, where it falls short, and which other stock market APIs make more sense when your project looks different.
Almost everyone starts the same way, by the way. Three lines with a popular library, a neat table in the terminal, one proud afternoon. Then the script runs on a schedule, an unofficial endpoint changes, and the dashboard is dead on a Monday morning. This guide is for the day after that.
Quick picks 🏆
Fundamentals, ratios, transcripts: ROIC.ai (top pick)
Live US data and options: Massive
Trading bots: Alpaca
Global history: EODHD
Learning on a free key: Alpha Vantage or Twelve Data
Free live US quotes: Finnhub
Personal notebooks only: yfinance
💡 Tip: Pricing in this market moves without warning. Everything here was checked against public pages and recent developer write ups in October 2026. Confirm on the provider's own page before you add a card.
Contents
- ROIC.ai, the top pick
- Scorecard at a glance
- The other APIs
- How to choose
- Mistakes that cost time
- FAQ
ROIC.ai, the top pick for fundamentals driven projects
Website: roic.ai and its API docs
Most stock APIs are really price APIs with fundamentals bolted on later. ROIC.ai is built the other way round. The core product is standardized company data: income statements, balance sheets, cash flow, more than 90 pre calculated ratios, valuation multiples and earnings call transcripts, all behind one consistent JSON format.
The published scale is roughly 68,000 tickers across more than 70 exchanges, up to 40 years of statements depending on the plan, 120 plus quarters per company, over 17 years of call transcripts, and daily forex rates for more than 4,000 currency pairs. It also has company profiles, logos, sector and industry reference data, stock splits and an earnings calendar with estimates and surprises.
Why Python developers tend to like it:
- Ratios arrive pre computed. You do not have to rebuild return on invested capital from raw statements. The idea behind the name is simple.
ROIC=NOPATInvested Capital
- One format everywhere. Resources, lists and errors share the same JSON shapes, so once you integrate statements, the same habits work for prices and transcripts.
- An official Python SDK, with Node and Go versions too. The package works with pandas and polars.
- Transcripts in the same API. Prepared remarks and Q and A organized by fiscal quarter, which is rare at this price.
- A hosted MCP server, so assistants like Claude or Cursor can query the same data in plain language. That matters if you build AI research tools.
- Easy to try. The free plan needs no credit card.
A first call takes a minute:
# pip install roicai
from roicai import Roicai
client = Roicai(api_key="YOUR_API_KEY") # or set ROICAI_API_KEY
statements = client.fundamentals.income_statements.list(
"NASDAQ:AAPL",
period_type="annual",
limit=5,
)
for year in statements.items:
print(year.fiscal_year, year.is_sales_revenue_turnover, year.is_net_income)
Prefer plain REST? The identifier is just exchange, colon, ticker:
curl "https://api.roic.ai/v3.0.0/stock-prices/latest/NASDAQ:AAPL?apikey=YOUR_API_KEY"
and the response is clean, predictable JSON:
{
"data": [
{
"date": "2026-07-17",
"open": 210.61,
"high": 213.34,
"low": 209.85,
"close": 212.41,
"volume": 48923700
}
],
"symbol": "NASDAQ:AAPL",
"currency": "USD"
}
Plans and limits in short
The free plan allows 5 requests per minute with about two years of annual fundamentals and daily prices, and no card. Paid plans start at 29 USD per month with higher limits, and the vendor lists 300 requests per minute at that level. Bulk downloads and some endpoints need a paid plan, and commercial redistribution is handled through an Enterprise plan. Check the pricing page for current tiers.
⚠️ The honest part: ROIC.ai serves daily price data, not streaming quotes1. If you need a live ticker or tick data, pair it with a real time provider from the list below. For screeners, valuation models, research dashboards and anything that asks how a business is really doing, it is the one I would start with.
roicai
/
roicai-python
Official Python SDK for the ROIC.ai financial data and stock API: fundamentals, earnings call transcripts, stock prices, pandas and polars
ROIC.AI Python Library
The ROIC.AI Python library is the official Python client for the ROIC.AI financial data API and stock API. Use it to get fundamentals for public companies, such as income statements, balance sheets, cash flow statements, financial ratios and valuation multiples, and earnings call transcripts. It also covers historical and latest stock prices, SEC filings and other company documents, the earnings calendar, company profiles and forex rates.
Responses are typed Pydantic models, list methods fetch the next pages for you, and any response converts to a pandas or polars DataFrame.
Documentation
See the ROIC.AI API reference for every endpoint, parameter and field, and the API guides for authentication, plans and response formats. reference.md lists every method of this library with its parameters.
Requirements
Python 3.10 or later.
Installation
Install the package with:
pip install --upgrade roicai
To convert responses to DataFrames, install pandas or polars with it:
pip
…
Scorecard at a glance
| API | Best at | Free tier | First paid plan | Python route |
|---|---|---|---|---|
| ROIC.ai | Fundamentals, transcripts | 5 requests per minute | 29 USD per month | Official SDK |
| Alpha Vantage | Learning, indicators | 25 requests per day | 49.99 USD per month | requests |
| Massive (ex Polygon.io) | Live US, options | 5 calls per minute | about 29 USD per month | Official client |
| EODHD | Global history | about 20 calls per day | about 19.99 per month | Official library |
| Financial Modeling Prep | US fundamentals | about 250 calls per day | about 22 USD per month | requests |
| Twelve Data | Many asset types | about 800 requests per day | see pricing page | Official client |
| Finnhub | Free live US quotes | about 60 calls per minute | about 49.99 USD per month | Official client |
| Alpaca | Trading bots | Free, IEX feed | about 99 USD per month | alpaca py |
| Tiingo | Clean price history | about 1,000 requests per day | about 30 USD per month | Official client |
| yfinance | Personal scripts | Free, unofficial | None | pip install yfinance |
The other APIs, and when they win
Before comparing, decide what data you really need. Stock data is four needs under one name: end of day prices, real time streams, fundamentals, and the extras around them such as transcripts and filings. Most bad choices come from skipping this step.
Alpha Vantage, the easy first stop
Website: alphavantage.co
A huge number of tutorials begin here. A free key arrives in a minute, and one API covers stocks, forex, crypto, fundamentals and many technical indicators. The catch is the free limit of 25 requests per day and 5 per minute. Premium plans are priced by requests per minute, from 49.99 USD for 75 per minute up to 249.99 USD for 1,200, with no daily cap.
import os
import requests
params = {
"function": "TIME_SERIES_DAILY",
"symbol": "IBM",
"apikey": os.environ["ALPHAVANTAGE_API_KEY"],
}
data = requests.get("https://www.alphavantage.co/query", params=params, timeout=30).json()
latest_day = max(data["Time Series (Daily)"])
print(latest_day, data["Time Series (Daily)"][latest_day]["4. close"])
Best for: learning and prototypes. Watch out for: the jump from free to 49.99 USD.
Massive, formerly Polygon.io
Website: massive.com
Same company, rebranded on October 30, 2025, with existing keys still working. Built around US market infrastructure with REST and WebSocket access, trades, quotes, aggregates and deep options coverage. The free plan gives 5 calls per minute of end of day data. Individual stock plans sit around 29, 79 and 199 USD per month, with options, forex and crypto priced separately.
from massive import RESTClient
client = RESTClient(api_key="YOUR_KEY")
for bar in client.list_aggs("AAPL", 1, "day", "2026-09-01", "2026-09-30"):
print(bar)
Best for: live and intraday US data. Watch out for: paying per asset class.
EODHD, for global historical data
Website: eodhd.com
Advertises more than 30 years of history, 60 plus exchanges and over 150,000 tickers, with fundamentals and some real time data under one key. The free plan is closer to a trial at about 20 calls per day. Paid plans start near 19.99 per month, among the cheapest for worldwide coverage. Not built for fast intraday systems.
Financial Modeling Prep, for US fundamentals
Website: financialmodelingprep.com
Popular for statements and screening, with about 250 free calls per day of end of day data. The Starter plan is listed near 22 USD per month billed annually, but it is US focused and global data sits in higher tiers.
Twelve Data, many asset types in one place
Website: twelvedata.com
Stocks, ETFs, forex, crypto and indices with a clean shared schema. Free gives about 800 requests per day, delayed data, and generally non commercial use, so read the licence.
Finnhub, generous free live US quotes
Website: finnhub.io
Around 60 free calls per minute, real time US quotes with limits, news, WebSockets and extras like social sentiment. Paid plans start near 49.99 USD per month. Caps vary by endpoint, so read the docs.
import finnhub
client = finnhub.Client(api_key="YOUR_KEY")
print(client.quote("AAPL"))
Alpaca, when your code also trades
Website: alpaca.markets
A broker first, with market data and an order API on one account plus a paper trading sandbox. The free feed is IEX only, so prices can differ from the full tape, and the full feed is listed near 99 USD per month. The Python library is alpaca py.
Tiingo, clean historical prices
Website: tiingo.com
Tidy, error checked end of day data with decades of history. Free allows about a thousand requests per day, and paid plans start near 30 USD per month. Quietly good for backtests.
yfinance, free with an asterisk
Website: github.com/ranaroussi/yfinance
An open source library that reads the same unofficial endpoints Yahoo uses for its own site. Free, no key, a few lines of code:
import yfinance as yf
hist = yf.Ticker("AAPL").history(period="1mo")
print(hist.tail())
The catch is the one we opened with: endpoints change without notice, heavy use triggers rate limits, there is no service agreement, and the project points to Yahoo's terms and describes the data as for personal, research and educational use. Fine for your notebook, a poor base for a product.
Download market data from Yahoo! Finance's API
yfinance offers a Pythonic way to fetch financial & market data from Yahoo!Ⓡ finance.
Important
Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of Yahoo, Inc.
yfinance is not affiliated, endorsed, or vetted by Yahoo, Inc. It's an open-source tool that uses Yahoo's publicly available APIs, and is intended for research and educational purposes.
You should refer to Yahoo!'s terms of use (here, here, and here) **for details on your rights to use the actual data downloaded.
Remember - the Yahoo! finance API is intended for personal use only.**
Main components
-
Ticker: single ticker data -
Tickers: multiple tickers' data -
download: download market data for multiple tickers -
Market: get information about a market -
WebSocketandAsyncWebSocket: live streaming data -
Search: quotes and…
Also worth knowing: Nasdaq Data Link for research datasets, Intrinio for standardized US fundamentals, Marketstack for cheap end of day data, and Bloomberg or QuoteMedia for teams that need licensed redistribution.
How to choose
| Your project | Start with |
|---|---|
| Screener, valuation tool, research dashboard | ROIC.ai |
| AI agent that reads financials and transcripts | ROIC.ai with its MCP server |
| Live US dashboard or options | Massive |
| Trading bot | Alpaca |
| Global backtests | EODHD |
| Learning project | Alpha Vantage or Twelve Data |
| Private notebook | yfinance |
Two providers is normal. A common and sensible pair is ROIC.ai for the fundamentals and a real time source for the prices, which usually costs less than one vendor trying to do everything.
Mistakes that cost developers time
Calling the API on every page load. Fetch once, store, refresh on a schedule. A tiny cache fixes most rate limit pain:
import json
import time
from pathlib import Path
def cached(key, fetch, ttl=3600):
path = Path(f".cache/{key}.json")
if path.exists() and time.time() - path.stat().st_mtime < ttl:
return json.loads(path.read_text())
data = fetch()
path.parent.mkdir(exist_ok=True)
path.write_text(json.dumps(data))
return data
Hard coding one provider everywhere. Keep data calls in one module so a provider swap is a one line change:
- from providers.alphavantage import get_daily
+ from providers.roicai import get_daily
Ignoring adjusted prices. Splits and dividends change history, and an unadjusted backtest quietly produces nonsense.
Forgetting the licence. Free plans are often personal or non commercial only.
Trusting one source. Spot check a few values against a second source after any plan change or rebrand.
FAQ
Is there a completely free stock market API for Python?
Several have usable free tiers, including ROIC.ai, Alpha Vantage, Twelve Data, Finnhub, Financial Modeling Prep and Alpaca. All limit requests, history or freshness, so free works best for learning and small tools.
Which API is best for company fundamentals?
ROIC.ai, Financial Modeling Prep and Intrinio are the usual picks. ROIC.ai stands out when you want global coverage, pre calculated ratios and earnings call transcripts in one consistent format.
What is the best stock API for real time data?
For US stocks, Massive and Finnhub are the usual names, and Alpaca suits you if you also want to trade. Free real time is limited, so check delays and coverage.
Is yfinance safe for production?
No. It relies on unofficial endpoints with no guarantees, and Yahoo's terms point to personal use. Keep it for your own notebooks.
Can I use these APIs in a commercial product?
Sometimes, but rarely on a free plan. Check each licence, because redistribution rights usually sit in paid or enterprise tiers.
Final thoughts
There is no perfect stock API, only the one that fits what you are building this month. If the question your project asks is how good a company is, start with ROIC.ai. If it asks what the price is right now, start with a real time provider. Cache your data, keep the provider behind a small wrapper, and you can change your mind without a rewrite.
Which API are you using right now, and why did you pick it? Tell me in the comments.
1 Based on the vendor's published documentation, which lists daily open, high, low, close and volume data. Pricing and limits throughout were checked in October 2026 and may have changed.
來源:DEV Community · dev.to

