๐Ÿ“ ICT ML Trading System

Complete Project Structure & File Organization

Production-grade architecture with comprehensive logging, error handling, and best practices

Complete Directory Structure

๐ŸŽฏ Architecture Philosophy: This project follows enterprise-grade Python best practices with clear separation of concerns, comprehensive error handling, extensive logging, and modular design for maintainability and scalability.
ict-ml-trading/ โ”‚ โ”œโ”€โ”€ .env.example # Environment variables template โ”œโ”€โ”€ .env # Actual environment variables (git-ignored) โ”œโ”€โ”€ .gitignore # Git ignore patterns โ”œโ”€โ”€ .pre-commit-config.yaml # Pre-commit hooks configuration โ”œโ”€โ”€ README.md # Project documentation โ”œโ”€โ”€ requirements.txt # Production dependencies โ”œโ”€โ”€ requirements-dev.txt # Development dependencies โ”œโ”€โ”€ setup.py # Package installation configuration โ”œโ”€โ”€ pyproject.toml # Modern Python project configuration โ”œโ”€โ”€ Makefile # Common commands automation โ”œโ”€โ”€ CHANGELOG.md # Version history and changes โ”œโ”€โ”€ LICENSE # Software license โ”‚ โ”œโ”€โ”€ config/ # Configuration files โ”‚ โ”œโ”€โ”€ config.yaml # Main application configuration โ”‚ โ”œโ”€โ”€ logging.yaml # Logging configuration โ”‚ โ”œโ”€โ”€ detectors.yaml # Pattern detector parameters โ”‚ โ”œโ”€โ”€ models.yaml # ML model hyperparameters โ”‚ โ”œโ”€โ”€ trading.yaml # Trading strategy parameters โ”‚ โ”œโ”€โ”€ alerts.yaml # Alert system configuration โ”‚ โ””โ”€โ”€ database.yaml # Database connection settings โ”‚ โ”œโ”€โ”€ src/ # Main source code โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ core/ # Core business logic โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ exceptions.py # Custom exception classes โ”‚ โ”‚ โ”œโ”€โ”€ constants.py # Application-wide constants โ”‚ โ”‚ โ”œโ”€โ”€ enums.py # Enumerations (PatternType, Grade, etc.) โ”‚ โ”‚ โ””โ”€โ”€ base_classes.py # Abstract base classes โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ config/ # Configuration management โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ config_loader.py # Load and validate configurations โ”‚ โ”‚ โ”œโ”€โ”€ settings.py # Settings dataclasses โ”‚ โ”‚ โ””โ”€โ”€ validators.py # Configuration validation logic โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ logging/ # Logging system โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ logger.py # Logger setup and configuration โ”‚ โ”‚ โ”œโ”€โ”€ formatters.py # Custom log formatters โ”‚ โ”‚ โ”œโ”€โ”€ handlers.py # Custom log handlers โ”‚ โ”‚ โ”œโ”€โ”€ filters.py # Log filters โ”‚ โ”‚ โ””โ”€โ”€ decorators.py # Logging decorators (@log_execution) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ data/ # Data management โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ database.py # Database connection and ORM โ”‚ โ”‚ โ”œโ”€โ”€ models.py # SQLAlchemy data models โ”‚ โ”‚ โ”œโ”€โ”€ repositories.py # Data access layer (repository pattern) โ”‚ โ”‚ โ”œโ”€โ”€ loaders.py # Data loading utilities โ”‚ โ”‚ โ”œโ”€โ”€ preprocessors.py # Data preprocessing and cleaning โ”‚ โ”‚ โ”œโ”€โ”€ validators.py # Data validation โ”‚ โ”‚ โ””โ”€โ”€ schemas.py # Pydantic schemas for validation โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ detectors/ # Pattern detection โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ base_detector.py # Abstract base detector class โ”‚ โ”‚ โ”œโ”€โ”€ fvg_detector.py # Fair Value Gap detection โ”‚ โ”‚ โ”œโ”€โ”€ order_block_detector.py # Order Block detection โ”‚ โ”‚ โ”œโ”€โ”€ liquidity_detector.py # Liquidity sweep detection โ”‚ โ”‚ โ”œโ”€โ”€ premium_discount.py # Premium/Discount calculator โ”‚ โ”‚ โ”œโ”€โ”€ structure_detector.py # Market structure (BOS, CHoCH) โ”‚ โ”‚ โ”œโ”€โ”€ scanner.py # Orchestrates all detectors โ”‚ โ”‚ โ””โ”€โ”€ utils.py # Detector utility functions โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ features/ # Feature engineering โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ base_features.py # Base feature engineering class โ”‚ โ”‚ โ”œโ”€โ”€ pattern_features.py # Pattern-specific features โ”‚ โ”‚ โ”œโ”€โ”€ technical_features.py # Technical indicators โ”‚ โ”‚ โ”œโ”€โ”€ temporal_features.py # Time-based features โ”‚ โ”‚ โ”œโ”€โ”€ context_features.py # Market context features โ”‚ โ”‚ โ”œโ”€โ”€ orderflow_features.py # Order flow features โ”‚ โ”‚ โ””โ”€โ”€ feature_store.py # Feature storage and retrieval โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ models/ # Machine learning models โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ base_model.py # Abstract base model class โ”‚ โ”‚ โ”œโ”€โ”€ pattern_grader.py # Individual pattern grading models โ”‚ โ”‚ โ”œโ”€โ”€ setup_classifier.py # Complete setup classification โ”‚ โ”‚ โ”œโ”€โ”€ training.py # Model training pipeline โ”‚ โ”‚ โ”œโ”€โ”€ evaluation.py # Model evaluation metrics โ”‚ โ”‚ โ”œโ”€โ”€ tuning.py # Hyperparameter tuning โ”‚ โ”‚ โ”œโ”€โ”€ inference.py # Real-time prediction โ”‚ โ”‚ โ””โ”€โ”€ registry.py # Model versioning and registry โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ labeling/ # Labeling system โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ interface.py # Labeling interface orchestrator โ”‚ โ”‚ โ”œโ”€โ”€ notion_integration.py # Notion API integration โ”‚ โ”‚ โ”œโ”€โ”€ web_ui.py # Flask/FastAPI web interface โ”‚ โ”‚ โ”œโ”€โ”€ quality_checker.py # Label quality validation โ”‚ โ”‚ โ”œโ”€โ”€ anchors.py # Anchor example management โ”‚ โ”‚ โ””โ”€โ”€ export.py # Export labels to training format โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ alerts/ # Alert system โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ base_alert.py # Abstract alert handler โ”‚ โ”‚ โ”œโ”€โ”€ telegram_bot.py # Telegram bot integration โ”‚ โ”‚ โ”œโ”€โ”€ slack_integration.py # Slack integration โ”‚ โ”‚ โ”œโ”€โ”€ email_alerts.py # Email notifications โ”‚ โ”‚ โ”œโ”€โ”€ alert_manager.py # Alert orchestration and routing โ”‚ โ”‚ โ””โ”€โ”€ templates.py # Alert message templates โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ trading/ # Trading execution โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ broker_interface.py # Broker API abstraction โ”‚ โ”‚ โ”œโ”€โ”€ order_manager.py # Order execution and tracking โ”‚ โ”‚ โ”œโ”€โ”€ risk_manager.py # Position sizing and risk controls โ”‚ โ”‚ โ”œโ”€โ”€ portfolio.py # Portfolio state management โ”‚ โ”‚ โ”œโ”€โ”€ execution_engine.py # Trade execution logic โ”‚ โ”‚ โ””โ”€โ”€ validators.py # Pre-trade validation โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ backtesting/ # Backtesting framework โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ engine.py # Backtest execution engine โ”‚ โ”‚ โ”œโ”€โ”€ metrics.py # Performance metrics calculation โ”‚ โ”‚ โ”œโ”€โ”€ reports.py # Backtest report generation โ”‚ โ”‚ โ”œโ”€โ”€ visualizations.py # Performance visualizations โ”‚ โ”‚ โ””โ”€โ”€ validators.py # Backtest result validation โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ monitoring/ # System monitoring โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ metrics_collector.py # Collect system metrics โ”‚ โ”‚ โ”œโ”€โ”€ health_checker.py # System health checks โ”‚ โ”‚ โ”œโ”€โ”€ performance_tracker.py # Track model performance โ”‚ โ”‚ โ”œโ”€โ”€ alerting.py # Monitoring alerts โ”‚ โ”‚ โ””โ”€โ”€ dashboard.py # Monitoring dashboard โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ visualization/ # Chart and data visualization โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ chart_generator.py # Generate trading charts โ”‚ โ”‚ โ”œโ”€โ”€ pattern_plotter.py # Plot detected patterns โ”‚ โ”‚ โ”œโ”€โ”€ performance_plots.py # Performance visualizations โ”‚ โ”‚ โ””โ”€โ”€ screenshot.py # Screenshot capture for labeling โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ utils/ # Utility functions โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”œโ”€โ”€ datetime_utils.py # Date/time helpers โ”‚ โ”œโ”€โ”€ file_utils.py # File operations โ”‚ โ”œโ”€โ”€ string_utils.py # String manipulation โ”‚ โ”œโ”€โ”€ math_utils.py # Mathematical utilities โ”‚ โ”œโ”€โ”€ decorators.py # Utility decorators โ”‚ โ”œโ”€โ”€ retry.py # Retry logic for API calls โ”‚ โ””โ”€โ”€ validators.py # General validation functions โ”‚ โ”œโ”€โ”€ data/ # Data storage โ”‚ โ”œโ”€โ”€ raw/ # Raw downloaded data โ”‚ โ”‚ โ”œโ”€โ”€ ohlcv/ # OHLCV market data โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ 1min/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ 5min/ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ 15min/ โ”‚ โ”‚ โ””โ”€โ”€ orderflow/ # Order flow data (if available) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ processed/ # Cleaned and processed data โ”‚ โ”‚ โ”œโ”€โ”€ features/ # Computed features โ”‚ โ”‚ โ”œโ”€โ”€ patterns/ # Detected patterns โ”‚ โ”‚ โ””โ”€โ”€ snapshots/ # OHLC snapshots for patterns โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ labels/ # Labeled data โ”‚ โ”‚ โ”œโ”€โ”€ individual_patterns/ # Pattern-level labels โ”‚ โ”‚ โ”œโ”€โ”€ complete_setups/ # Setup-level labels โ”‚ โ”‚ โ”œโ”€โ”€ anchors/ # Anchor examples โ”‚ โ”‚ โ””โ”€โ”€ label_metadata.json # Label versioning and metadata โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ screenshots/ # Chart screenshots for labeling โ”‚ โ”‚ โ”œโ”€โ”€ patterns/ # Pattern screenshots โ”‚ โ”‚ โ””โ”€โ”€ setups/ # Complete setup screenshots โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ external/ # External data sources โ”‚ โ”œโ”€โ”€ economic_calendar/ # News events โ”‚ โ””โ”€โ”€ reference/ # Reference data (holidays, etc.) โ”‚ โ”œโ”€โ”€ models/ # Trained models storage โ”‚ โ”œโ”€โ”€ pattern_graders/ # Individual pattern models โ”‚ โ”‚ โ”œโ”€โ”€ fvg/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ v1.0.0/ # Versioned models โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ v1.1.0/ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ latest/ # Symlink to latest version โ”‚ โ”‚ โ”œโ”€โ”€ order_block/ โ”‚ โ”‚ โ””โ”€โ”€ liquidity/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ strategy_models/ # Complete setup models โ”‚ โ”‚ โ”œโ”€โ”€ continuation/ # 3:00-3:15 continuation model โ”‚ โ”‚ โ””โ”€โ”€ reversal/ # 3:30-3:50 reversal model โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ metadata/ # Model metadata and configs โ”‚ โ”‚ โ”œโ”€โ”€ model_registry.json # Track all model versions โ”‚ โ”‚ โ””โ”€โ”€ performance_history.json # Historical performance โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ artifacts/ # Training artifacts โ”‚ โ”œโ”€โ”€ feature_importances/ โ”‚ โ”œโ”€โ”€ training_curves/ โ”‚ โ””โ”€โ”€ validation_reports/ โ”‚ โ”œโ”€โ”€ logs/ # Application logs โ”‚ โ”œโ”€โ”€ application/ # General application logs โ”‚ โ”‚ โ”œโ”€โ”€ app.log # Current log file โ”‚ โ”‚ โ””โ”€โ”€ archive/ # Rotated logs โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ detectors/ # Pattern detection logs โ”‚ โ”‚ โ”œโ”€โ”€ fvg_detector.log โ”‚ โ”‚ โ”œโ”€โ”€ order_block_detector.log โ”‚ โ”‚ โ””โ”€โ”€ scanner.log โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ models/ # ML model logs โ”‚ โ”‚ โ”œโ”€โ”€ training.log # Training sessions โ”‚ โ”‚ โ”œโ”€โ”€ inference.log # Real-time predictions โ”‚ โ”‚ โ””โ”€โ”€ evaluation.log # Model evaluation โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ trading/ # Trading execution logs โ”‚ โ”‚ โ”œโ”€โ”€ orders.log # Order execution โ”‚ โ”‚ โ”œโ”€โ”€ risk.log # Risk management decisions โ”‚ โ”‚ โ””โ”€โ”€ portfolio.log # Portfolio changes โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ alerts/ # Alert system logs โ”‚ โ”‚ โ”œโ”€โ”€ telegram.log โ”‚ โ”‚ โ””โ”€โ”€ notifications.log โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ errors/ # Error logs โ”‚ โ”‚ โ”œโ”€โ”€ exceptions.log # All exceptions โ”‚ โ”‚ โ””โ”€โ”€ critical.log # Critical errors only โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ performance/ # Performance monitoring โ”‚ โ”‚ โ”œโ”€โ”€ metrics.log # System metrics โ”‚ โ”‚ โ””โ”€โ”€ profiling.log # Performance profiling โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ audit/ # Audit trail โ”‚ โ”œโ”€โ”€ data_access.log # Data access audit โ”‚ โ”œโ”€โ”€ config_changes.log # Configuration changes โ”‚ โ””โ”€โ”€ model_deployments.log # Model deployment history โ”‚ โ”œโ”€โ”€ tests/ # Test suite โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”œโ”€โ”€ conftest.py # Pytest configuration and fixtures โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ unit/ # Unit tests โ”‚ โ”‚ โ”œโ”€โ”€ test_detectors/ โ”‚ โ”‚ โ”œโ”€โ”€ test_features/ โ”‚ โ”‚ โ”œโ”€โ”€ test_models/ โ”‚ โ”‚ โ””โ”€โ”€ test_utils/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ integration/ # Integration tests โ”‚ โ”‚ โ”œโ”€โ”€ test_pipeline.py # End-to-end pipeline โ”‚ โ”‚ โ”œโ”€โ”€ test_database.py # Database integration โ”‚ โ”‚ โ””โ”€โ”€ test_alerts.py # Alert system integration โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ validation/ # Validation tests โ”‚ โ”‚ โ”œโ”€โ”€ test_model_accuracy.py โ”‚ โ”‚ โ”œโ”€โ”€ test_backtest_results.py โ”‚ โ”‚ โ””โ”€โ”€ test_data_quality.py โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ fixtures/ # Test data and fixtures โ”‚ โ”‚ โ”œโ”€โ”€ sample_data/ โ”‚ โ”‚ โ”œโ”€โ”€ mock_responses/ โ”‚ โ”‚ โ””โ”€โ”€ expected_outputs/ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ performance/ # Performance tests โ”‚ โ”œโ”€โ”€ test_speed.py # Speed benchmarks โ”‚ โ””โ”€โ”€ test_memory.py # Memory usage tests โ”‚ โ”œโ”€โ”€ scripts/ # Utility scripts โ”‚ โ”œโ”€โ”€ download_data.py # Download historical data โ”‚ โ”œโ”€โ”€ process_data.py # Batch data processing โ”‚ โ”œโ”€โ”€ run_detection.py # Run pattern detection โ”‚ โ”œโ”€โ”€ train_models.py # Train ML models โ”‚ โ”œโ”€โ”€ evaluate_models.py # Evaluate model performance โ”‚ โ”œโ”€โ”€ backtest.py # Run backtests โ”‚ โ”œโ”€โ”€ live_trading.py # Live trading execution โ”‚ โ”œโ”€โ”€ setup_database.py # Initialize database โ”‚ โ”œโ”€โ”€ migrate_data.py # Data migration โ”‚ โ”œโ”€โ”€ cleanup.py # Cleanup old logs/data โ”‚ โ””โ”€โ”€ export_labels.py # Export labels from Notion โ”‚ โ”œโ”€โ”€ notebooks/ # Jupyter notebooks โ”‚ โ”œโ”€โ”€ 01_data_exploration.ipynb โ”‚ โ”œโ”€โ”€ 02_pattern_analysis.ipynb โ”‚ โ”œโ”€โ”€ 03_feature_engineering.ipynb โ”‚ โ”œโ”€โ”€ 04_model_training.ipynb โ”‚ โ”œโ”€โ”€ 05_model_evaluation.ipynb โ”‚ โ”œโ”€โ”€ 06_backtest_analysis.ipynb โ”‚ โ””โ”€โ”€ 07_label_quality_check.ipynb โ”‚ โ”œโ”€โ”€ docs/ # Documentation โ”‚ โ”œโ”€โ”€ architecture.md # System architecture โ”‚ โ”œโ”€โ”€ api_reference.md # API documentation โ”‚ โ”œโ”€โ”€ user_guide.md # User guide โ”‚ โ”œโ”€โ”€ deployment.md # Deployment guide โ”‚ โ”œโ”€โ”€ troubleshooting.md # Troubleshooting guide โ”‚ โ”œโ”€โ”€ contributing.md # Contribution guidelines โ”‚ โ”œโ”€โ”€ diagrams/ # Architecture diagrams โ”‚ โ””โ”€โ”€ examples/ # Code examples โ”‚ โ”œโ”€โ”€ deployment/ # Deployment configuration โ”‚ โ”œโ”€โ”€ Dockerfile # Docker container โ”‚ โ”œโ”€โ”€ docker-compose.yml # Multi-container setup โ”‚ โ”œโ”€โ”€ .dockerignore # Docker ignore patterns โ”‚ โ”œโ”€โ”€ kubernetes/ # Kubernetes manifests โ”‚ โ”‚ โ”œโ”€โ”€ deployment.yaml โ”‚ โ”‚ โ”œโ”€โ”€ service.yaml โ”‚ โ”‚ โ””โ”€โ”€ configmap.yaml โ”‚ โ”œโ”€โ”€ systemd/ # Systemd service files โ”‚ โ”‚ โ””โ”€โ”€ ict-trading.service โ”‚ โ””โ”€โ”€ supervisor/ # Supervisor configuration โ”‚ โ””โ”€โ”€ ict-trading.conf โ”‚ โ”œโ”€โ”€ monitoring/ # Monitoring configuration โ”‚ โ”œโ”€โ”€ prometheus.yml # Prometheus config โ”‚ โ”œโ”€โ”€ grafana_dashboards/ # Grafana dashboards โ”‚ โ””โ”€โ”€ alerts.yml # Alert rules โ”‚ โ””โ”€โ”€ backups/ # Backup directory โ”œโ”€โ”€ database/ # Database backups โ”œโ”€โ”€ models/ # Model backups โ””โ”€โ”€ config/ # Configuration backups

