This is the English companion of
README.md. It is a full translation; refer to the Chinese version as the primary document.
This project is for quantitative trading learning and research and does not constitute any investment advice.
LeanQuantHub is a localized, multi-user quantitative platform: the frontend follows a QuantConnect-style experience, and the backend uses a Lean Runner task execution model. It supports theme management, data management, backtests, and report archiving.
backend/: FastAPI + MySQL metadata servicefrontend/: React + Vite frontendalgorithms/: Lean algorithm scriptsml/: ML scoring and inference utilitiesconfigs/: Lean config templates and theme weightsdeploy/: systemd services and deployment scripts
- Docs overview:
docs/README.md - Data sources:
docs/data_sources/README.md - Reports:
docs/reports/README.md - TODO lists:
docs/todolists/README.md
Run build/serve commands inside
backend/orfrontend/, not in the repo root.
cd /app/stocklean
cp backend/.env.example backend/.env
# Fill DB_* / LEAN_* / ML_* env vars
python3.11 -m venv .venv
.venv/bin/pip install -r backend/requirements.txt -r ml/requirements.txt
cd backend
../.venv/bin/uvicorn app.main:app --reload --host 0.0.0.0 --port 8021cd frontend
cp .env.example .env
npm install
npm run devDefault frontend: http://localhost:5173
Default backend: http://localhost:8021
cd frontend
npm install
npm run build
# Deploy systemd user services
cp deploy/systemd/*.service ~/.config/systemd/user/
cp deploy/systemd/*.timer ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user restart stocklean-backend stocklean-frontendOptional: override Gateway parameters (port, version, watchdog thresholds) in ~/.config/stocklean/ibgateway.env.
Important: if the machine already runs system-level /etc/systemd/system/ibgateway.service, do not enable user-level stocklean-ibgateway.service; keep only one manager.
Current host convention: use user-level stocklean-ibgateway.service and keep system-level ibgateway.service disabled/inactive.
Gateway management commands (user-level):
systemctl --user restart stocklean-ibgateway.service
systemctl --user status stocklean-ibgateway.service
systemctl --user status stocklean-ibgateway-watchdog.timerstocklean-ibgateway.serviceremains the only Gateway manager. It launches and supervises Gateway through IBC; do not enable a second system-levelibgateway.serviceor another supervisor in parallel.stocklean-ibgateway-watchdog.serviceperforms staged recovery. It no longer relies only on process/port checks; it also uses business-level probes:- whether
positions/open_orders/account_summarysnapshots keep advancing - whether
commands/contains timed-out pending commands - whether
command_results/keeps receiving results - whether the direct
reqPositionsprobe fails repeatedly
- whether
- Current recovery state machine:
healthysnapshot_stalecommand_stuckbridge_degradedgateway_restartinggateway_degradedrecovering
- Recovery ladder:
- Force Lean Bridge refresh
- Restart Lean Bridge leader
- Run
systemctl --user restart stocklean-ibgateway.service - If recovery still fails, enter
gateway_degradedand block new executions and new orders
- While in
gateway_restarting/gateway_degraded, the frontend keeps showing the last trusted positions and clearly marks the page as recovering/degraded.
Common troubleshooting commands:
systemctl --user status stocklean-ibgateway.service --no-pager
systemctl --user status stocklean-ibgateway-watchdog.timer --no-pager
journalctl --user -u stocklean-ibgateway-watchdog.service -n 100 --no-pager
journalctl --user -u stocklean-ibgateway.service -n 100 --no-pagerDefault frontend: http://:8081
Default backend: http://:8021
Set in backend .env:
LEAN_LAUNCHER_PATH: Lean Launcher csprojLEAN_CONFIG_TEMPLATE: Lean config template JSONLEAN_ALGORITHM_PATH: algorithm script pathLEAN_DATA_FOLDER: Lean data directoryLEAN_PYTHON_VENV: unified Python 3.11 venv (recommended/app/stocklean/.venv)PYTHON_DLL: Python 3.11libpythonpath (recommended/app/stocklean/.venv/lib/libpython3.11.so)DOTNET_PATH/DOTNET_ROOT
Backtests use data_root/universe/alpha_symbol_life.csv for IPO/delist dates. If Alpha’s delistingDate conflicts with price history, an override file can be used:
- Default path:
data_root/universe/symbol_life_override.csv - Format:
symbol,ipoDate,delistingDate,source,note - Priority:
symbol_life_override.csv>alpha_symbol_life.csv - Custom path via
symbol_life_override_path
- Directory:
docs/data_sources/ - Implemented: Alpha Vantage (
docs/data_sources/alpha.md)
- Directory:
docs/todolists/ - Naming:
<Topic>TODO.md/<Topic>TestTODO.md - No TODO files in repo root
- Index:
docs/todolists/README.md
- Backtest reports:
docs/reports/backtests/ - ML training comparisons:
docs/reports/ml/
- Lean and ML use Python 3.11 (Python.NET compatible)
- Set in
.env:ML_PYTHON_PATH=/app/stocklean/.venv/bin/python
- Do not commit
.env, data directories, logs, or build artifacts - Use
.env.exampleas template; never expose secrets or internal addresses