How boscaleb/ai-trading-bot works
This repository implements an automated trading desk with a browser dashboard, scheduled trading and reporting endpoints, strategy evaluation, broker execution, risk controls, and backtesting. The principal workflow runs a timeframe-specific cron request through the trading engine, which evaluates market data and risk rules before submitting broker orders. The dashboard separately requests a snapshot assembled from broker state and market evaluations, then presents account, market, order, equity, and risk views. The README is empty; some route and UI relationships are supported only by the source index, so those links are marked unverified where appropriate.
Main entry points: trading/engine.ts Trade cycle · snapshot.ts Desk snapshot · route.ts Report endpoint · backtest/engine.ts Backtest engine
Components 30
API and dashboard
- Trade endpoint
app/api/cron/trade/[timeframe]/route.ts - Report endpoint
app/api/cron/report/[type]/route.ts - Dashboard API
app/api/dashboard/route.ts - Reports API
app/api/reports/route.ts - Trading dashboard
components/dashboard/dashboard.tsx - Dashboard panels
components/dashboard - UI button
components/ui/button.tsx - Dashboard access
lib/dashboard-auth.ts - Cron authorization
lib/cron-auth.ts - Display formatting
lib/format.ts
Trading runtime
- Desk snapshot
lib/trading/snapshot.ts - Trade cycle
lib/trading/engine.ts - Strategy dispatch
lib/trading/strategies/index.ts - Trading strategies
lib/trading/strategies - Market indicators
lib/trading/indicators.ts - Market configuration
lib/trading/markets.ts - Risk and sizing
lib/trading/risk.ts - Stop protection
lib/trading/protection.ts - Trading data types
lib/trading/types.ts
Reports and backtests
- Analyst reports
lib/reports/analyst.ts - Backtest engine
lib/backtest/engine.ts - Market history
lib/backtest/history.ts - Backtest metrics
lib/backtest/metrics.ts
External services
- Broker adapter
lib/broker/alpaca.ts - Alpaca
- SMS notification
lib/notify/sms.ts - SMS provider
- Text generation service
Other components
- Cron scheduler
- Trading user
Connections 34
- Cron scheduler → Trade endpoint: triggers
- Cron scheduler → Report endpoint: triggers
- Trade endpoint → Cron authorization: checks access
app/api/cron/trade/[timeframe]/route.ts - Trade endpoint → Trade cycle: runs cycle
app/api/cron/trade/[timeframe]/route.ts - Report endpoint → Cron authorization: checks access
app/api/cron/report/[type]/route.ts - Report endpoint → Desk snapshot: requests state
app/api/cron/report/[type]/route.ts - Report endpoint → Analyst reports: generates report
app/api/cron/report/[type]/route.ts - Dashboard API → Desk snapshot: builds state
app/api/dashboard/route.ts - Reports API → Desk snapshot: requests state
app/api/reports/route.ts - Reports API → Analyst reports: generates report
app/api/reports/route.ts - Trading user → Trading dashboard: views desk
- Trading dashboard → Dashboard API: requests snapshot
- Trading dashboard → Dashboard panels: renders
components/dashboard/dashboard.tsx - Dashboard panels → UI button: uses controls
components/dashboard/reports-panel.tsx - Dashboard panels → Display formatting: formats values
components/dashboard/market-card.tsx - Dashboard access → Trading dashboard: guards access
- Trade cycle → Broker adapter: reads and trades
lib/trading/engine.ts - Trade cycle → Strategy dispatch: evaluates signals
lib/trading/engine.ts - Trade cycle → Risk and sizing: filters and sizes
lib/trading/engine.ts - Trade cycle → Stop protection: checks stops
lib/trading/engine.ts - Strategy dispatch → Trading strategies: dispatches
lib/trading/strategies/index.ts - Trading strategies → Market indicators: uses indicators
lib/trading/strategies/mean-reversion.ts - Desk snapshot → Broker adapter: reads account data
lib/trading/snapshot.ts - Desk snapshot → Trade cycle: evaluates markets
lib/trading/snapshot.ts - Desk snapshot → Risk and sizing: computes exposure
lib/trading/snapshot.ts - Broker adapter → Market configuration: uses market config
lib/broker/alpaca.ts - Broker adapter → Alpaca: requests data and orders
- Report endpoint → SMS notification: sends notification
app/api/cron/report/[type]/route.ts - SMS notification → SMS provider: delivers message
- Analyst reports → Text generation service: generates text
lib/reports/analyst.ts - Backtest engine → Market history: uses bars
- Backtest engine → Strategy dispatch: replays strategy
lib/backtest/engine.ts - Backtest engine → Risk and sizing: sizes positions
lib/backtest/engine.ts - Backtest engine → Backtest metrics: computes results
lib/backtest/engine.ts