# bluedabadi/schwabautotrading architecture

> Architecture diagram of the GitHub repository bluedabadi/schwabautotrading, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bluedabadi/schwabautotrading
- Repository: https://github.com/bluedabadi/schwabautotrading

## Overview

##### Main Components

a) External Services Layer:
- Charles Schwab API (via schwabdev)
- APIcalls.io (for earnings data)
- ThinkOrSwim integration

b) Core Application Components:
- Configuration Management
- Options Trading Engine
- Data Management
- Trading Strategies
- Analysis Tools

##### Detailed Component Breakdown

Top Level (External Interfaces):
**┌─ Charles Schwab API ─┐    ┌─ APIcalls.io ─┐**
- ┘    └──────────────┘

Core Application Layer:
**┌─ Configuration ─┐    ┌─ Trading Engine ─┐    ┌─ Analysis ─┐**
- config.py      │    │  trade_options.py│    │theta_analyzer│
- utils.py       │    │  stock_screener  │    └────────────┘
- ┘    │  earnings_calendar│
- ┘

Domain Layer:
**┌─ Options Module ─┐**
- options.py      │
- option_chains.py│
- stocks.py       │
- ┘

Data Layer:
**┌─ Data Storage ─┐**
- JSON Files    │
- Price History │
- Option Chains │
- ┘

##### Key Relationships to Highlight

- Data flow from external APIs to the trading engine
- Configuration influence on trading strategies
- Trading engine interaction with options module
- Analysis tools' data consumption
- Data storage interactions

##### Earnings Calendar Trading (Step 3)

A special note for "The Wheel Strategy" implementation as it's a recent addition.

##### Process Flows to Highlight

- Option Trade Lifecycle
- Decision Flow for Trade Selection
- Theta Decay Analysis Process

##### Technical Details

- Python as the primary language
- JSON as the data storage format
- Required API credentials and configurations
- Testing framework integration

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Services Layer
    subgraph External
        SchwabAPI["Charles Schwab API"]:::external
        APIcalls["APIcalls.io"]:::external
        TOS["ThinkOrSwim"]:::external
    end

    %% Core Application Layer
    subgraph Core
        Config["Configuration Management"]:::config
        click Config "https://github.com/bluedabadi/SchwabAutoTrading/tree/main/configs"
        ConfigMain["Main Config"]:::config
        click ConfigMain "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/configs/config.py"
        Utils["Utilities"]:::config
        click Utils "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/configs/utils.py"
        
        TradingEngine["Trading Engine"]:::trading
        click TradingEngine "https://github.com/bluedabadi/SchwabAutoTrading/tree/main/trading"
        TradeOptions["Trade Options"]:::trading
        click TradeOptions "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/trading/trade_options.py"
        StockScreener["Stock Screener"]:::trading
        click StockScreener "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/trading/stock_screener.py"
        EarningsCalendar["Earnings Calendar"]:::trading
        click EarningsCalendar "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/trading/earnings_calendar.py"
        
        Analysis["Analysis Tools"]:::analysis
        ThetaAnalyzer["Theta Analyzer"]:::analysis
        click ThetaAnalyzer "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/trading/theta_analyzer.py"
    end

    %% Domain Layer
    subgraph Domain
        OptionsModule["Options Module"]:::domain
        click OptionsModule "https://github.com/bluedabadi/SchwabAutoTrading/tree/main/options"
        Options["Core Options"]:::domain
        click Options "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/options/options.py"
        OptionChains["Option Chains"]:::domain
        click OptionChains "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/options/option_chains.py"
        Stocks["Stocks"]:::domain
        click Stocks "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/options/stocks.py"
    end

    %% Data Layer
    subgraph Data
        Storage["Data Storage"]:::data
        click Storage "https://github.com/bluedabadi/SchwabAutoTrading/tree/main/data"
        CompanyData["Company Data"]:::data
        click CompanyData "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/data/company_tickers.json"
        ChainStorage["Option Chains Storage"]:::data
        click ChainStorage "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/data/duol_option_chains.json"
        PriceHistory["Price History"]:::data
        click PriceHistory "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/data/duol_price_history.json"
        EarningsData["Earnings Data"]:::data
        click EarningsData "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/data/earnings_calendar.json"
    end

    %% Testing Framework
    subgraph Testing
        TestFramework["Testing Framework"]:::testing
        click TestFramework "https://github.com/bluedabadi/SchwabAutoTrading/tree/main/test"
        OptionsTest["Options Testing"]:::testing
        click OptionsTest "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/test/test_options.py"
        ChainTest["Option Chains Testing"]:::testing
        click ChainTest "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/test/test_option_chains.py"
        UtilsTest["Utils Testing"]:::testing
        click UtilsTest "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/test/test_utils.py"
    end

    %% Main Entry Point
    MainApp["Application Entry Point"]:::main
    click MainApp "https://github.com/bluedabadi/SchwabAutoTrading/blob/main/main.py"

    %% Relationships
    SchwabAPI --> TradingEngine
    APIcalls --> EarningsCalendar
    TOS --> TradingEngine
    
    Config --> ConfigMain
    Config --> Utils
    
    TradingEngine --> TradeOptions
    TradingEngine --> StockScreener
    TradingEngine --> EarningsCalendar
    
    Analysis --> ThetaAnalyzer
    
    OptionsModule --> Options
    OptionsModule --> OptionChains
    OptionsModule --> Stocks
    
    Storage --> CompanyData
    Storage --> ChainStorage
    Storage --> PriceHistory
    Storage --> EarningsData
    
    TestFramework --> OptionsTest
    TestFramework --> ChainTest
    TestFramework --> UtilsTest
    
    MainApp --> TradingEngine
    MainApp --> Config
    TradingEngine --> OptionsModule
    OptionsModule --> Storage
    Analysis --> Storage

    %% Styles
    classDef external fill:#68a0cf
    classDef config fill:#a8d695
    classDef trading fill:#95d6a4
    classDef analysis fill:#d695cf
    classDef domain fill:#d6cf95
    classDef data fill:#959595
    classDef testing fill:#cf95d6
    classDef main fill:#95cfd6

    %% Legend
    subgraph Legend
        L1["External Services"]:::external
        L2["Configuration"]:::config
        L3["Trading Components"]:::trading
        L4["Analysis Tools"]:::analysis
        L5["Domain Layer"]:::domain
        L6["Data Storage"]:::data
        L7["Testing"]:::testing
        L8["Main Entry"]:::main
    end
```
