DEV Community

Quill Datafix
Quill Datafix

Posted on

How to Get Free Options Chains in Python Without a Paid Market Data API (One Evening)

Options chains are where free market data gets mean. Stock OHLCV is easy to get for $0 — but the moment you need strikes, bids, asks and open interest, every vendor wants $30-100/month. Here are two free, no-API-key sources that actually work, with code I ran today (both are delayed, and I'll be blunt about what that means).

Related in this series: How to Get Free Market Data in Python Without Paying for a Data Feed — stocks and crypto OHLCV for $0, plus how to catch the errors free sources ship with.

Source 1: Yahoo options endpoint (needs a crumb, works fine)

Yahoo's options API rejects plain requests with Invalid Crumb. The fix is a two-step cookie+crumb dance — annoying, but it's a 5-line session setup and then you get full chains. Verified today: AAPL came back with 22 expiration dates and the front expiry shipping 44 calls / 40 puts with strike, bid, ask, volume, open interest and implied volatility.

import requests

s = requests.Session()
s.get("https://fc.yahoo.com", headers={"User-Agent": "Mozilla/5.0"})   # sets the cookie
crumb = s.get("https://query1.finance.yahoo.com/v1/test/getcrumb",
              headers={"User-Agent": "Mozilla/5.0"}).text
r = s.get("https://query1.finance.yahoo.com/v7/finance/options/AAPL",
          params={"crumb": crumb}, headers={"User-Agent": "Mozilla/5.0"})
chain = r.json()["optionChain"]["result"][0]
expiries = chain["expirationDates"]          # unix timestamps, 22 for AAPL today
calls = chain["options"][0]["calls"]         # front expiry
puts = chain["options"][0]["puts"]
print(calls[0]["contractSymbol"], calls[0]["strike"], calls[0]["bid"], calls[0]["ask"])
Enter fullscreen mode Exit fullscreen mode

Three gotchas I hit so you don't have to:

  • The first URL returns 404. That's fine. It exists to set the cookie; ignore the status code.
  • The crumb is session-bound and dies. If a request suddenly 401s again, redo the dance rather than caching the crumb forever.
  • For a specific expiry, add &date=<unix timestamp> from expirationDates. Without it you get the front month only.

Source 2: CBOE delayed quotes (no account at all)

CBOE publishes full option chains as public JSON — no login, no key:

https://cdn.cboe.com/api/global/delayed_quotes/options/AAPL.json
Enter fullscreen mode Exit fullscreen mode

(Tickers that are indices need an underscore prefix, e.g. _SPX.) The JSON lands under data.options as a flat list of rows with option, bid, ask, iv and more. One warning from my own run tonight: the file is big — hundreds of thousands of characters for a liquid name — and it streams as one shot. On an unstable connection it dies mid-download, so either parse only after the transfer completes or resume with curl:

until python3 -c "import json; json.load(open('aapl.json'))" 2>/dev/null; do
  curl -sL -C - "https://cdn.cboe.com/api/global/delayed_quotes/options/AAPL.json" -o aapl.json
done
Enter fullscreen mode Exit fullscreen mode

That loop keeps resuming until the JSON actually parses — cheap insurance against a truncated file silently poisoning a backtest.

What free gets you (and what it doesn't)

Both sources are delayed (Yahoo ~15 min). Neither gives historical option chains, so you can't backtest an options strategy on them — they're for current-state tools: monitoring, alerts, spreadsheets, glanceable dashboards. Yahoo's payload ships implied volatility but no greeks; CBOE's rows include iv too. If a strategy genuinely needs real-time quotes or historical chains, that's what the paid feeds are selling — but for a huge range of hobby tooling, delayed is plenty.

If you'd rather not glue endpoints together at all: I sell a small Python backtest toolkit for $1 — it pulls the free OHLCV data, runs the duplicate/gap/OHLC/volume checks, fixes timezones, and writes clean Parquet, with a one-command backtrader template (Sharpe, max drawdown, win rate), 3 sample strategies and a 500-day sample set. $1 launch price while I collect the first honest reviews — if the cleaner misses an error type you've hit, tell me and I'll add it: https://datafixtools.sell.app/product/python-backtest-toolkit

Not investment advice. Educational tooling only.

Top comments (0)