From @openapiv3.yaml to a working options pull.
Gemini can read our OpenAPI spec directly and connect to the same MCP server Claude uses. Ground it once, then ask for stocks, options, and index data in plain English.
$ gemini
> @openapiv3.yaml Using this spec and the Theta Data Python library, write code for SPX 0DTE call greeks at 3:45pm ET
reading openapiv3.yaml · 1 file …
✓ wrote spx_0dte_greeks.py — checked against option/history/greeks/eod
Two ways to ground it
Give Gemini the real spec, or connect it live.
Both cut hallucinated methods to nearly zero — use whichever fits the moment.
Reference the spec directly
In the Gemini CLI, pull the whole schema into context with @openapiv3.yaml, then ask your question. Gemini checks endpoints and parameters against the real file instead of guessing.
Connect the MCP server
For a quick number instead of a script — "AAPL 0DTE call Greeks at 3:45pm ET" — connect once and ask in plain English. Setup below.
Copy, paste, run
Everything you need, in the format you'll actually use.
Prompts to paste into Gemini, plus the Python, SDK, notebook, and REST snippets it should produce — pre-verified against the current library.
Using the current Theta Data Python library from PyPI, write complete, executable Python code to [describe the task]. Use [symbol(s)], [date/time range], [interval], and [required fields]. Return the result as a pandas DataFrame and [save / plot / transform it]. Use only officially supported methods, state your authentication assumptions, handle AuthenticationError and NoDataFoundError, validate the returned schema, avoid pseudo-code, and explain each section.
Here is a known-good request using the Theta Data Python library: client.stock_history_eod(symbol="AAPL", start_date=date(2024,1,2), end_date=date(2024,1,5)) It returns a DataFrame with columns created, last_trade, open, high, low, close, volume (plus bid/ask fields). Using this exact pattern, write a call that pulls 5-minute OHLC bars for TSLA over the same date range.
Add explicit handling for AuthenticationError and NoDataFoundError (both from thetadata.errors) to the function below, without changing its return type or output columns: [paste your function]
Explain what each section of this script does line by line, then rewrite it in the simplest possible form while keeping the same behavior and output columns: [paste your script]
# Written with Gemini, run locally after a quick read-through from datetime import date from thetadata import ThetaClient from thetadata.errors import AuthenticationError, NoDataFoundError client = ThetaClient(dataframe_type="pandas") try: eod = client.stock_history_eod( symbol="AAPL", start_date=date(2024, 1, 2), end_date=date(2024, 1, 31), ) except AuthenticationError: raise SystemExit("Check THETADATA_API_KEY and try again.") except NoDataFoundError: raise SystemExit("No data returned for this symbol/date range.") print(eod.head()) eod.plot(x="last_trade", y="close", title="AAPL — January 2024")
from thetadata import ThetaClient # Option 1 — environment variable (recommended) # export THETADATA_API_KEY="your_api_key_here" client = ThetaClient(dataframe_type="pandas") # Option 2 — pass the key directly client = ThetaClient(api_key="your_api_key_here", dataframe_type="pandas") # Option 3 — email + password via ./creds.txt # line 1: email, line 2: password client = ThetaClient(email="you@yourfirm.com", password="your-password") # dataframe_type defaults to "polars" — pass "pandas" if that's your stack. # Get your key at thetadata.net/portal/api_key
| timestamp | delta | gamma | theta | vega | implied_vol |
|---|---|---|---|---|---|
| 2025-07-28 | 0.482 | 0.031 | -0.184 | 0.612 | 0.214 |
| 2025-07-29 | 0.501 | 0.033 | -0.176 | 0.598 | 0.209 |
| 2025-07-30 | 0.519 | 0.034 | -0.169 | 0.583 | 0.205 |
| 2025-07-31 | 0.536 | 0.035 | -0.161 | 0.567 | 0.201 |
| 2025-08-01 | 0.553 | 0.036 | -0.153 | 0.549 | 0.198 |
curl "http://localhost:25503/v3/stock/history/ohlc\ ?symbol=AAPL&start_date=2024-01-02&end_date=2024-01-05&interval=1m"
import httpx, csv BASE_URL = "http://localhost:25503/v3" params = {"symbol": "MSFT", "expiration": "*"} response = httpx.get(f"{BASE_URL}/option/snapshot/ohlc", params=params, timeout=60) response.raise_for_status() for row in csv.reader(response.text.split("\n")): print(row)
!pip install thetadata, paste your key, go.Native integration
Connect the MCP server
Five minutes, once, and every future question skips the boilerplate.
Install Gemini CLI
The CLI that can read local files and connect to MCP servers.
npm install -g @google/gemini-cli
Launch Theta Terminal v3
Needs an active Theta Data subscription and Java 21+. Starting it also starts the MCP server, listening on
127.0.0.1:25503.Edit your Gemini CLI settings
Add ThetaData to
~/.gemini/settings.json:{ "mcpServers": { "Theta Data": { "url": "http://127.0.0.1:25503/mcp/sse", "timeout": 30000 } } }Verify the connection
Inside the Gemini CLI, run
/mcpand confirm Theta Data shows as connected.Ask naturally
Be explicit: real ticker symbols, ISO dates (
YYYY-MM-DD), call/put spelled out rather thanC/P, and strikes as decimals.
Every strategy is only as good as its data.
Free tier available — no credit card to start pulling data.