Class Diagrams
Pair with alphaswarm_docs/erd.md (database schema) and alphaswarm_docs/architecture.md (system view). Doc map: alphaswarm_docs/index.md.
Hand-authored mermaid classDiagram blocks for the five hierarchies AI
coders most often need to navigate. Every diagram cites the canonical
file so you can jump from the diagram into the code in one click.
1. Symbol + core enums
The atom that flows through every data feed, strategy, and broker. Defined in alphaswarm/core/types.py.
Key invariants:
Symbolis hashable + frozen. Round-trip viaSymbol.parse(symbol.format())is the identity.vt_symbolis alwaysf"{ticker}.{exchange}"(vnpy convention).- Concrete instrument shapes (option chains, future contracts) live
alongside
Symbolas additional fields, not separate classes.
2. LLM provider registry
The router from alphaswarm/llm/providers/router.py dispatches every LLM call through LiteLLM. Adding a provider is a single dict entry in alphaswarm/llm/providers/catalog.py.
Conventions:
- Always call via
router_complete(provider=..., model=..., ...). - Tier (
deep/quick) routing happens viasettings.provider_for_tierprovider.default_model(tier).
- The control plane in alphaswarm/runtime/control_plane.py
can override
ollama_host/vllm_base_urlat runtime.
3. Strategy hierarchy
AlphaSwarm follows the Lean 5-stage pattern (Universe → Alpha → Portfolio →
Risk → Execution). Concrete strategies are factory-instantiated from
config via the class/module_path/kwargs registry pattern.
The interfaces are in alphaswarm/core/interfaces.py; concrete alphas in alphaswarm/strategies/ (one file per alpha). See alphaswarm_docs/factor-research.md for the authoring guide.
4. Backtest + paper + live (IBrokerage / IDataQueueHandler)
The same strategy runs unchanged across backtest, paper, and live — the engines differ in how they implement the broker + data-queue contract, not in how they call the strategy.
Files of interest:
- alphaswarm/backtest/engine.py — base engine
- alphaswarm/backtest/vectorbt_engine.py
- alphaswarm/backtest/broker_sim.py — brokerage simulator used by all non-live engines
- alphaswarm/trading/ — concrete
IBrokerageimplementations for paper + live - alphaswarm/streaming/ — Kafka and IBKR feed handlers
See alphaswarm_docs/backtest-engines.md for the full engine matrix, alphaswarm_docs/paper-trading.md for the session lifecycle.
5. Generic ingestion pipeline
Discovery → Director → Materialise → Verify → Annotate. The dataclasses below are the canonical contract between stages.
Files:
- alphaswarm/data/pipelines/discovery.py
- alphaswarm/data/pipelines/director.py
- alphaswarm/data/pipelines/materialize.py
- alphaswarm/data/pipelines/annotate.py
- alphaswarm/data/pipelines/runner.py
- alphaswarm/data/pipelines/extractors.py
Walkthrough lives in alphaswarm_docs/data-catalog.md.
6. Bot entity (TradingBot / ResearchBot)
The Bot Entity Refactor introduced a first-class deployable unit that aggregates universe + strategy + engine + ML + agents + RAG + metrics. The runtime never re-implements those primitives — it composes references and dispatches to the existing entry points.
Files:
- alphaswarm/bots/spec.py
- alphaswarm/bots/base.py
- alphaswarm/bots/trading_bot.py
- alphaswarm/bots/research_bot.py
- alphaswarm/bots/runtime.py
- alphaswarm/bots/deploy.py
- alphaswarm/bots/registry.py
- alphaswarm/bots/cli.py
Walkthrough lives in alphaswarm_docs/bots.md.