Key File Descriptions

๐Ÿ“ Logging System (src/logging/)

Purpose: Comprehensive logging infrastructure for debugging, monitoring, and auditing

  • logger.py: Central logger setup - creates module-specific loggers with configured handlers and formatters
  • formatters.py: JSON formatter for machine parsing, colored console formatter, detailed/compact formatters
  • handlers.py: Rotating file handlers (size/time-based), database handler for critical events, alert handler for CRITICAL logs
  • filters.py: Sensitive data redaction (API keys, passwords), rate limiting for repeated messages
  • decorators.py: @log_execution (entry/exit/timing), @log_exceptions (catch and log errors), @log_performance

โš ๏ธ Error Handling (src/core/exceptions.py)

Custom Exception Hierarchy:

  • ICTTradingException - Base exception with error codes and context data
  • DataError - Data loading/validation failures
  • DetectorError - Pattern detection failures
  • ModelError - ML training/inference errors
  • ConfigurationError - Invalid configuration
  • TradingError - Order execution failures

Every exception is logged with full context and stack trace

๐Ÿ“Š Data Management (data/)

Directory Purpose Retention
data/raw/ Downloaded OHLCV data (Parquet format) 24 months
data/processed/ Cleaned data, detected patterns, features 12 months
data/labels/ User labels (versioned), anchor examples Permanent
data/screenshots/ Chart images for labeling 6 months

