Automated Options Trading System
Multi-strategy trading platform with intelligent strategy selection, real-time market data streaming, and order execution via TastyTrade API.
- 14 Automated Strategies: Vertical spreads (4), Iron condors (2), Butterflies (2), Straddles/Strangles (4), Senex Trident (2)
- Intelligent Selection: Auto mode with market condition scoring and strategy comparison
- Daily Automation: Scheduled execution via Celery Beat at 10 AM ET
- Order Management: Complete execution workflow with profit targets and cancellation support
- Live Streaming: DXLinkStreamer integration for quotes, Greeks, and account data
- WebSocket Communication: Real-time updates for positions, orders, and market conditions
- Smart Caching: 5-second cache for Greeks, 5-minute TTL for option chains
- Position Sizing: Automated capital allocation based on account size
- Greeks Calculations: Portfolio and position-level Greeks with health scoring
- Market Validation: Bollinger Bands, ATR, trend analysis for strategy selection
- OAuth Integration: Complete TastyTrade OAuth flow with token refresh
- Encrypted Storage: Django encrypted model fields for sensitive data
- Session-Based Auth: Secure user authentication without JWT complexity
Backend: Python 3.12, Django 5.2 Database: SQLite (dev), PostgreSQL (prod) Async: Celery + Redis, Django Channels Trading API: TastyTrade SDK 11.0 Testing: pytest Code Quality: ruff, black, mypy, bandit
- Python 3.12+
- Podman and podman-compose (for Redis container)
- TastyTrade account (for OAuth authentication)
-
Clone the repository
git clone <senextrader-url> senextrader cd senextrader
-
Install Podman and podman-compose (if not already installed)
# Fedora/RHEL sudo dnf install podman podman-compose # Ubuntu/Debian sudo apt-get install podman podman-compose
-
Set up Redis with Podman
# Start Redis container using the development docker-compose file cd docker podman-compose -f docker-compose.dev.yml up -d cd ..
-
Create virtual environment
python3 -m venv .venv source .venv/bin/activate # bash/zsh # OR for fish shell: source .venv/bin/activate.fish
-
Install dependencies
pip install --upgrade pip pip install -r requirements.txt
-
Create .env file
cp .env.example .env
-
Generate encryption key and update .env
Generate
FIELD_ENCRYPTION_KEY:python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"Copy the output and add to
.env:FIELD_ENCRYPTION_KEY=<paste-generated-key-here>
Optional: If developing remotely (over SSH), also set:
ALLOWED_HOSTS=localhost,127.0.0.1,your-remote-host WS_ALLOWED_ORIGINS=http://localhost:8000,http://your-remote-host:8000
-
Run database migrations
python manage.py migrate
-
Create superuser (optional, for admin access)
python manage.py createsuperuser
# Terminal 1: Django development server
python manage.py runserver
# Terminal 2: Celery worker + beat (convenience script)
./run_celery.sh # Runs both worker and beat, cleans stale schedule files
# Alternative: Run Celery manually
# Terminal 2: celery -A senextrader worker -l info
# Terminal 3: celery -A senextrader beat -l infoNote: Redis should already be running from step 3. If you need to restart it:
cd docker
podman-compose -f docker-compose.dev.yml restart- Access admin at
http://localhost:8000/admin - Navigate to Settings → Brokerage
- Complete TastyTrade OAuth authentication
- Configure risk tolerance and strategy preferences
- Enable automated trading (optional)
senextrader/
├── accounts/ # User auth, broker OAuth, account settings
├── trading/ # Trading logic, positions, orders
├── streaming/ # Real-time WebSocket consumers
├── services/ # Business logic layer (ALL logic here)
│ ├── *_strategy.py # 14 strategy implementations
│ ├── strategy_selector.py
│ ├── strategy_registry.py
│ ├── greeks_service.py
│ ├── market_analysis.py
│ ├── option_chain_service.py
│ └── execution/ # Order placement and management
├── templates/ # Dark theme UI
└── static/ # Frontend assets (UI only, no business logic)
Available Strategies:
- Vertical Spreads: Bull Put, Bear Call, Bull Call, Bear Put
- Iron Condors: Long, Short
- Butterflies: Iron Butterfly
- Straddles/Strangles: Long Straddle, Long Strangle
- Advanced: Senex Trident, Calendar Spread, Call Backspread
- Basic: Cash Secured Put, Covered Call
# Format code
black .
# Lint and auto-fix
ruff check --fix .
# Type check
mypy .
# Security scan
bandit -r . -ll
# Run tests
pytest
# Run tests with coverage report
pytest # Coverage report automatically generated (terminal + HTML)
# HTML report: htmlcov/index.htmlDry-Run Mode enables safe development and testing without real API calls or database writes.
- Calls TastyTrade API with
dry_run=Trueparameter for validation - Gets real buying power impact and fee calculations from TastyTrade
- Skips database writes (no Position/Trade records created)
- Returns DryRunResult with order validation and simulated details
- Perfect for testing strategy logic end-to-end with real TastyTrade validation
Enabled by default in development (defined in settings/development.py):
TASTYTRADE_DRY_RUN = True # Default in developmentDisable dry-run in development (for real sandbox testing):
# In your .env file
TASTYTRADE_DRY_RUN=FalseProduction (automatically enforced in settings/production.py):
TASTYTRADE_DRY_RUN = False # Hardcoded - attempts to enable will raise ValueError- All validation logic runs normally
- Strategy selection and market analysis execute
- TastyTrade API validates order via
/orders/dry-runendpoint - Returns buying power impact and fee calculations from TastyTrade
- Order gets
order.id = -1(TastyTrade sentinel for dry-run) - Order is NOT queued or executed by TastyTrade
- No database records created (Position/Trade models)
- ℹ️ Returns
DryRunResultdataclass with validation results
After testing in dry-run mode:
- Set
TASTYTRADE_DRY_RUN=Falsein.env - Restart Django server
- Execute trades normally - full API calls and database persistence
Dry-run mode cannot be enabled in production (raises ValueError on startup).
- Simplicity First: Choose the simplest solution that works
- DRY Principle: Search existing code before writing new
- Service Layer: All business logic in
services/, never in frontend - Dark Theme: All UI follows dark theme variables
- Session Auth: No JWT, session-based authentication only
In-Repo Documentation:
docs/directory- AI Configuration:
AI.md,AGENTS.md,CLAUDE.md(root directory, gitignored)
- Environment Setup: Follow the Installation section to set up your development environment
- AI Guidelines: Read
AGENTS.md/CLAUDE.mdfor development patterns - Code Quality: Run linting/formatting tools before commits
ruff check --fix . black . pytest
- Pre-Implementation Checks:
- Search existing code before writing new (
/pre-impl <feature>) - Verify TastyTrade SDK usage (
/tt-check <function>)
- Search existing code before writing new (
- Testing: Write tests for new features (maintain 100% pass rate)
- Documentation: Update README and code comments as needed
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
- Free for personal, educational, and research use
- Commercial use prohibited without explicit permission
- Attribution required - Give appropriate credit
- Share-Alike - Derivatives must use the same license
See the LICENSE file for full details.
For commercial licensing inquiries, please contact the project maintainers.
- Issues: GitHub Issues
- Questions: Open a discussion
- Development: See Contributing section above
Built with Django, powered by TastyTrade API