Overview
AI Trading Agent is an autonomous trading system that leverages xAI's Grok model for intelligent market analysis and decision-making. The system connects to Interactive Brokers for real order execution, featuring a professional dashboard for monitoring portfolio performance in real-time.
Key Features
| Feature | Description |
|---|---|
| AI-Powered Analysis | Grok model analyzes market conditions and makes trading decisions |
| Real-time Dashboard | Monitor portfolio value, positions, and P&L with interactive charts |
| Automated Trading Loop | Configurable intervals (30 min) with manual/auto modes |
| Self-Reflection System | AI reviews past trades and adjusts strategy automatically |
| 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 |