๐Ÿค– Model Versioning (models/)

Every model version includes:

  • model.pkl - Trained model file
  • hyperparameters.yaml - All configuration used
  • features.json - Feature list and scaling parameters
  • metrics.json - Performance metrics (accuracy, precision, recall)
  • training_log.txt - Full training session log
  • feature_importance.csv - Which features matter most

Symlink "latest/" always points to production model - easy rollback

๐Ÿ“ˆ Logging Categories (logs/)

Log Type Contents Rotation
application/ Startup, shutdown, config loading Daily or 10MB
detectors/ Pattern detection runs, counts, timing Daily or 10MB
models/ Training, inference, evaluation Per session
trading/ Orders, fills, risk decisions, P&L Never rotate (compliance)
errors/ All exceptions with stack traces Daily or 10MB
audit/ Data access, config changes, deployments Monthly

All logs: 30-day retention, compressed archives for older logs

Best Practices Implementation

๐Ÿ”’ Security

  • All secrets in .env (never committed)
  • Sensitive data filtered from logs automatically
  • Database credentials from environment variables only
  • API keys validated at startup, logged failures
  • All external calls use HTTPS

โšก Performance

  • Async logging (non-blocking for high-volume logs)
  • Parquet format for data (10x faster than CSV)
  • Database indexes on frequently queried columns
  • Connection pooling for database
  • Retry logic with exponential backoff for API calls
  • Performance profiling logs (identify bottlenecks)

