Skip to content
OptionData
50% Off First Year
Save 50% on your first year after a 14-day free trial. Create an account to begin; an invitation is required to qualify. Contact Sales for the promotion code, then apply it on Billing.

Historical Option Trades API (SQL)

Preparing your API workspace…

API overview and examples
Historical options data API

Historical Options Data API with SQL

Historical options data API over REST with ClickHouse SQL. Query U.S. option trades for backtests and research without bulk file downloads. Paid Pro covers the past 15 days of trades, with a 15-minute delay.

historical options datahistorical options data apioptions data apistock options data apioptions databaseclickhouse options sql
REST endpoint
POST https://www.optiondata.io/api/historical/sql
15 days
paid history window
SQL
query interface
15 min
minimum delay

Ask ChatGPT or Claude Code

Copy this prompt, paste it into ChatGPT, Claude, Claude Code, Cursor, or Codex, then add your question. It tells the model to read our public docs first — no API key needed for that step.

You are helping me use OptionData (https://www.optiondata.io/), an OPRA-licensed U.S. equity options data API.

Before answering, fetch these public files (no login required) and treat them as the source of truth:
- https://www.optiondata.io/llms.txt — short product map (same content as https://www.optiondata.io/llm.txt)
- https://www.optiondata.io/llms-full.txt — full API reference
- https://www.optiondata.io/openapi.json — HTTP OpenAPI

Do not invent endpoints, fields, tables, or limits. Prefer `Authorization: Bearer apikey_…` for HTTP APIs. Realtime uses `wss://ws.optiondata.io` with a `token` query parameter.

Products:
- Realtime trades WebSocket: wss://ws.optiondata.io
- Historical SQL: POST https://www.optiondata.io/api/historical/sql
- Option chain: POST https://www.optiondata.io/api/option-chain
- Market structure: GET https://www.optiondata.io/api/v1/market-structure/{symbol}

I am asking about: Historical Option Trades API (SQL)
- Product / playground page: https://www.optiondata.io/historical_data
- Markdown: https://www.optiondata.io/md/historical-option-trades-api
- HTML docs: https://www.optiondata.io/docs/historical-option-trades-api

My question:

SQL access over HTTPS

Send SELECT queries through a REST endpoint and receive structured JSON for analytics, reporting, and research apps. No bulk CSV dumps to host yourself.

Backtest-ready options history

Run SELECT queries over unmodified RAW trade history (not AGGREGATED). Stored columns and derived-field formulas are in the historical SQL docs.

Guarded query execution

SELECT-only checks, table allowlists, row caps, and ClickHouse limits protect the shared warehouse while you run custom research SQL.

Best for

  • Historical options-flow backtests
  • Signal research and model training
  • Market microstructure analysis
  • Custom analytics dashboards

Common API questions

Historical option trades SQL reference

How far back can paid users query? Does Pro include the full archive?

Paid Pro includes the past 15 days of trades, with a 15-minute delay. Full-archive access is not included. Trial access is unchanged.

Does 15 days mean trading days?

It means 360 elapsed hours from query execution, including weekends and holidays. The oldest timestamp is included; the newest 15 minutes are excluded.

Why does my historical query return no rows?

Check your symbol and date filters. Paid queries exclude trades older than 15 days and newer than 15 minutes. A range crossing the boundary includes only eligible trades, including in aggregates. See the Historical SQL reference for details.

Can I query historical options data with SQL?

Yes. POST guarded ClickHouse SELECT queries to /api/historical/sql with your API key and receive JSON rows. Paid access covers the past 15 days with a 15-minute delay.

Do historical responses include Greeks and implied volatility?

Yes. Stored trade rows include IV and Greeks when available. Some metrics such as premium are derived in SQL — see the historical SQL docs for stored vs derived columns.

Is this a file download API?

No. The historical API is request-based. You query the warehouse directly instead of downloading and maintaining static files.

Is historical data RAW or aggregated?

Historical SQL stores original OPRA-derived trade prints without AGGREGATED consolidation. Build your own GROUP BY aggregations in SQL when you need them.

How historical SQL works

POST a form or JSON body with api_key and a SELECT-only SQL string to https://www.optiondata.io/api/historical/sql. The warehouse is ClickHouse; responses are JSON rows plus meta/statistics when available.

Query RawOptionTrades (and allowed materialized views). Partition on date and filter symbol early. Stored vs derived columns are documented in the historical SQL reference — this page does not restate the schema.

Guardrails enforce SELECT-only, no multi-statements/comments, table allowlists, and row/time caps. Trial accounts receive smaller row caps; paid subscribers can query the past 15 days under the same Pro plan.

Historical option trades SQL reference → · All API docs · openapi.json

Example: top premium AAPL prints in the latest available session
curl -X POST 'https://www.optiondata.io/api/historical/sql' \
  -H 'Content-Type: application/json' \
  -d '{
    "api_key": "YOUR_API_KEY",
    "sql": "SELECT symbol, strike, put_call, size, price, toFloat64(price) * size * 100 AS premium FROM RawOptionTrades WHERE date = (SELECT max(date) FROM RawOptionTrades WHERE symbol = '\''AAPL'\'' AND date >= today() - 7) AND symbol = '\''AAPL'\'' ORDER BY premium DESC LIMIT 25"
  }'

Request and response schema

Field names, types, filters, limits, and error codes live in the public API reference. This product page does not keep a second copy of the schema.

Historical option trades SQL reference → · openapi.json