Denis Mbugua commited on
Commit
237e306
ยท
1 Parent(s): dc93bbc

R eupload changes

Browse files
Files changed (1) hide show
  1. README.md +232 -9
README.md CHANGED
@@ -1,13 +1,236 @@
1
- ---
2
- title: Autonomous Trading Floor with 4 traders
3
- emoji: ๐Ÿง 
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: gradio
7
- app_port: 7860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  ---
10
 
11
- # Autonomous Trading Floor with 4 traders
12
 
13
- This space hosts the Model Context Protocol (MCP) server implementation and trading agent application.
 
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!