๐Ÿงช Testing

  • Unit tests for all detectors, features, models
  • Integration tests for end-to-end pipeline
  • Validation tests ensure model accuracy thresholds met
  • Performance tests benchmark speed and memory
  • Fixtures provide realistic test data
  • Target: 80%+ code coverage

๐Ÿš€ Deployment

  • Docker for reproducible environments
  • docker-compose for multi-container setup
  • Kubernetes manifests for cloud deployment
  • systemd service for Linux servers
  • Health checks and auto-restart
  • Blue-green deployment support

๐Ÿค– AI Agent Implementation Guide

๐Ÿ“‹ Purpose: This guide provides step-by-step instructions for AI agents (like Claude, GPT, etc.) to build the ICT ML Trading System. Each version is a stable checkpoint that can be committed to Git, tested, and rolled back if needed.

๐ŸŽฏ For AI Agents: Code Quality Standards

When implementing ANY file in this project, ALWAYS follow these rules:

  • Type Hints: Add type hints to all function signatures (PEP 484)
  • Docstrings: Write Google-style docstrings for all classes and functions
  • Error Handling: Wrap risky operations in try-except, use custom exceptions from src/core/exceptions.py
  • Logging: Log entry/exit of major functions, all errors, and important state changes using src/logging/logger.py
  • Validation: Validate all inputs (function args, config values, data)
  • Constants: No magic numbers - define constants in src/core/constants.py
  • Configuration: Read parameters from config files, never hardcode
  • Testing: Write at least one test for each public function
  • Comments: Explain WHY, not WHAT (code should be self-explanatory)
  • Dependencies: Minimize external dependencies, document all additions to requirements.txt

๐ŸŒณ Git Branching Strategy

Recommended Branch Model (GitHub Flow - Simple & Effective):

  • main: Production-ready code, always stable
  • develop: Integration branch for completed features
  • feature/VERSION-feature-name: Feature development branches
  • hotfix/issue-description: Emergency fixes

Workflow:

# Start new version
git checkout develop
git checkout -b feature/v0.1.0-project-setup

# Work on version, commit frequently
git add .
git commit -m "feat: add project structure and config files"

# Complete version
git checkout develop
git merge feature/v0.1.0-project-setup
git tag v0.1.0
git push origin develop --tags

