Autonomous AI-powered trading system using xAI's Grok model for market analysis and order execution via Interactive Brokers.
- AI-Powered Analysis: Grok model analyzes market conditions and makes trading decisions
- Real-time Dashboard: Monitor portfolio value, positions, and P&L
- Interactive Brokers Integration: Execute trades directly through IBKR
- Automated Trading Loop: Configurable intervals with manual/auto modes
- Self-Reflection System: AI reviews past trades and adjusts strategy
| Technology | Purpose |
|---|---|
| Next.js 14 | React framework with App Router |
| TypeScript | Type-safe development |
| Tailwind CSS | Utility-first styling |
| Recharts | Interactive charts |
| Zustand | State management |
| React Query | Server state & caching |
| Technology | Purpose |
|---|---|
| FastAPI | Async Python API |
| ib_insync | Interactive Brokers SDK |
| xAI Grok | AI analysis engine |
| Pydantic | Data validation |
| SQLite | Local persistence |
| APScheduler | Automated trading loop |
| Technology | Purpose |
|---|---|
| Docker | Containerization |
| Caddy | Reverse proxy with auto-SSL |
- Node.js 18+
- Python 3.11+
- Interactive Brokers Gateway/TWS
- xAI API key
git clone https://github.com/nolancacheux/AI-Agent-Grok-Trading-System.git
cd AI-Agent-Grok-Trading-System
# Backend
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# Frontend
cd ../frontend
npm installcp .env.example .envEdit .env with your credentials:
XAI_API_KEY=your_xai_api_key
IBKR_HOST=127.0.0.1
IBKR_PORT=4002
IBKR_CLIENT_ID=1
IBKR_ACCOUNT=your_account_id# Terminal 1: Backend
cd backend
python -m uvicorn src.api.main:app --reload --port 8000
# Terminal 2: Frontend
cd frontend
npm run dev| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Service health + IBKR connection |
/api/agent/status |
GET | Agent state, positions, P&L |
/api/agent/trades |
GET | Trade history |
/api/agent/decisions |
GET | All decisions (BUY/SELL/KEEP) |
/api/agent/analyze |
POST | Trigger AI analysis |
/api/portfolio |
GET | Full portfolio state |
/api/trade |
POST | Execute trade order |
# Docker
docker compose -f docker-compose.prod.yml up -d- Never commit
.envfiles - Use paper trading for testing
- Enable 2FA on Interactive Brokers
- Rotate API keys regularly
MIT License
This software is for educational purposes only. Trading involves substantial risk of loss. Use at your own risk.
Built by Nolan Cacheux


