Skip to content

Get's option chain data from Tasty Trade and stores it in a database for further analysis

License

Notifications You must be signed in to change notification settings

Quenos/option_chain_fetcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SPX Option Chain Fetcher

A powerful tool to fetch SPX option chain data including Greeks (delta, gamma, theta, vega, rho), bid/ask quotes, and underlying prices. Data is stored in SQLite and can be exported to JSON for analysis.

πŸ“‹ Table of Contents


✨ Features

  • Comprehensive Data Collection: Fetches options data for SPX (monthly/quarterly) and SPXW (weekly) automatically
  • Full Greeks: Delta, gamma, theta, vega, and rho for all options
  • Market Quotes: Real-time bid/ask prices and calculated mid prices
  • Underlying Price Tracking: Records SPX price at the time of each data fetch
  • SQLite Database: Organized storage with indexing for fast queries
  • JSON Export: Export data to well-structured JSON files for analysis
  • Flexible Filtering: Filter by expiration date, strike range, and delta range
  • Command-Line Interface: Easy to use and automate

πŸ“¦ Prerequisites

  • A Tastytrade account (with API access enabled)
  • Internet connection
  • Computer running macOS or Windows

πŸš€ Installation

Step 1: Install Python

Python is the programming language this tool is written in. You need to install it first.

For macOS Users:

  1. Open Terminal

    • Press Command (⌘) + Space to open Spotlight
    • Type Terminal and press Enter
  2. Check if Python is already installed

    python3 --version
    • If you see something like Python 3.11.x or higher, you already have Python! Skip to Step 2.
    • If not, continue below.
  3. Install Python using Homebrew (recommended method)

    First, install Homebrew if you don't have it:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Then install Python:

    brew install python
  4. Verify installation

    python3 --version

    You should see Python 3.11.x or higher.

Alternative for macOS: Download the installer from python.org and run it.


For Windows Users:

  1. Download Python

    • Go to python.org
    • Click on the latest Python 3.x version (e.g., Python 3.12.x)
    • Download the "Windows installer (64-bit)"
  2. Run the Installer

    • Double-click the downloaded file
    • ⚠️ IMPORTANT: Check the box that says "Add Python to PATH" at the bottom
    • Click "Install Now"
    • Wait for installation to complete
    • Click "Close"
  3. Verify Installation

    • Press Windows Key + R
    • Type cmd and press Enter
    • In the command prompt, type:
    python --version

    You should see Python 3.11.x or higher.


Step 2: Download the Code

Option A: Download ZIP File (Easiest - No GitHub Account Required)

  1. Go to https://github.com/Quenos/option_chain_fetcher
    • No login required - the repository is public
  2. Click the green "Code" button (near the top right)
  3. Click "Download ZIP"
  4. Extract the ZIP file to a folder on your computer
    • macOS: Double-click the ZIP file
    • Windows: Right-click the ZIP file β†’ "Extract All"
  5. Remember where you extracted it (e.g., Documents/option_chain_fetcher)

Option B: Clone with Git (Advanced)

If you have Git installed:

git clone https://github.com/Quenos/option_chain_fetcher.git
cd option_chain_fetcher

Step 3: Install Dependencies

Dependencies are additional Python packages this tool needs to work.

For macOS:

  1. Open Terminal

  2. Navigate to the project folder

    cd /path/to/option_chain_fetcher

    Replace /path/to/ with the actual path where you extracted the files.

    Example:

    cd ~/Documents/option_chain_fetcher
  3. Install required packages

    pip3 install -r requirements.txt

    This will take a minute or two. Wait for it to complete.

For Windows:

  1. Open Command Prompt

    • Press Windows Key + R
    • Type cmd and press Enter
  2. Navigate to the project folder

    cd C:\path\to\option_chain_fetcher

    Replace C:\path\to\ with the actual path where you extracted the files.

    Example:

    cd C:\Users\YourName\Documents\option_chain_fetcher
  3. Install required packages

    pip install -r requirements.txt

    This will take a minute or two. Wait for it to complete.


