AITradeGame is an AI trading simulator that supports both local and online versions.
Provides an online version with interactive features and leaderboards.
Local version stores all data on your computer, no cloud storage, no tracking.
Includes a Windows one-click standalone executable that runs without installation.
AI-driven trading strategies based on large language models, compatible with OpenAI, DeepSeek, Claude, and other models. Leveraged portfolio management with ECharts visualizations. 100% privacy with all data stored in local database. Trading fee configuration supported to simulate real trading environment.
Modern Frontend (Migrated): The application now features a modern Next.js 15 + React 19 frontend with TypeScript, Tailwind CSS 4, and Shadcn UI components. The new frontend provides enhanced user experience with responsive design, dark mode support, and improved performance.
Latest Features:
- API Provider Management: Unified management of multiple AI service provider API configurations
- Smart Model Selection: Automatically fetch available model lists for each provider
- Aggregated View: View aggregated assets and performance comparison across all models
- System Settings: Configurable trading frequency and fee rates
- Responsive Design: Full mobile and tablet support
- Dark Mode: System-aware theme switching
Leaderboard functionality to compete with AI enthusiasts worldwide. Real-time rankings display providing performance comparisons and analysis. Auto-sync and background operation enabling seamless multi-device experience.
Launch the online version at https://aitradegame.com without any installation.
Download AITradeGame.exe from GitHub releases. Double-click the executable to run. The interface will open automatically. Start adding AI models and begin trading.
Alternatively, clone the repository from GitHub. Install dependencies with pip install -r requirements.txt. Run the application with python main.py and visit http://localhost:5000.
You can also run AITradeGame using Docker:
Using docker-compose (recommended):
# Build and start the container
docker-compose up -d
# Access the application at http://localhost:5000Using docker directly:
# Build the image
docker build -t aitradegame .
# Run the container
docker run -d -p 5000:5000 -v $(pwd)/data:/app/data aitradegame
# Access the application at http://localhost:5000The docker-compose stack provisions PostgreSQL automatically and stores data in the postgres_data volume. If you run the backend container manually, make sure POSTGRES_URI points to a reachable PostgreSQL instance before starting the app. To stop the compose stack, run docker-compose down.
The project follows a modular architecture with clear separation of concerns:
project/
├── main.py # Backend entry point
├── backend/
│ ├── core/ # Core trading logic (engine, AI trader)
│ ├── data/ # Data layer (database, market data)
│ ├── api/ # API routes (providers, models, trades, market, system)
│ ├── models/ # Data models (provider, trading_model, portfolio, trade)
│ ├── services/ # Business services (trading, portfolio, market)
│ ├── utils/ # Utility functions (formatters, validators, version)
│ └── config/ # Configuration (settings, constants)
├── frontend/ # Next.js 15 + React 19 frontend
│ ├── app/ # Next.js App Router pages
│ ├── components/ # React components (UI + features)
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utilities and API client
│ └── store/ # Zustand state management
└── requirements.txt # Python dependencies
Copy .env.example to .env and configure your settings:
cp .env.example .envKey configuration options:
DEBUG: Enable debug mode (default: False)HOST: Server host (default: 0.0.0.0)PORT: Server port (default: 5000)POSTGRES_URI: PostgreSQL connection URI (default:postgresql://aitrade:aitrade@localhost:5432/aitrade)AUTO_TRADING: Enable automatic trading (default: True)LOG_LEVEL: Logging level (default: INFO)MARKET_CACHE_DURATION: Market data cache duration in seconds (default: 5)MARKET_API_URL: External market data API base URL (default: CoinGecko)MARKET_HISTORY_ENABLED: Toggle background market snapshot persistence (default: True)MARKET_HISTORY_INTERVAL: Snapshot interval in seconds (default: 5)MARKET_HISTORY_RESOLUTION: Resolution bucket in seconds for stored candles (default: 60)MARKET_HISTORY_MAX_POINTS: Maximum records returned from history API (default: 500, capped at 2000)MARKET_HISTORY_CACHE_TTL: Cache TTL for history responses (default: 60; placeholder for future Redis integration)TRADING_COINS: Comma-separated list of tradable coins (default: BTC,ETH,SOL,BNB,XRP,DOGE)NEXT_PUBLIC_MARKET_API_BASE_URL: Frontend override for the market collector service (default: falls back to backend API URL)
Trading frequency, fee rate, and refresh intervals are now configured inside the in-app Settings dialog instead of environment variables.
First, add AI service providers:
- Click the "API Provider" button
- Enter provider name, API URL, and API key
- Manually input available models or click "Fetch Models" to auto-fetch
- Click save to complete configuration
After configuring providers, add trading models:
- Click the "Add Model" button
- Select a configured API provider
- Choose a specific model from the dropdown
- Enter display name and initial capital
- Click submit to start trading
Click the "Settings" button to configure:
- Trading Frequency: Control AI decision interval (1-1440 minutes)
- Trading Fee Rate: Commission rate per trade (default 0.1%)
- Market Refresh Interval: How often market data updates (seconds)
- Portfolio Refresh Interval: How often portfolio data refreshes (seconds)
GET /api/market/prices: Returns the latest price and 24h change for the configured trading universe.GET /api/market/history: Returns persisted OHLC snapshots. Query params:coin(required): Symbol such asBTCresolution(optional): Bucket size in seconds (default from config)limit(optional): Number of points (max 2000, default 500)start/end(optional): ISO8601 timestamps to bound the query
- Standalone Collector: When running via docker-compose, a dedicated
market-collectorservice (port 5100) handles price persistence and exposes/api/health,/api/market/prices,/api/market/historyso price tracking continues even if the main backend restarts.
Supports all OpenAI-compatible APIs. This includes OpenAI models like gpt-4 and gpt-3.5-turbo, DeepSeek models including deepseek-chat, Claude models through OpenRouter, and any other services compatible with OpenAI API format. More protocols are being added.
Run AITradeGame.exe and the interface will open automatically at http://localhost:5000.
- Start the backend server:
python main.pyThe backend API will be available at http://localhost:5000
- Start the frontend development server:
cd frontend
pnpm devThe frontend will be available at http://localhost:3000
Add AI model configuration through the web interface. The system automatically begins trading simulation based on your configuration. Trading fees are charged for each open and close position according to the set rate, ensuring AI strategies operate under realistic cost conditions.
All data is stored in PostgreSQL (using the database defined by POSTGRES_URI). When running under docker-compose, the postgres_data volume keeps the data on your machine. No external servers are contacted except your specified AI API endpoints. No user accounts or login required - everything runs locally.
Development requires Python 3.9 or later. Internet connection is needed for market data and AI API calls.
Install all dependencies with:
pip install -r requirements.txtStart the backend server:
python main.pyThe backend API will be available at http://localhost:5000
Run all tests with coverage:
pytestOr use the test script:
./scripts/run_tests.shSee DEVELOPMENT.md for detailed development guide.
- API Key Encryption: All API keys are encrypted at rest using Fernet symmetric encryption
- Error Handling: Comprehensive error handling with custom exception classes
- Schema Bootstrap: Database tables are created automatically when the app starts
- Input Validation: Strict validation on all API endpoints
The frontend is built with Next.js 15, React 19, TypeScript, Tailwind CSS 4, and Shadcn UI.
Prerequisites:
- Node.js 18+
- pnpm (recommended) or npm
Setup:
- Navigate to the frontend directory:
cd frontend- Install dependencies:
pnpm install
# or
npm install- Configure environment variables:
cp .env.example .env.localEdit .env.local and set the API base URL:
NEXT_PUBLIC_API_BASE_URL=http://localhost:5000- Start the development server:
pnpm dev
# or
npm run devThe frontend will be available at http://localhost:3000
Build for production:
pnpm build
pnpm startFrontend Structure:
frontend/
├── app/ # Next.js App Router pages
├── components/
│ ├── ui/ # Shadcn UI base components
│ └── features/ # Business components
├── hooks/ # Custom React hooks
├── lib/ # Utilities and API client
└── store/ # Zustand state management
Key Technologies:
- Next.js 15 with App Router
- React 19 with Server Components
- TypeScript for type safety
- Tailwind CSS 4 for styling
- Shadcn UI for component library
- Zustand for state management
- ECharts for data visualization
Community contributions are welcome.
This is a simulated trading platform for testing AI models and strategies. It is not real trading and no actual money is involved. Always conduct your own research and analysis before making investment decisions. No warranties are provided regarding trading outcomes or AI performance.
Online version with leaderboard and social features: https://aitradegame.com
Desktop builds and releases: https://github.com/chadyi/AITradeGame/releases/tag/main
Source code repository: https://github.com/chadyi/AITradeGame