Python wrapper and DuckDB cache for ThetaData option and streaming endpoints.
Project description
ThetaDataRS
ThetaDataRS is a Python wrapper around the thetadata package. It adds a small convenience facade and local DuckDB caching for option list, history, and snapshot endpoints.
Installation
This project uses Python 3.12 and uv.
uv sync
Create a local .env file with your ThetaData credentials:
EMAIL=you@example.com
PASSWD=your-password
Credentials are loaded by thetadatars.client.create_client() through python-dotenv.
Quick Start
Use ThetaDataRS when you want one object that wraps the existing endpoint functions and automatically supplies the ThetaData client.
from thetadatars.thetadata import ThetaDataRS
theta = ThetaDataRS()
contracts = theta.get_options_contract_list(
"AAPL",
"2026-04-24",
)
print(contracts)
The first call fetches from ThetaData when local data is missing or stale, writes the result to DuckDB, and returns a Polars DataFrame. Later calls read from the local cache until the endpoint's stale_threshold is exceeded.
Option List Examples
from thetadatars.thetadata import ThetaDataRS
theta = ThetaDataRS()
symbols = theta.get_options_symbols_list()
expirations = theta.get_options_expiration_list("AAPL")
strikes = theta.get_options_strike_list("AAPL", "2026-04-24")
contracts = theta.get_options_contract_list("AAPL", "2026-04-24")
Snapshot Example
from thetadatars.thetadata import ThetaDataRS
theta = ThetaDataRS()
quotes = theta.get_snapshot_quote(
ticker="AAPL",
expiration="2026-04-24",
strike="*",
right="both",
)
print(quotes.head())
Snapshot endpoints default to a shorter cache window than historical endpoints because the data changes during the trading day.
Historical Option Example
from thetadatars.thetadata import ThetaDataRS
theta = ThetaDataRS()
eod = theta.get_option_history_eod(
ticker="AAPL",
start_date="2026-04-01",
end_date="2026-04-24",
expiration="2026-04-24",
strike="*",
right="both",
)
print(eod)
Streaming Example
Streaming helpers return async iterators. ThetaDataRS automatically applies its stream_url, which defaults to ws://127.0.0.1:25520/v1/events.
import asyncio
from thetadatars.thetadata import ThetaDataRS
async def main():
theta = ThetaDataRS()
async for message in theta.stream_option_trades(
"AAPL",
"2026-04-24",
200,
"C",
max_messages=5,
timeout=10,
):
print(message)
asyncio.run(main())
Direct Function Usage
You can also import endpoint functions directly if you want explicit control over the client.
from thetadatars.client import create_client
from thetadatars.options.list.contracts import get_options_contract_list
client = create_client()
contracts = get_options_contract_list(
"AAPL",
"2026-04-24",
client=client,
)
Local Data
Cached endpoint data is stored in DuckDB through thetadatars.data.db. Do not commit local database files, .env files, credentials, or generated market data.
Development
uv sync
uv run python test.py
uv run python -m py_compile thetadatars/thetadata.py
uv build
uv syncinstalls dependencies.uv run python test.pyruns the current smoke-test script.uv run python -m py_compile ...checks syntax for a module.uv buildcreates package distributions indist/.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thetadatars-0.1.0.tar.gz.
File metadata
- Download URL: thetadatars-0.1.0.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84c97bbcd7bbae844f925c903a8288bfe319d204e2bc7282c70c8e2a5dc202fa
|
|
| MD5 |
2f41ddeaf2c8a81c14b1ac9539481871
|
|
| BLAKE2b-256 |
ea95f5ab355c0a14cd7a304d2576721345ba70dcf535e065125e11080300b214
|
File details
Details for the file thetadatars-0.1.0-py3-none-any.whl.
File metadata
- Download URL: thetadatars-0.1.0-py3-none-any.whl
- Upload date:
- Size: 55.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5203a871db2af31aa0eb9d793a4e2966ee3efbf319f93f4e51ed55d3a2d802c5
|
|
| MD5 |
8664802c5fd147be7724ea06c5f0b868
|
|
| BLAKE2b-256 |
e24eb68b2fb769aea9b68bf733cc42aaf0c18ff2aa02cf372578fbf0aa34d0f8
|