Step 4: Setup Tastytrade API Access

To fetch option data, you need to set up API access with your Tastytrade account.

πŸ“š Follow the detailed tutorial: OAUTH_SETUP_TUTORIAL.md

Quick Overview:

  1. Log in to Tastytrade β†’ https://trade.tastytrade.com/

  2. Navigate to: Manage β†’ My Profile β†’ API

  3. Enable API Access (if not already enabled)

  4. Create a new OAuth Grant:

    • Redirect URI: http://localhost:8000 (exactly)
    • Permission: Select "Read" only (⚠️ do NOT select "Trade")
  5. Copy your Client ID and Client Secret (save them immediately!)

  6. Run the setup script:

    macOS:

    python3 get_refresh_token.py

    Windows:

    python get_refresh_token.py
  7. Follow the prompts to complete authentication

The script will create a .secrets file with your credentials. Keep this file safe and never share it!

For detailed step-by-step instructions with screenshots, see OAUTH_SETUP_TUTORIAL.md.


🎯 Quick Start

Fetch Option Data

macOS:

python3 option_chain_fetcher.py --max_dte 7 --min_strike 5800 --max_strike 6000

Windows:

python option_chain_fetcher.py --max_dte 7 --min_strike 5800 --max_strike 6000

This fetches options expiring in the next 7 days with strikes between 5800 and 6000.

⏱️ Performance Note: The fetcher retrieves data for each option individually. For large date ranges (high max_dte) and wide strike ranges, the process can take several minutes to complete. This is normal as the tool is fetching quotes and Greeks for hundreds or thousands of options. The script will show progress in the console and log file.

Export to JSON

macOS:

python3 export_to_json.py

Windows:

python export_to_json.py

This exports the latest data to JSON files in the json_exports/ folder.

Clear Database

macOS:

python3 option_chain_fetcher.py --clear_db

Windows:

python option_chain_fetcher.py --clear_db

πŸ“š Documentation

For detailed documentation, see:

Key Features Explained

Database Structure

The tool creates a SQLite database with two tables:

  1. option_chain_data: All option data with Greeks and quotes
  2. underlying_prices: SPX price at the time of each fetch

SPX/SPXW Handling

When you specify --symbol SPX or --symbol SPXW, the tool automatically fetches both:

  • SPX: Monthly/quarterly expirations
  • SPXW: Weekly expirations

This gives you complete market coverage in a single run!

Export Options

Filter your exports by:

  • Expiration date range
  • Strike price range
  • Delta range
  • Specific expiration date

Example:

# macOS
python3 export_to_json.py --start_date 2025-10-06 --end_date 2025-10-10 --min_delta 0.25 --max_delta 0.45

# Windows
python export_to_json.py --start_date 2025-10-06 --end_date 2025-10-10 --min_delta 0.25 --max_delta 0.45

🀝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


⚠️ Disclaimer

This tool is for educational and research purposes only. It provides market data but does not execute trades. Always verify data independently before making trading decisions.


πŸ†˜ Support

If you encounter issues:

  1. Check the OAUTH_SETUP_TUTORIAL.md troubleshooting section
  2. Review the log file: option_chain_fetcher.log
  3. Open an issue on GitHub with:
    • Your operating system (macOS/Windows)
    • Python version (python --version or python3 --version)
    • Error messages from the log file

πŸŽ‰ You're All Set!

Once you've completed the installation steps above, you're ready to start fetching SPX option data!

First run command:

macOS:

cd ~/Documents/option_chain_fetcher
python3 option_chain_fetcher.py --max_dte 7 --min_strike 5800 --max_strike 6000

Windows:

cd C:\Users\YourName\Documents\option_chain_fetcher
python option_chain_fetcher.py --max_dte 7 --min_strike 5800 --max_strike 6000

Happy trading! πŸ“ˆ

About

Get's option chain data from Tasty Trade and stores it in a database for further analysis

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages