Algorithmic trading repository for Alpaca with backtesting, paper/live execution paths, monitoring dashboards, and research/governance tooling.
This repository has multiple runtime entrypoints. The commands below reflect the current supported paths in the codebase, not older historical workflows.
main.py: primary multi-mode CLI forlive,backtest,optimize,replay, andresearchlive_trader.py: single-strategy paper-only runner with risk-profile controls; used by the low-resource launcherrun_adaptive.py: standalone adaptive strategy runner and opportunity scannerweb/app.py: FastAPI monitoring dashboard and JSON APIstart.py: deployment wrapper that launchesweb.appandrun_adaptive.pytogether
Architecture notes live in docs/RUNTIME_ARCHITECTURE.md.
uv sync --group dev --group test
source .venv/bin/activate
cp .env.example .envSet Alpaca credentials in .env or your shell environment:
ALPACA_API_KEY=...
ALPACA_SECRET_KEY=...
PAPER=trueRun the full test suite:
uv run pytestRun only unit tests without coverage:
uv run pytest tests/unit/ --no-covRun a backtest:
uv run python main.py backtest \
--strategy MomentumStrategy \
--symbols AAPL,MSFT \
--start-date 2024-01-01 \
--end-date 2024-12-31Run a validated backtest report:
uv run python scripts/validated_backtest_report.py \
--strategy MomentumStrategy \
--symbols AAPL,MSFT \
--start-date 2014-01-01 \
--end-date 2024-12-31 \
--output results/validated_backtest_report.md \
--json results/validated_backtest_report.jsonStart paper trading with the main runtime:
uv run python main.py live --strategy MomentumStrategy --forcemain.py live now enforces current validation evidence by default. Generate a fresh artifact bundle with scripts/generate_validation_artifacts.py before startup, and for --real also ensure results/validation/precheck/go_live_precheck_summary.json is present and passing. Use --skip-validation only for controlled dry runs.
Start the single-strategy paper trader directly:
uv run python live_trader.py --strategy momentum --symbols AAPL MSFTStart the low-resource profile:
uv run python scripts/run_low_resource_profile.py --dry-run
uv run python scripts/run_low_resource_profile.pyLaunch the interactive quickstart:
uv run python scripts/quickstart.pyRun the FastAPI dashboard locally:
uv run python -m uvicorn web.app:app --host 0.0.0.0 --port 8000Run the terminal dashboard:
uv run python scripts/dashboard.pyEmergency kill switch:
uv run python scripts/kill_switch.py --confirm "HALT TRADING" --cancel-orders --liquidateQUICKSTART.md: current local setup and first-run commandsDOCKER.md: Docker anddocker composeworkflowsdocs/RUNTIME_ARCHITECTURE.md: runtime entrypoints and architectural overlapsdocs/LOW_HARDWARE_PROFILE.md: Raspberry Pi / low-resource deployment guidancedocs/OPERATIONS_RUNBOOK.md: operational procedures and incident handlingdocs/README.md: documentation index with authoritative vs historical guides
engine/: backtesting, evaluation, validation, and replay logicbrokers/: Alpaca/backtest/options broker adaptersstrategies/: strategy implementations and base classesutils/: risk, reconciliation, audit, runtime-state, and ops helpersweb/: FastAPI dashboard and templatesscripts/: runnable utilities and reporting scriptstests/: unit and higher-level testsdocs/: active guides plus historical implementation notesresults/,audit_logs/: generated outputs and runtime artifacts
main.py liveis the primary live/paper operator path;live_trader.pyis a separate paper-only single-strategy runtime.run_adaptive.pyremains a separate execution path and is not integrated intomain.py.web/app.pyis a monitoring surface, not the trading control plane.start.pyis intended for deployment environments, not as the primary local CLI.