# If stable, merge to main
git checkout main
git merge develop
git push origin main

๐Ÿ“ฆ Version Roadmap

Version Milestone Duration Deliverables
v0.1.0 Project Foundation 1-2 days Project structure, configs, logging
v0.2.0 Data Pipeline 2-3 days Data loading, preprocessing, database
v0.3.0 Pattern Detectors 3-5 days FVG, OB, Liquidity detectors
v0.4.0 Feature Engineering 2-3 days Feature extraction pipeline
v0.5.0 Labeling System 2-3 days Labeling interface, quality checks
v0.6.0 ML Models 3-4 days Training pipeline, evaluation
v0.7.0 Backtesting 2-3 days Backtest engine, metrics
v0.8.0 Alert System 1-2 days Telegram bot, notifications
v0.9.0 Paper Trading 2-3 days Live detection, simulated execution
v1.0.0 Production Ready 1-2 days Deployment, monitoring, docs

๐Ÿ”จ Version 0.1.0 - Project Foundation

Branch: feature/v0.1.0-project-setup

โœ… Todo List:

  • โ˜ Create directory structure (all folders as shown above)
  • โ˜ Initialize Git repository: git init
  • โ˜ Create .gitignore file with Python, data, logs, models patterns
  • โ˜ Create requirements.txt with core dependencies
  • โ˜ Create requirements-dev.txt with testing/linting tools
  • โ˜ Create setup.py for package installation
  • โ˜ Create pyproject.toml with tool configurations
  • โ˜ Create Makefile with common commands
  • โ˜ Create README.md with project overview
  • โ˜ Create .env.example with required environment variables

๐Ÿ“ Configuration Files to Create:

  • โ˜ config/config.yaml - Main configuration
  • โ˜ config/logging.yaml - Logging setup (JSON formatter, rotating handlers)
  • โ˜ config/detectors.yaml - Pattern detector parameters (placeholder values)
  • โ˜ config/models.yaml - ML hyperparameters (placeholder values)
  • โ˜ config/trading.yaml - Trading parameters (risk limits, time windows)
  • โ˜ config/alerts.yaml - Alert configuration (Telegram tokens from env)
  • โ˜ config/database.yaml - Database settings

๐Ÿ”ง Core Infrastructure Files:

  • โ˜ src/__init__.py - Package marker
  • โ˜ src/core/__init__.py
  • โ˜ src/core/constants.py - Define TIMEFRAMES, SESSION_TIMES, PATHS
  • โ˜ src/core/enums.py - PatternType, Grade, SetupType, TimeWindow enums
  • โ˜ src/core/exceptions.py - Custom exception hierarchy (7-8 exception classes)
  • โ˜ src/core/base_classes.py - Abstract base classes (BaseDetector, BaseModel, etc.)

๐Ÿ“Š Logging System:

  • โ˜ src/logging/__init__.py
  • โ˜ src/logging/logger.py - get_logger() function, load from logging.yaml
  • โ˜ src/logging/formatters.py - JSONFormatter, ColoredFormatter, DetailedFormatter
  • โ˜ src/logging/handlers.py - RotatingFileHandler, ErrorFileHandler, DatabaseHandler
  • โ˜ src/logging/filters.py - SensitiveDataFilter (redact API keys), RateLimitFilter
  • โ˜ src/logging/decorators.py - @log_execution, @log_exceptions, @log_performance

โš™๏ธ Configuration Management:

  • โ˜ src/config/__init__.py
  • โ˜ src/config/config_loader.py - Load YAML configs, merge with env vars, singleton pattern
  • โ˜ src/config/settings.py - Pydantic dataclasses for type-safe config
  • โ˜ src/config/validators.py - Validate config ranges, file paths, consistency

๐Ÿงช Initial Tests:

  • โ˜ tests/__init__.py
  • โ˜ tests/conftest.py - Pytest fixtures (temp directories, mock configs)
  • โ˜ tests/unit/test_core/test_exceptions.py - Test exception hierarchy
  • โ˜ tests/unit/test_logging/test_logger.py - Test logger initialization
  • โ˜ tests/unit/test_config/test_config_loader.py - Test config loading

๐Ÿ” Validation Steps:

  • โ˜ Run: python -m pytest tests/ - All tests pass
  • โ˜ Run: python -c "from src.logging import get_logger; logger = get_logger('test'); logger.info('Test')"
  • โ˜ Check logs/ directory has app.log file created
  • โ˜ Run: python -c "from src.config import config_loader; config = config_loader.load_config()"
  • โ˜ Verify no import errors, no missing dependencies

๐Ÿ“ฆ Commit Checklist:

  • โ˜ All files have docstrings and type hints
  • โ˜ All tests pass
  • โ˜ No hardcoded secrets in code
  • โ˜ README.md updated with setup instructions
  • โ˜ Git commit: git commit -m "feat(v0.1.0): project foundation with logging and config"
  • โ˜ Git tag: git tag v0.1.0

๐Ÿ”จ Version 0.2.0 - Data Pipeline

Branch: feature/v0.2.0-data-pipeline

Prerequisites:

  • โ˜ v0.1.0 completed and tagged
  • โ˜ Branch from develop: git checkout -b feature/v0.2.0-data-pipeline develop

โœ… Todo List:

๐Ÿ“ฆ Database Setup:

  • โ˜ src/data/__init__.py
  • โ˜ src/data/database.py - SQLAlchemy engine, session management, connection pooling
  • โ˜ src/data/models.py - ORM models (OHLCVData, DetectedPattern, Label, Trade, etc.)
  • โ˜ src/data/repositories.py - Repository classes (OHLCVRepository, PatternRepository)
  • โ˜ scripts/setup_database.py - Create tables, indexes, seed data

๐Ÿ“ฅ Data Loaders:

  • โ˜ src/data/loaders.py - CSVLoader, ParquetLoader, DatabaseLoader classes
  • โ˜ src/data/preprocessors.py - handle_missing_data(), remove_duplicates(), filter_session()
  • โ˜ src/data/validators.py - validate_ohlcv(), check_continuity(), detect_outliers()
  • โ˜ src/data/schemas.py - Pydantic schemas (OHLCVSchema, PatternSchema)

