Overview
AI Trading Systems Engineering Prototype explores how an LLM-based agent can collect market context, call typed tools, explain a decision, and interact with a broker API. The system has live order-execution capability through Interactive Brokers and includes a dashboard for monitoring positions, decisions, and portfolio state. This is an experimental engineering project, not a claim that an LLM can trade safely or profitably. Model outputs are fallible, market data can be delayed or incomplete, and automated actions can cause financial loss.Risk Controls and Human Oversight
- Manual and automated modes are separated in the interface
- Broker, API, scheduler, and market status are visible before action
- Stop-loss and take-profit tools exist for explicit risk boundaries
- Decisions, tool calls, and reflections are persisted for review
- A human operator remains responsible for credentials, permissions, capital limits, and whether execution is enabled
- Production use would require stronger pre-trade limits, idempotency, kill switches, reconciliation, independent monitoring, and regulatory review
Key Features
| Feature | Description |
|---|---|
| AI-Assisted Analysis | Grok analyzes available market context and proposes a decision with reasoning |
| Real-time Dashboard | Monitor portfolio value, positions, and P&L with interactive charts |
| Automated Trading Loop | Configurable intervals (30 min) with manual/auto modes |
| Decision Review | The agent records reflections on past decisions for operator review |
| Interactive Brokers | Direct integration for live order execution |
Technical Architecture
Frontend
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling with dark/light themes
- Recharts - Interactive portfolio charts
- Zustand - State management with persistence
- React Query - Server state and caching
- WebSocket - Real-time updates
Backend
- FastAPI - High-performance async Python API
- ib_insync - Interactive Brokers SDK for order execution
- xAI Grok API - AI analysis engine with tool calling
- SQLite - Local persistence for trades, decisions, reflections
- APScheduler - Automated trading loop
- Pydantic - Data validation
AI Agent Features
The Grok agent has access to 12 trading tools:| Tool | Purpose |
|---|---|
| get_stock_price_history | Historical OHLCV data |
| get_stock_info | Company fundamentals |
| trade_stock | Execute buy/sell/close orders |
| get_portfolio_state | Current positions and P&L |
| search_news | News and catalyst search |
| set_stop_loss / set_take_profit | Risk management orders |
Infrastructure
- Docker - Containerized deployment
- Caddy - Reverse proxy with auto-SSL
- Yahoo Finance - Fallback market data source
Dashboard Features
Portfolio Monitoring
- Real-time portfolio value with interactive chart (1H/24H/7D/ALL views)
- Dollar and percentage P&L display
- Paris and New York timezone clocks
Trading Controls
- Manual/Auto trading mode toggle
- Trigger Analysis button for on-demand AI analysis
- Status indicators (IBKR, API, Scheduler, Market)
Analysis Panel
- All AI decisions with reasoning (BUY/SELL/KEEP)
- Chat history with Grok
- Auto-reflections with lessons learned
Technologies Summary
| Category | Technologies |
|---|---|
| Frontend | Next.js 14, TypeScript, Tailwind CSS, Recharts, Zustand, React Query |
| Backend | Python 3.11, FastAPI, ib_insync, SQLite, APScheduler |
| AI | xAI Grok API, Tool Calling, Self-Reflection |
| Infrastructure | Docker, Caddy, WebSocket |
| Data | Yahoo Finance, Interactive Brokers API |
