EMO Options Bot v2.0 is a comprehensive, institutional-grade options trading system with advanced database management, real-time monitoring, and professional-grade infrastructure.
π― Current Status: Phase 3 Complete β Phase 4 Ready
- β Production patch set applied with fail-closed safety
- β Stage-only integration operational
- π Ready for Phase 4 Auto-Promotion Sprint
- ποΈ Dual Database Architecture: OPS (Operational) + Institutional databases
- π Real-time Web Interface: Professional HTML dashboard with auto-refresh
- π§ Advanced CLI Tools: Comprehensive command-line interface for order management
- π₯ Health Monitoring: Live system health monitoring with REST APIs
- π‘οΈ Risk Management: Built-in risk scoring and compliance validation
- π Institutional Integration: Enterprise-grade order management and approval workflows
- π Backup & Recovery: Comprehensive data backup and restore capabilities
- β‘ Performance Optimized: Efficient database operations and caching
- π Phase 3 Components: LLM orchestration, risk gates, Lua strategies, voice interface
π― Next Phase: Stage-Only β Adaptive Auto-Promotion
The system is ready for the Phase 4 Initialization Sprint Plan - a 6-week roadmap to transition from manual staging to controlled auto-promotion.
- Week 1-2: Infrastructure hardening + promotion engine
- Week 3-4: Paper trading integration + adaptive feedback
- Week 5-6: Voice interface + compliance audit
- β
Stage-Only Integration - Trades staged to
data/staged/safely - β Risk Gates - Fail-closed validation with comprehensive checks
- β Production Safety - Pydantic schemas + environment routing
- β Lua Strategies - Sandboxed execution with graceful fallback
- β Test Coverage - Contract tests passing
π π View Full Phase 4 Sprint Plan β
EMO Options Bot v2.0
βββ π¦ OPS Database (SQLite/PostgreSQL)
β βββ Order Staging & Management
β βββ Risk Assessment Engine
β βββ Compliance Validation
βββ ποΈ Institutional Database
β βββ Enterprise Order Management
β βββ Approval Workflows
β βββ Audit Trails
βββ π Web Interface (Port 8082)
β βββ Order Dashboard
β βββ Health Monitoring
β βββ Real-time Metrics
βββ π οΈ CLI Tools
βββ Order Staging CLI
βββ Database Manager
βββ Health Monitor
- Python 3.8+ (3.11+ recommended)
- pip package manager
- SQLite (included with Python)
- PostgreSQL (optional, for production)
# Clone or extract the project
cd emo_options_bot_sqlite_plot_upgrade
# Install dependencies
pip install -r requirements.txt
# Run setup (initializes databases and validates system)
python setup.py --full# Start all services
python start_emo.py
# Or start components individually
python tools/emit_health.py --port 8082 # Health monitoring
python tools/stage_order_cli.py --help # CLI tools- Order Dashboard: http://localhost:8082/orders.html
- Health Status: http://localhost:8082/health
- System Metrics: http://localhost:8082/metrics
- Health Monitoring Integration: Real-time component health tracking
- Order Staging Hooks: Seamless integration with order management
- Performance Metrics: Comprehensive execution time and resource monitoring
- Email Notifications: Automated alerts for critical events
- Backup Management: Automated database backup with rotation
- Error Recovery: Robust error handling with graceful degradation
- Robust API Error Handling: Intelligent retry logic with exponential backoff
- Performance Monitoring: Real-time metrics collection and reporting
- Integration Hooks: Seamless connection to runner system
- Health Check Endpoints: Status monitoring for operational dashboards
- Configurable Symbols: Dynamic symbol management for data collection
- Rate Limit Handling: Intelligent API rate limit management
- Order Rotation (
tools/rotate_staged_orders.py): Date-based archival with configurable retention - Order Staging (
tools/stage_order_cli.py): Interactive order review and approval - Health Monitoring (
tools/emit_health.py): Component status tracking
- Database Router (
db/router.py): Environment-aware SQLite/PostgreSQL routing - Health Monitoring: Connection pool management and health checks
- Schema Management: Automatic migration and version tracking
- CLI Management: Command-line database operations
- Environment Validator (
tools/validate_env.py): Multi-mode production readiness checks - Workspace Manager (
workspace_config.py): Comprehensive environment setup - Enhanced Configuration (
src/utils/enhanced_config.py): Type-safe configuration management
- Comprehensive Test Suite (
test_suite.py): Unit, integration, and performance tests - Enhanced Build System (
build.py): Automated build, test, and deployment pipeline - Health Monitoring: Real-time component status tracking
# Initialize workspace
python workspace_config.py --init
# Setup development environment
python workspace_config.py --setup-dev
# Verify installation
python workspace_config.py --healthCopy and configure environment variables:
# Copy development template
copy .env.dev .env
# Edit configuration (required)
notepad .envRequired Environment Variables:
# Core Configuration
EMO_ENV=dev
EMO_SQLITE_PATH=./ops/emo.sqlite
EMO_SYMBOLS=SPY,QQQ,AAPL
# API Credentials (required for live data)
ALPACA_KEY_ID=your_alpaca_key_id
ALPACA_SECRET_KEY=your_alpaca_secret_key
# Optional: Email Notifications
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@example.com
SMTP_PASS=your_app_password
NOTIFY_EMAIL=notifications@example.com# Full build with tests
python build.py
# Quick build (skip tests)
python build.py --quick
# Run tests only
python test_suite.py# Start health monitoring
python tools/emit_health.py
# Run live data collection
python data/live_logger.py
# Execute main orchestration
python tools/runner.py
# Manual order staging
python tools/stage_order_cli.pyEnhanced orchestration system with comprehensive monitoring:
# Basic execution
python tools/runner.py
# With email notifications
python tools/runner.py --email-notifications
# Performance monitoring mode
python tools/runner.py --performance-monitoring
# Health integration mode
python tools/runner.py --health-integrationFeatures:
- Real-time health monitoring integration
- Performance metrics collection and reporting
- Automatic backup management with rotation
- Email notifications for critical events
- Order staging hooks for review workflow
- Robust error handling with recovery
Enhanced live market data collector with error handling:
# Start live data collection
python data/live_logger.py
# Specific symbols
python data/live_logger.py --symbols SPY,QQQ,AAPL
# Performance monitoring
python data/live_logger.py --performance-monitoring
# Health check
python data/live_logger.py --health-checkFeatures:
- Robust API error handling with retry logic
- Real-time performance metrics collection
- Integration hooks for runner system
- Health check endpoints for monitoring
- Configurable symbol lists
- Rate limit intelligent handling
Automated order archival and cleanup:
# Archive orders older than 7 days
python tools/rotate_staged_orders.py --archive --retention-days 7
# Preview what would be archived (dry run)
python tools/rotate_staged_orders.py --archive --dry-run
# Clean up old archives
python tools/rotate_staged_orders.py --cleanup --archive-retention-days 30Production readiness validation:
# Validate development environment
python tools/validate_env.py dev
# Validate production with all checks
python tools/validate_env.py prod --check-database --check-broker
# Generate validation report
python tools/validate_env.py staging --output-format jsonComprehensive build and deployment pipeline:
# Full development build
python build.py
# Production deployment
python build.py --deploy prod
# Staging deployment
python build.py --deploy staging
# Test-only build
python build.py --test-only
# Environment validation only
python build.py --validateBuild Phases:
- Environment validation and setup
- Component dependency checking
- Database migration and health validation
- Comprehensive testing (unit/integration/performance)
- Live logger integration and validation
- Workspace configuration and validation
- Health monitoring setup
- Deployment readiness verification
Comprehensive testing framework:
# Run all tests
python test_suite.py
# Unit tests only
python test_suite.py --unit
# Integration tests
python test_suite.py --integration
# Performance benchmarking
python test_suite.py --performance
# Test specific component
python test_suite.py --component live_logger- Purpose: Local development and testing
- Configuration:
.env.dev - Features: Order staging enabled, email notifications disabled, auto-backup enabled
- Database: Local SQLite
- API: Paper trading enabled
- Purpose: Pre-production testing
- Configuration:
.env.staging - Features: Order staging enabled, email notifications enabled, comprehensive monitoring
- Database: Staging SQLite or PostgreSQL
- API: Paper trading (Alpaca Paper API)
- Purpose: Live trading operations
- Configuration:
.env.prod - Features: Order staging disabled, all monitoring enabled, email notifications enabled
- Database: Production PostgreSQL or SQLite
- API: Live trading (Alpaca Live API)
- Component Health:
python tools/emit_health.py - Live Logger Health:
python data/live_logger.py --health-check - Workspace Health:
python workspace_config.py --health
- Runner Metrics: Execution time, resource usage, component performance
- Live Logger Metrics: API response times, error rates, data collection rates
- Database Metrics: Query performance, connection health, schema status
- Robust Retry Logic: Exponential backoff for API failures
- Graceful Degradation: Continues operation with reduced functionality
- Error Reporting: Comprehensive logging with email notifications
- Recovery Procedures: Automatic recovery from transient failures
- Environment Separation: Distinct configurations for dev/staging/prod
- Credential Management: Secure handling of API keys and secrets
- Validation: Environment-specific security validations
- Database Encryption: SQLite encryption support (optional)
- API Security: Secure credential storage and transmission
- Backup Security: Encrypted backup storage (configurable)
python workspace_config.py --setup-dev
python build.py --validate# Edit code
# Run tests for affected components
python test_suite.py --component your_component# Run integration tests
python test_suite.py --integration
# Validate environment
python tools/validate_env.py devpython build.py --deploy staging
python tools/validate_env.py staging --check-databasepython build.py --deploy prod
python tools/validate_env.py prod --check-database --check-broker- Connection Pooling: Efficient database connection management
- Query Optimization: Optimized database queries and indexing
- Health Monitoring: Real-time database performance tracking
- Rate Limiting: Intelligent API rate limit management
- Retry Logic: Exponential backoff for failed requests
- Caching: Response caching for frequently accessed data
- Metrics Collection: Real-time performance monitoring
- Resource Management: Efficient memory and CPU usage
- Background Processing: Non-blocking operations for better responsiveness
# Check environment
python build.py --validate
# Check component health
python workspace_config.py --health
# Run tests to identify issues
python test_suite.py --verbose# Test database connection
python -c "from db.router import test_connection; print(test_connection())"
# Reset database (development only)
rm ops/emo.sqlite
python workspace_config.py --setup-dev# Validate API credentials
python tools/validate_env.py dev --check-broker
# Test live logger connectivity
python data/live_logger.py --health-check# Validate configuration
python tools/validate_env.py dev
# Check environment variables
python -c "from src.utils.enhanced_config import Config; c = Config(); print(c.get('EMO_ENV'))"- Application Logs:
logs/directory - Build Reports:
build_report_*.jsonfiles - Health Reports: Component health endpoints
- Performance Reports: Generated by build system
- Create component in appropriate directory
- Add to
workspace_config.pycomponent list - Add tests in
test_suite.py - Update build system in
build.py
- Add new environment to
workspace_config.py - Create environment template
- Update validation in
tools/validate_env.py - Add deployment support in
build.py
- Implement health check interface
- Add to health monitoring system
- Update performance tracking
- Add to build validation
from src.utils.enhanced_config import Config
config = Config()
value = config.get("SETTING_NAME", "default_value")
bool_value = config.as_bool("BOOLEAN_SETTING")
int_value = config.as_int("INTEGER_SETTING")from db.router import DatabaseRouter
router = DatabaseRouter()
connection = router.get_connection()
health = router.test_connection()from data.live_logger import LiveLogger
logger = LiveLogger()
health = logger.health_check()
report = logger.get_performance_report()- Fork the Repository: Create your own fork for development
- Create Feature Branch:
git checkout -b feature/your-feature - Make Changes: Implement your feature with tests
- Run Tests:
python test_suite.py - Validate Build:
python build.py - Submit Pull Request: With comprehensive description
- Type Hints: Use type hints for all public APIs
- Documentation: Comprehensive docstrings and comments
- Error Handling: Robust error handling with logging
- Testing: Unit and integration tests for all functionality
This project is licensed under the MIT License. See LICENSE file for details.
For support and questions:
- Issues: GitHub Issues for bug reports and feature requests
- Documentation: This README and inline code documentation
- Health Monitoring: Built-in health check endpoints
- Logs: Comprehensive logging for troubleshooting
Built with β€οΈ for robust, production-ready EMO Options Bot operations