๐Ÿ› ๏ธ Utility Scripts:

  • โ˜ scripts/download_data.py - Download DAX OHLCV data (CLI with argparse)
  • โ˜ scripts/process_data.py - Batch preprocessing (clean, filter 3-4am, save)

๐Ÿ“ Data Directory Structure:

  • โ˜ Create data/raw/ohlcv/1min/ (with .gitkeep)
  • โ˜ Create data/raw/ohlcv/5min/ (with .gitkeep)
  • โ˜ Create data/raw/ohlcv/15min/ (with .gitkeep)
  • โ˜ Create data/processed/features/ (with .gitkeep)
  • โ˜ Create data/processed/patterns/ (with .gitkeep)
  • โ˜ Create data/labels/individual_patterns/ (with .gitkeep)

๐Ÿงช Tests:

  • โ˜ tests/unit/test_data/test_database.py - Test connection, session management
  • โ˜ tests/unit/test_data/test_loaders.py - Test loading from various sources
  • โ˜ tests/unit/test_data/test_preprocessors.py - Test data cleaning functions
  • โ˜ tests/unit/test_data/test_validators.py - Test validation logic
  • โ˜ tests/integration/test_database.py - Test full database workflow
  • โ˜ tests/fixtures/sample_data/ - Add sample OHLCV CSV for testing

๐Ÿ” Validation Steps:

  • โ˜ Run: python scripts/setup_database.py - Database created
  • โ˜ Run: python scripts/download_data.py --symbol DAX --start 2024-01-01 --end 2024-01-31 --output data/raw/ohlcv/1min/
  • โ˜ Verify data file created in data/raw/
  • โ˜ Run: python scripts/process_data.py --input data/raw/ --output data/processed/
  • โ˜ Verify processed data created
  • โ˜ All tests pass: pytest tests/

๐Ÿ“ฆ Commit Checklist:

  • โ˜ All repository methods have proper error handling and logging
  • โ˜ Database connection uses environment variables
  • โ˜ All SQL queries use parameterized statements (no SQL injection)
  • โ˜ Data validation catches common issues (nulls, duplicates, outliers)
  • โ˜ Git commit: git commit -m "feat(v0.2.0): data pipeline with loaders and database"
  • โ˜ Merge to develop, tag: git tag v0.2.0

๐Ÿ”จ Version 0.3.0 - Pattern Detectors

Branch: feature/v0.3.0-pattern-detectors

Prerequisites:

  • โ˜ v0.2.0 completed and tagged
  • โ˜ Sample OHLCV data available in data/processed/

โœ… Todo List:

๐Ÿ” Detector Implementation:

  • โ˜ src/detectors/__init__.py
  • โ˜ src/detectors/base_detector.py - Abstract BaseDetector class with detect() method
  • โ˜ src/detectors/fvg_detector.py - FVGDetector class (bullish/bearish gap detection)
  • โ˜ src/detectors/order_block_detector.py - OrderBlockDetector (find BOS, last opposite candle)
  • โ˜ src/detectors/liquidity_detector.py - LiquidityDetector (swing sweeps, reversals)
  • โ˜ src/detectors/premium_discount.py - PremiumDiscountCalculator (equilibrium levels)
  • โ˜ src/detectors/structure_detector.py - StructureDetector (BOS, CHoCH, trend)
  • โ˜ src/detectors/utils.py - Helper functions (find_swing_high, find_swing_low, calculate_atr)
  • โ˜ src/detectors/scanner.py - Scanner class orchestrating all detectors

๐Ÿ“Š Visualization:

  • โ˜ src/visualization/__init__.py
  • โ˜ src/visualization/chart_generator.py - Generate charts with matplotlib/plotly
  • โ˜ src/visualization/pattern_plotter.py - Annotate FVG zones, OB levels on charts
  • โ˜ src/visualization/screenshot.py - Capture chart screenshots for labeling

๐Ÿ› ๏ธ Scripts:

  • โ˜ scripts/run_detection.py - CLI to run detectors on historical data
  • โ˜ Add --detector flag (fvg, ob, liquidity, all)
  • โ˜ Add --visualize flag to generate screenshots
  • โ˜ Save detections to database and data/processed/patterns/

๐Ÿงช Tests:

  • โ˜ tests/unit/test_detectors/test_fvg_detector.py - Test FVG detection logic
  • โ˜ tests/unit/test_detectors/test_order_block_detector.py - Test OB detection
  • โ˜ tests/unit/test_detectors/test_liquidity_detector.py - Test liquidity sweeps
  • โ˜ tests/unit/test_detectors/test_scanner.py - Test scanner orchestration
  • โ˜ tests/fixtures/sample_data/patterns/ - Known patterns for validation

๐Ÿ” Validation Steps:

  • โ˜ Run: python scripts/run_detection.py --input data/processed/ --detector fvg
  • โ˜ Check logs/detectors/fvg_detector.log for detection counts
  • โ˜ Verify detections saved to database and data/processed/patterns/
  • โ˜ Run with --visualize flag, check screenshots in data/screenshots/
  • โ˜ Manually review 10-20 screenshots - are detections correct?
  • โ˜ All tests pass: pytest tests/

๐Ÿ“ฆ Commit Checklist:

  • โ˜ Each detector logs entry, parameters, detection count, execution time
  • โ˜ Detectors handle edge cases (insufficient data, no patterns found)
  • โ˜ Scanner catches detector exceptions, continues with other detectors
  • โ˜ Detection metadata includes all context (price levels, timestamp, features)
  • โ˜ Git commit: git commit -m "feat(v0.3.0): pattern detectors with FVG, OB, liquidity"
  • โ˜ Merge to develop, tag: git tag v0.3.0

๐Ÿ”จ Version 0.4.0 - Feature Engineering

Branch: feature/v0.4.0-feature-engineering

โœ… Todo List:

๐ŸŽฏ Feature Extractors:

  • โ˜ src/features/__init__.py
  • โ˜ src/features/base_features.py - BaseFeatureEngineering abstract class
  • โ˜ src/features/pattern_features.py - Extract FVG size, OB range, liquidity sweep distance
  • โ˜ src/features/technical_features.py - ATR, momentum, volume metrics
  • โ˜ src/features/temporal_features.py - Time since open, day of week, session phase
  • โ˜ src/features/context_features.py - HTF alignment, premium/discount position
  • โ˜ src/features/orderflow_features.py - CVD, delta (if available)
  • โ˜ src/features/feature_store.py - Save/load computed features (Parquet)

