This project provides a Python client for interacting with the Theta Terminal Local API (v3), offering functionality for fetching option data, underlying OHLC data, and managing real-time data feeds.
The ThetaClient is designed to interact with the Theta Terminal Local API, enabling users to:
- Fetch option expirations and strikes
- Retrieve underlying OHLC data using Greeks (Spot Proxy)
- Download historical option data (OHLC and Greeks)
- Handle real-time data feeds
- Perform data correction and integrity checks
- Asynchronous HTTP client using
httpx - Automatic retry logic with exponential backoff
- Data integrity checks and zero-repair logic
- Real-time data polling for ML models
- Batch processing of historical option data
- Calendar-based holiday and trading day handling
Requires the ThetaTerminalv3.jar service up and running in the port 25503/v3.
To install the required dependencies, run:
pip install httpx pandas numpy tenacity pyarrowfrom client import ThetaClient
client = ThetaClient(base_url="http://127.0.0.1:25503/v3")exps = await client.get_expirations("SPX", "2024-04-15")strikes = await client.get_strikes("SPX", "20240426", "2024-04-15")underlying = await client.fetch_underlying_ohlc("SPX", "2024-04-15")from realtime import RealtimeFeed
feed = RealtimeFeed(["SPX", "VIX"], poll_interval=60)
await feed.run_forever()from bulk import download_historical_options
download_historical_options(
symbols=["SPX", "VIX"],
start_date="2024-01-01",
end_date="2024-03-31",
output_path="./data_options"
)from pipeline import Pipeline
pipeline = Pipeline(client)
await pipeline.run_full_pipeline("2024-04-15", ["SPX"], ["SPX"])/option/list/expirations/option/list/strikes/option/history/greeks/first_order/index/history/ohlc/stock/history/ohlc/calendar/year_holidays
Represents derived underlying data using Greeks (Spot Proxy).
Represents historical option data.
Finds the last valid trading day of the current week.
Returns the Wednesday of the current week.
Finds the next valid VIX expiration starting from the current date.
Selects target expirations (0DTE + Weekly) based on symbol logic.
The client includes automatic retry logic with exponential backoff for transient network issues. Errors are logged and audited using RetryAuditLog and RequestStats.
The Corrector module provides functions for:
- Zero-repair of OHLC data
- Gap-filling for missing values
- Batch processing of existing Parquet files
The RealtimeFeed class provides a daemon that polls real-time data at regular intervals and maintains session data for ML model consumption.
The bulk.py module allows for downloading historical option data in parallel across multiple processes, automatically handling weekends and holidays.
The system uses structured logging with get_logger and maintains statistics in CSV files for monitoring and debugging purposes.
httpxfor asynchronous HTTP requestspandasfor data manipulationnumpyfor numerical operationstenacityfor retry logicpyarrowfor Parquet file handling
This project is licensed under the MIT License.