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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
|
|
|
| 1 |
+
# ๐ค AI Trading Floor
|
| 2 |
+
|
| 3 |
+
An autonomous multi-agent trading simulation where AI traders powered by different language models compete in the stock market. Watch as each AI develops its own trading strategy and makes real-time decisions!
|
| 4 |
+
|
| 5 |
+
## ๐ฏ Live Demo
|
| 6 |
+
|
| 7 |
+
๐ **[View Live Trading Floor](https://huggingface.co/spaces/dynamodenis254/trading_floor)**
|
| 8 |
+
|
| 9 |
+
## ๐ Meet the Traders
|
| 10 |
+
|
| 11 |
+
Each AI agent starts with **$10,000** and trades independently in the stock market:
|
| 12 |
+
|
| 13 |
+
| Name | Personality | Model | Strategy Style |
|
| 14 |
+
|------|------------|-------|----------------|
|
| 15 |
+
| **Warren Patience** | Conservative, long-term value investor | GPT-4.1 Mini | Patient, fundamental analysis |
|
| 16 |
+
| **George Bold** | Aggressive risk-taker | DeepSeek V3 | Bold moves, high conviction |
|
| 17 |
+
| **Ray Systematic** | Data-driven quantitative trader | Gemini 2.5 Flash | Systematic, rule-based |
|
| 18 |
+
| **Cathie Crypto** | Innovation-focused growth investor | Grok 3 Mini | Disruptive tech & crypto exposure |
|
| 19 |
+
|
| 20 |
+
## โจ Features
|
| 21 |
+
|
| 22 |
+
- **Real-time Trading Dashboard**: Monitor all 4 agents simultaneously
|
| 23 |
+
- **Portfolio Tracking**: Live portfolio values, P&L, and holdings
|
| 24 |
+
- **Transaction History**: Complete audit trail of all trades
|
| 25 |
+
- **Performance Charts**: Visualize portfolio growth over time
|
| 26 |
+
- **Live Logs**: Watch AI decision-making in real-time
|
| 27 |
+
- **Multi-Model Competition**: Different AI models with unique trading styles
|
| 28 |
+
- **Market Hours Aware**: Respects actual market trading hours
|
| 29 |
+
|
| 30 |
+
## ๐ Quick Start
|
| 31 |
+
|
| 32 |
+
### Prerequisites
|
| 33 |
+
|
| 34 |
+
- Python 3.10+
|
| 35 |
+
- API keys for the AI models you want to use
|
| 36 |
+
|
| 37 |
+
### Installation
|
| 38 |
+
|
| 39 |
+
1. Clone the repository:
|
| 40 |
+
```bash
|
| 41 |
+
git clone https://github.com/yourusername/trading-floor.git
|
| 42 |
+
cd trading-floor
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
2. Install dependencies:
|
| 46 |
+
```bash
|
| 47 |
+
pip install -r requirements.txt
|
| 48 |
+
# or with uv
|
| 49 |
+
uv pip install -r requirements.txt
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
3. Create a `.env` file with your configuration:
|
| 53 |
+
|
| 54 |
+
```env
|
| 55 |
+
# Required: At least one API key
|
| 56 |
+
OPENAI_API_KEY=your_openai_key_here
|
| 57 |
+
|
| 58 |
+
# Optional: For multi-model competition (set USE_MANY_MODELS=true)
|
| 59 |
+
DEEPSEEK_API_KEY=your_deepseek_key_here
|
| 60 |
+
GOOGLE_API_KEY=your_google_key_here
|
| 61 |
+
GROK_API_KEY=your_grok_key_here
|
| 62 |
+
OPENROUTER_API_KEY=your_openrouter_key_here
|
| 63 |
+
|
| 64 |
+
# Trading Configuration
|
| 65 |
+
RUN_EVERY_N_MINUTES=60
|
| 66 |
+
RUN_EVEN_WHEN_MARKET_IS_CLOSED=false
|
| 67 |
+
USE_MANY_MODELS=true
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### Running Locally
|
| 71 |
+
|
| 72 |
+
**Option 1: Run Everything (UI + Agents)**
|
| 73 |
+
```bash
|
| 74 |
+
python app.py
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
**Option 2: Run Components Separately**
|
| 78 |
+
```bash
|
| 79 |
+
# Terminal 1: Start the trading agents
|
| 80 |
+
python trading_floor.py
|
| 81 |
+
|
| 82 |
+
# Terminal 2: Start the UI
|
| 83 |
+
python app.py
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
The dashboard will be available at `http://localhost:7860`
|
| 87 |
+
|
| 88 |
+
## โ๏ธ Configuration Options
|
| 89 |
+
|
| 90 |
+
### Environment Variables
|
| 91 |
+
|
| 92 |
+
| Variable | Description | Default | Options |
|
| 93 |
+
|----------|-------------|---------|---------|
|
| 94 |
+
| `RUN_EVERY_N_MINUTES` | Trading cycle frequency | `60` | Any integer (minutes) |
|
| 95 |
+
| `RUN_EVEN_WHEN_MARKET_IS_CLOSED` | Trade outside market hours | `false` | `true` / `false` |
|
| 96 |
+
| `USE_MANY_MODELS` | Enable 4 different AI models | `false` | `true` / `false` |
|
| 97 |
+
|
| 98 |
+
### Single Model vs Multi-Model
|
| 99 |
+
|
| 100 |
+
**Single Model Mode** (`USE_MANY_MODELS=false`):
|
| 101 |
+
- All 4 agents use GPT-4.1 Mini
|
| 102 |
+
- Only requires `OPENAI_API_KEY`
|
| 103 |
+
- Lower API costs
|
| 104 |
+
- Great for testing strategies
|
| 105 |
+
|
| 106 |
+
**Multi-Model Mode** (`USE_MANY_MODELS=true`):
|
| 107 |
+
- Each agent uses a different AI model
|
| 108 |
+
- Requires multiple API keys
|
| 109 |
+
- Diverse trading strategies
|
| 110 |
+
- More interesting competition
|
| 111 |
+
|
| 112 |
+
## ๐๏ธ Architecture
|
| 113 |
+
|
| 114 |
+
```
|
| 115 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 116 |
+
โ app.py โ
|
| 117 |
+
โ (Gradio UI + Background Trading Thread) โ
|
| 118 |
+
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 119 |
+
โ
|
| 120 |
+
โโโโโโโโโโดโโโโโโโโโ
|
| 121 |
+
โ โ
|
| 122 |
+
โโโโโโโโโโผโโโโโโโโโ โโโโโโโผโโโโโโโโโโโ
|
| 123 |
+
โ trading_floor โ โ Gradio UI โ
|
| 124 |
+
โ (Agents) โ โ Dashboard โ
|
| 125 |
+
โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
|
| 126 |
+
โ
|
| 127 |
+
โโโโโโดโโโโโโฌโโโโโโโฌโโโโโโโ
|
| 128 |
+
โ โ โ โ
|
| 129 |
+
โโโโโผโโโโ โโโโโผโโโโ โโผโโโโโ โโผโโโโโโ
|
| 130 |
+
โWarren โ โGeorge โ โRay โ โCathieโ
|
| 131 |
+
โ GPT-4 โ โDeepSeekโGeminiโ โ Grok โ
|
| 132 |
+
โโโโโโโโโ โโโโโโโโโ โโโโโโโ โโโโโโโโ
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
## ๐ฆ Project Structure
|
| 136 |
+
|
| 137 |
+
```
|
| 138 |
+
trading-floor/
|
| 139 |
+
โโโ app.py # Main Gradio UI application
|
| 140 |
+
โโโ trading_floor.py # Autonomous agent scheduler
|
| 141 |
+
โโโ traders.py # Trader class implementation
|
| 142 |
+
โโโ accounts.py # Portfolio & transaction management
|
| 143 |
+
โโโ agents.py # AI agent logic
|
| 144 |
+
โโโ market.py # Market data & trading hours
|
| 145 |
+
โโโ database.py # Logging & persistence
|
| 146 |
+
โโโ util.py # Utilities & styling
|
| 147 |
+
โโโ requirements.txt # Python dependencies
|
| 148 |
+
โโโ .env # Configuration (create this)
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
## ๐ฎ How It Works
|
| 152 |
+
|
| 153 |
+
1. **Initialization**: Each agent starts with $10,000 in cash
|
| 154 |
+
2. **Analysis Phase**: Agents analyze market conditions, news, and their portfolio
|
| 155 |
+
3. **Decision Making**: AI models decide on trades based on their personality
|
| 156 |
+
4. **Execution**: Buy/sell orders are executed at market prices
|
| 157 |
+
5. **Logging**: All decisions and transactions are recorded
|
| 158 |
+
6. **Repeat**: Cycle repeats every N minutes during market hours
|
| 159 |
+
|
| 160 |
+
## ๐ Dashboard Features
|
| 161 |
+
|
| 162 |
+
### Real-Time Metrics
|
| 163 |
+
- **Portfolio Value**: Current total value (cash + holdings)
|
| 164 |
+
- **P&L Indicator**: Profit/Loss with color coding (๐ข/๐ด)
|
| 165 |
+
- **Performance Chart**: Historical portfolio value over time
|
| 166 |
+
|
| 167 |
+
### Data Tables
|
| 168 |
+
- **Holdings**: Current stock positions
|
| 169 |
+
- **Recent Transactions**: Trade history with rationale
|
| 170 |
+
- **Live Logs**: AI thinking process and decisions
|
| 171 |
+
|
| 172 |
+
## ๐ง API Keys Setup
|
| 173 |
+
|
| 174 |
+
### Getting API Keys
|
| 175 |
+
|
| 176 |
+
1. **OpenAI (GPT-4.1 Mini)**: https://platform.openai.com/api-keys
|
| 177 |
+
2. **DeepSeek**: https://platform.deepseek.com/
|
| 178 |
+
3. **Google AI (Gemini)**: https://aistudio.google.com/apikey
|
| 179 |
+
4. **Grok (xAI)**: https://console.x.ai/
|
| 180 |
+
5. **OpenRouter**: https://openrouter.ai/keys
|
| 181 |
+
|
| 182 |
+
### Security Notes
|
| 183 |
+
- โ ๏ธ **Never commit your `.env` file**
|
| 184 |
+
- Add `.env` to `.gitignore`
|
| 185 |
+
- For Hugging Face Spaces, use the Secrets tab in settings
|
| 186 |
+
- Rotate keys regularly
|
| 187 |
+
|
| 188 |
+
## ๐ Deploying to Hugging Face Spaces
|
| 189 |
+
|
| 190 |
+
1. Create a new Space at https://huggingface.co/spaces
|
| 191 |
+
2. Upload your code
|
| 192 |
+
3. Add secrets in Settings โ Repository Secrets:
|
| 193 |
+
- `OPENAI_API_KEY`
|
| 194 |
+
- `DEEPSEEK_API_KEY` (if using multi-model)
|
| 195 |
+
- `GOOGLE_API_KEY` (if using multi-model)
|
| 196 |
+
- `GROK_API_KEY` (if using multi-model)
|
| 197 |
+
- `RUN_EVERY_N_MINUTES=60`
|
| 198 |
+
- `USE_MANY_MODELS=true`
|
| 199 |
+
4. Space will auto-deploy!
|
| 200 |
+
|
| 201 |
+
## ๐ค Contributing
|
| 202 |
+
|
| 203 |
+
Contributions are welcome! Ideas:
|
| 204 |
+
- New trading strategies
|
| 205 |
+
- Additional AI models
|
| 206 |
+
- Enhanced analytics
|
| 207 |
+
- Risk management features
|
| 208 |
+
- Backtesting capabilities
|
| 209 |
+
|
| 210 |
+
## โ๏ธ Disclaimer
|
| 211 |
+
|
| 212 |
+
**This is a simulation for educational and entertainment purposes only.**
|
| 213 |
+
|
| 214 |
+
- ๐ซ Not financial advice
|
| 215 |
+
- ๐ซ Not suitable for real trading
|
| 216 |
+
- ๐ซ No guarantee of accuracy
|
| 217 |
+
- โ ๏ธ AI models can make irrational decisions
|
| 218 |
+
- โ ๏ธ Past performance โ future results
|
| 219 |
+
|
| 220 |
+
**Do not use this for actual investment decisions. Always consult with a qualified financial advisor.**
|
| 221 |
+
|
| 222 |
+
## ๐ License
|
| 223 |
+
|
| 224 |
+
MIT License - feel free to use and modify!
|
| 225 |
+
|
| 226 |
+
## ๐ Acknowledgments
|
| 227 |
+
|
| 228 |
+
- Built with [Gradio](https://gradio.app/)
|
| 229 |
+
- Powered by OpenAI, DeepSeek, Google, and xAI
|
| 230 |
+
- Inspired by legendary investors Warren Buffett, George Soros, Ray Dalio, and Cathie Wood
|
| 231 |
|
| 232 |
---
|
| 233 |
|
| 234 |
+
**Made with โค๏ธ by [DynamoDenis254](https://huggingface.co/dynamodenis254) [LinkedIn](https://www.linkedin.com/in/dynamo-denis-mbugua-53304b197/)**
|
| 235 |
|
| 236 |
+
โญ Star this project if you find it interesting!
|