๐Ÿงช Tests:

  • โ˜ tests/unit/test_features/ - Test each feature extractor
  • โ˜ Verify feature ranges (no NaNs, no infinities)
  • โ˜ Test feature reproducibility (same input โ†’ same output)

๐Ÿ” Validation Steps:

  • โ˜ Run feature extraction on sample patterns
  • โ˜ Verify feature values are reasonable (no extreme outliers)
  • โ˜ Check feature correlation matrix (detect redundant features)
  • โ˜ Save features to data/processed/features/

๐Ÿ“ฆ Commit & Tag v0.4.0

๐Ÿ”จ Version 0.5.0 - Labeling System

Branch: feature/v0.5.0-labeling-system

โœ… Todo List:

๐Ÿท๏ธ Labeling Components:

  • โ˜ src/labeling/__init__.py
  • โ˜ src/labeling/interface.py - Orchestrator for labeling workflow
  • โ˜ src/labeling/notion_integration.py - Notion API client (optional)
  • โ˜ src/labeling/web_ui.py - Flask/FastAPI web interface (optional)
  • โ˜ src/labeling/quality_checker.py - Inter-session consistency, drift detection
  • โ˜ src/labeling/anchors.py - Manage anchor examples for calibration
  • โ˜ src/labeling/export.py - Export labels to training format

๐Ÿ› ๏ธ Scripts:

  • โ˜ scripts/export_labels.py - Export from Notion or web UI to CSV/database

๐Ÿ“Š Grading Rubrics:

  • โ˜ docs/grading_rubric.md - Document FVG, OB, Liquidity grading criteria (1-5 scale)
  • โ˜ Create 20-30 anchor examples per pattern type
  • โ˜ Save anchors in data/labels/anchors/

๐Ÿ” Validation Steps:

  • โ˜ Test labeling workflow end-to-end
  • โ˜ Label 50 patterns, check quality metrics
  • โ˜ Re-label 10 anchors after 1 day - check consistency

๐Ÿ“ฆ Commit & Tag v0.5.0

๐Ÿ”จ Version 0.6.0 - ML Models

Branch: feature/v0.6.0-ml-models

โœ… Todo List:

๐Ÿค– Model Components:

  • โ˜ src/models/__init__.py
  • โ˜ src/models/base_model.py - Abstract BaseModel with train(), predict(), evaluate()
  • โ˜ src/models/pattern_grader.py - RandomForest/XGBoost for individual patterns
  • โ˜ src/models/setup_classifier.py - Meta-model for complete setups
  • โ˜ src/models/training.py - Training pipeline (load labels, extract features, train, save)
  • โ˜ src/models/evaluation.py - Calculate metrics (accuracy, precision, recall, F1)
  • โ˜ src/models/tuning.py - Hyperparameter search (GridSearchCV or Optuna)
  • โ˜ src/models/inference.py - Real-time prediction with loaded model
  • โ˜ src/models/registry.py - Track model versions, metadata

๐Ÿ› ๏ธ Scripts:

  • โ˜ scripts/train_models.py - CLI for training (--model-type, --pattern, --tune)
  • โ˜ scripts/evaluate_models.py - Generate evaluation reports

๐Ÿ“ Model Storage:

  • โ˜ Save trained models to models/pattern_graders/fvg/v1.0.0/
  • โ˜ Include model.pkl, hyperparameters.yaml, features.json, metrics.json
  • โ˜ Create models/metadata/model_registry.json
  • โ˜ Create symlink models/pattern_graders/fvg/latest/ โ†’ v1.0.0/

๐Ÿงช Tests:

  • โ˜ tests/unit/test_models/ - Test training, prediction, evaluation
  • โ˜ tests/validation/test_model_accuracy.py - Assert accuracy >= 75%

๐Ÿ” Validation Steps:

  • โ˜ Train on 300 labeled patterns
  • โ˜ Evaluate on held-out test set
  • โ˜ Check train/test gap < 10%
  • โ˜ Generate confusion matrix, feature importance

๐Ÿ“ฆ Commit & Tag v0.6.0

๐Ÿ”จ Version 0.7.0 - Backtesting

Branch: feature/v0.7.0-backtesting

โœ… Todo List:

๐Ÿ“ˆ Backtesting Components:

  • โ˜ src/backtesting/__init__.py
  • โ˜ src/backtesting/engine.py - Backtest execution loop
  • โ˜ src/backtesting/metrics.py - Win rate, Sharpe, max drawdown, expectancy
  • โ˜ src/backtesting/reports.py - HTML/PDF report generation
  • โ˜ src/backtesting/visualizations.py - Equity curve, drawdown chart

๐Ÿ› ๏ธ Scripts:

  • โ˜ scripts/backtest.py - Run strategy backtest (--strategy, --start, --end, --capital)

๐Ÿ” Validation Steps:

  • โ˜ Backtest continuation strategy on 6 months data
  • โ˜ Generate performance report
  • โ˜ Verify metrics match manual backtest (sanity check)

๐Ÿ“ฆ Commit & Tag v0.7.0

๐Ÿ”จ Version 0.8.0 - Alert System

Branch: feature/v0.8.0-alerts

โœ… Todo List:

๐Ÿ”” Alert Components:

  • โ˜ src/alerts/__init__.py
  • โ˜ src/alerts/base_alert.py - Abstract BaseAlertHandler
  • โ˜ src/alerts/telegram_bot.py - Telegram bot with python-telegram-bot
  • โ˜ src/alerts/slack_integration.py - Slack webhook integration (optional)
  • โ˜ src/alerts/email_alerts.py - Email via SMTP (optional)
  • โ˜ src/alerts/alert_manager.py - Route alerts to appropriate channels
  • โ˜ src/alerts/templates.py - Message templates with pattern details

๐Ÿ” Validation Steps:

  • โ˜ Send test alert to Telegram
  • โ˜ Verify message formatting, pattern details included
  • โ˜ Test alert rate limiting (no spam)

๐Ÿ“ฆ Commit & Tag v0.8.0

