Architecture
Crate structure
crates/
├── cli/ # bin crate - the matchstick binary
├── core-types/ # foundation types, no external deps beyond serde/chrono
├── indicators/ # technical analysis calculations
├── orders/ # order lifecycle management
├── risk/ # position sizing and risk limits
├── strategy/ # strategy configuration and metrics
├── watchlist/ # watchlist types + formula DSL (pest)
└── render/ # table rendering (ASCII + JSON)Dependency graph
core-types (standalone)
├── indicators
├── orders
├── risk
├── strategy
watchlist (standalone, contains formula DSL)
└── render
cli (depends on all above + clap + colored + tokio)Library crates depend only on core-types or watchlist. They do not depend on each other (except render -> watchlist). The cli crate assembles everything.
Key types
core-types
| Type | Purpose |
|---|---|
MarketTick | Single price update with bid/ask |
OhlcvBar | Candlestick bar with VWAP |
Position | Open position with P&L tracking |
Timeframe | Bar duration (Tick through Month) |
TradingError | 13 error variants |
indicators
| Type | Purpose |
|---|---|
IndicatorEngine | Calculation engine with 5-minute cache |
IndicatorRequest | What to calculate (type, symbol, period) |
IndicatorResult | Computed values with metadata |
orders
| Type | Purpose |
|---|---|
OrderManager | Multi-order tracking |
Order | Full order with fills and state machine |
OrderFill | Execution details |
risk
| Type | Purpose |
|---|---|
RiskManager | Portfolio-level validation |
PositionSizer | 4 sizing methods |
RiskLimits | Configurable constraints |
strategy
| Type | Purpose |
|---|---|
StrategyManager | Multi-strategy orchestration |
StrategyConfig | Name, symbols, timeframe, capital |
StrategyMetrics | Win rate, Sharpe, drawdown |
watchlist
| Type | Purpose |
|---|---|
Watchlist | Container for symbols and columns |
CustomColumn | Formula-driven computed column |
Expr | Formula AST node |
Design patterns
- Epsilon comparisons: Floating-point safety throughout (1e-8)
- State machines: Order and strategy lifecycle validation
- Builder patterns: OrderRequest, StrategyConfig, RiskLimits
- Capability tokens: OrderRef with UUID-based access control