How markdregan/freqai-marcos-lopez-de-prado works
Project Type & Purpose
• This is a modular, backend-focused trading engine built on Freqtrade with an ML/“Litmus” extension (FreqAI).
• It provides a CLI and RPC/Web UI for downloading market data, backtesting, hyperparameter optimization, live trading via exchange adapters, and ML‐powered strategies.
High-Level Architectural Components
a. Presentation Layer
• CLI (freqtrade/main.py + commands/*)
• RPC/API server (freqtrade/rpc/api_server/*) exposing REST & WebSocket endpoints
• Web UI (embedded static files under rpc/api_server/ui)
• Notification adapters (Telegram, Discord, Webhook)
b. Application/Core Engine
• Core trading loop (freqtrade/worker.py, freqtrade/freqtradebot.py)
• Command dispatch/resolvers (freqtrade/resolvers/*)
• Configuration loader & validator (freqtrade/configuration/*)
• Strategy/plugin manager (freqtrade/strategy/*, plugins/pairlist, plugins/protections)
c. Domain/Business Logic
• Exchange adapters (freqtrade/exchange/*) for live/pre–live REST & WS market data & order execution
• Data handlers & backtesting modules (freqtrade/data/*, freqtrade/optimize/backtesting.py)
• ML components (“Litmus” & FreqAI) for feature engineering, model training, inference (freqtrade/litmus/* + freqtrade/freqai/*)
• Hyperopt engine (freqtrade/optimize/hyperopt*)
d. Infrastructure Layer
• Persistence and state (SQLite/SQLAlchemy models under freqtrade/persistence/*)
• Logging (freqtrade/loggers/*)
• Key-value store & caches (freqtrade/persistence/key_value_store.py, freqtrade/util/periodic_cache.py)
• Docker environment & orchestration (Dockerfile, docker-compose.yml, .devcontainer/*)
Interactions & Data-Flow
1. User invokes CLI command → Core Engine
2. Core loads & validates config → Instantiates resolvers → Selects strategy/plugins
3. Core fetches market data via Exchange Adapter → Feeds data to Strategy & Data Handlers
4. Strategy generates signals → Execution via Exchange Adapter
5. Orders, trades, metrics persist to DB / key-value store → Logging subsystem
6. RPC/API server exposes state & metrics → Client UIs (web browser, external scripts)
7. ML workflows (FreqAI/Litmus) integrate in backtesting & live loops for prediction
Key Architectural Patterns & Principles
• Plugin/Extension Pattern: strategies, pairlists, protections, resolvers load dynamically
• Layered Separation: Presentation → Application → Domain → Infrastructure
• Dependency Injection via Resolver interfaces
• Modular packaging by feature (commands, exchange, data, optimize, persistence, rpc, strategy)
• Configuration-first approach (JSON/YAML config + env vars)
• Clear component labels matching directory/package names