๐Ÿ”จ Version 0.9.0 - Paper Trading

Branch: feature/v0.9.0-paper-trading

โœ… Todo List:

๐Ÿ’ผ Trading Components:

  • โ˜ src/trading/__init__.py
  • โ˜ src/trading/broker_interface.py - Abstract broker API (paper trading mode)
  • โ˜ src/trading/order_manager.py - Order submission, tracking
  • โ˜ src/trading/risk_manager.py - Position sizing, max loss checks
  • โ˜ src/trading/portfolio.py - Track positions, P&L
  • โ˜ src/trading/execution_engine.py - Live detection โ†’ prediction โ†’ order execution
  • โ˜ src/trading/validators.py - Pre-trade validation (risk checks)

๐Ÿ› ๏ธ Scripts:

  • โ˜ scripts/live_trading.py - Run live (paper) trading session
  • โ˜ Add --dry-run flag for simulation
  • โ˜ Add --auto-grade flag (automate only grade 5 predictions)

๐Ÿ” Validation Steps:

  • โ˜ Run paper trading for 1 week (5 sessions)
  • โ˜ Manually validate each alert before execution
  • โ˜ Track model grade vs. your judgment (correlation)
  • โ˜ Log all decisions to logs/trading/orders.log

๐Ÿ“ฆ Commit & Tag v0.9.0

๐Ÿ”จ Version 1.0.0 - Production Ready

Branch: feature/v1.0.0-production

โœ… Todo List:

๐Ÿš€ Production Readiness:

  • โ˜ deployment/Dockerfile - Create production Docker image
  • โ˜ deployment/docker-compose.yml - Multi-container setup (app + database + monitoring)
  • โ˜ deployment/systemd/ict-trading.service - Systemd service file
  • โ˜ monitoring/prometheus.yml - Prometheus metrics collection
  • โ˜ monitoring/grafana_dashboards/ - Create dashboards for key metrics
  • โ˜ src/monitoring/metrics_collector.py - Expose Prometheus metrics
  • โ˜ src/monitoring/health_checker.py - Health check endpoint

๐Ÿ“š Documentation:

  • โ˜ docs/architecture.md - Complete system architecture
  • โ˜ docs/api_reference.md - Generate from docstrings (Sphinx)
  • โ˜ docs/user_guide.md - Setup, configuration, usage
  • โ˜ docs/deployment.md - Deployment instructions
  • โ˜ docs/troubleshooting.md - Common issues and solutions
  • โ˜ README.md - Update with badges, quick start, features

๐Ÿงช Final Testing:

  • โ˜ Run full test suite: pytest tests/ --cov=src --cov-report=html
  • โ˜ Verify code coverage >= 80%
  • โ˜ Run linting: flake8 src/
  • โ˜ Run type checking: mypy src/
  • โ˜ Test Docker build: docker build -t ict-trading .
  • โ˜ Test deployment in staging environment

๐Ÿ”’ Security Audit:

  • โ˜ Verify no secrets in code (use .env only)
  • โ˜ Check all API keys are redacted in logs
  • โ˜ Verify database uses parameterized queries
  • โ˜ Run security scan: bandit -r src/

๐Ÿ“ฆ Release Checklist:

  • โ˜ Update CHANGELOG.md with all changes
  • โ˜ Update version in setup.py to 1.0.0
  • โ˜ Merge to main branch
  • โ˜ Git tag: git tag v1.0.0 -m "Release version 1.0.0"
  • โ˜ Push tags: git push origin main --tags
  • โ˜ Create GitHub release with notes

๐Ÿ”„ Post-Release: Continuous Improvement

Ongoing Maintenance Versions

v1.1.0 - Performance Optimization:

  • Profile code with cProfile, identify bottlenecks
  • Optimize hot loops with Numba JIT compilation
  • Add caching for expensive computations
  • Database query optimization (indexes, query plans)

v1.2.0 - Enhanced Features:

  • Add more order flow features (if ATAS API available)
  • Implement model retraining pipeline (monthly)
  • Add regime detection features
  • Enhance visualization dashboard

v1.3.0 - Advanced ML:

  • Experiment with XGBoost/LightGBM vs. RandomForest
  • Implement ensemble models
  • Add SHAP explainability
  • Hyperparameter optimization with Optuna

v2.0.0 - Multi-Instrument Support:

  • Extend to trade multiple instruments (NQ, ES)
  • Shared feature engineering pipeline
  • Instrument-specific models
  • Portfolio-level risk management

โš ๏ธ Troubleshooting Guide for AI Agents

Common Issues & Solutions

โŒ Tests Failing:

  • Issue: Import errors
  • Solution: Ensure all __init__.py files exist, check PYTHONPATH
  • Issue: Database connection errors
  • Solution: Check .env file has correct DATABASE_URL, test connection manually

โŒ Logging Not Working:

  • Issue: No logs appearing
  • Solution: Check logging.yaml loaded correctly, verify logs/ directory exists with write permissions

โŒ Pattern Detection Produces No Results:

  • Issue: Detectors find 0 patterns
  • Solution: Check data date range (3-4 AM only?), verify detection thresholds not too strict, add debug logging

โŒ Model Training Fails:

  • Issue: Insufficient labeled data
  • Solution: Need minimum 200-300 labels per pattern type, verify labels exported correctly
  • Issue: Feature extraction errors
  • Solution: Check for NaN values, validate feature ranges, log feature statistics

๐Ÿ’ก Best Practice: Always Check Logs First

Every component logs extensively. Before debugging code, check:

  • logs/application/app.log - General flow
  • logs/errors/exceptions.log - Errors with stack traces
  • logs/[component]/*.log - Component-specific logs

๐Ÿ“ AI Agent Final Checklist

Before marking any version complete, verify:
  • โœ… All files have proper docstrings (Google style)
  • โœ… All functions have type hints
  • โœ… All risky operations wrapped in try-except
  • โœ… All errors logged with context
  • โœ… All tests pass: pytest tests/
  • โœ… No hardcoded secrets (use .env)
  • โœ… No TODO comments left in code
  • โœ… Git commit messages follow format: type(scope): description
  • โœ… Version tagged: git tag vX.Y.Z
  • โœ… Merged to develop branch