Skip to main content

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 sync installs dependencies.
  • uv run python test.py runs the current smoke-test script.
  • uv run python -m py_compile ... checks syntax for a module.
  • uv build creates package distributions in dist/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thetadatars-0.2.0.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thetadatars-0.2.0-py3-none-any.whl (89.9 kB view details)

Uploaded Python 3

File details

Details for the file thetadatars-0.2.0.tar.gz.

File metadata

  • Download URL: thetadatars-0.2.0.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for thetadatars-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7ad08b526045d7252810510cd9864d01f7ce948591587d7804657f3da0985046
MD5 b274ecf669b4315c3325240775634b67
BLAKE2b-256 b44f36fe81eaf966f573b2be28d8cd5778950fcda5c5b2002ef357ed08b4ad1e

See more details on using hashes here.

File details

Details for the file thetadatars-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: thetadatars-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 89.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for thetadatars-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44f277532fd1e10cf0de1c552bbac9c4f0ee22159f9190ee4559f5249a997cd0
MD5 d23b4b3df6c9c0fd4c5bd1b1a1c2a89c
BLAKE2b-256 5945a80b810b856847b0145de1fa203158d6abda46f72ad3e9e4e4d9c58ced4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page