使用说明
title: "Trader Floor AI Simulator" emoji: "📈" colorFrom: blue colorTo: green sdk: gradio sdk_version: "5.47.2" app_file: app.py pinned: false
Trader Floor AI Simulator
A group of AI traders with different strategies research the market, decide and trade a simulated portfolio on a daily schedule, with a live dashboard to watch them.
This started as the autonomous traders project from Ed Donner's agentic AI course. What I changed:
- Restructured the flat scripts into a package (domain, services, integration, agents, scheduler, UI)
- Replaced the account, market and notification MCP servers with in-process tools, and ran traders sequentially after concurrent MCP servers kept conflicting
- Kept the researcher's MCP servers (fetch, Brave search, libSQL memory) and silenced npm output so their stdio stays valid JSON
- Dockerised it and deployed it to Railway with a persistent volume, first-run database setup and a daily schedule
Stack: Python, OpenAI Agents SDK, MCP, Gradio, SQLite, Docker, Railway
🚀 Quick Start
Local Development
# Clone and install
git clone https://github.com/CarolinaCapilla/trader-floor-ai-simulator.git
cd trader-floor-ai-simulator
uv pip install -e .
# Set up environment variables (copy .env.example to .env)
# Add your API keys: OPENAI_API_KEY, POLYGON_API_KEY, etc.
# Run the UI
python app.py
# Or run the scheduler
python trading_floor.py
Deploy to Railway (Recommended for Scheduled Trading)
railway login
railway init
railway up
See RAILWAY.md for complete deployment guide with:
- Persistent database via volumes
- Daily scheduled trading runs
- Environment variable setup
- Monitoring and troubleshooting
🏗️ Features
- AI-Powered Trading Loop: Each trader researches, generates a plan, and executes trades
- Multi-Agent Composition: Trader agents leverage a dedicated Researcher agent via MCP
- Web Interface (Gradio): Live dashboard with portfolio values, charts, logs, holdings, and transactions
- Pluggable Market Data: Use Polygon MCP (paid or realtime) or a local market server
- Persistent State: SQLite-backed accounts and logs in
accounts.db - Push Notifications: Optional Pushover integration for post-trade summaries
- Configurable Scheduling: Run continuously or a fixed number of iterations
🏗️ Architecture
Core components:
- Trader agents (
traders.Trader): Orchestrate research and trading using tools - Researcher agent: Exposed as a tool to each trader via MCP servers
- MCP servers (
mcp_params.py):accounts_server.pyfor account tools and resourcespush_server.pyfor push notifications (optional)- Market data via:
- Polygon MCP (
uvx --from git+https://github.com/polygon-io/mcp_polygon@v0.1.0 mcp_polygon) when configured, or - Local
market_server.py
- Polygon MCP (
- Scheduler (
trading_floor.py): Runs all traders every N minutes (or a fixed number of iterations) - UI (
app.py): Gradio dashboard polling live account data and logs - Database (
database.py): SQLite tables foraccounts,logs, andmarket
📋 Prerequisites
- Python 3.12+ (Hugging Face Spaces defaults to Python 3.10 unless you set a runtime. If using HF Spaces, either:
- Add a
runtime.txtwithpython-3.12OR - Remove dependencies that require newer stdlib behavior.)
- Add a
uvfor fast installs/runs (or pip)- Optional: Polygon API key (for market data MCP)
- Optional: Pushover credentials (for notifications)
🛠️ Installation
-
Clone the repository
git clone <your-repo-url> cd trader-floor-ai-simulator -
Install dependencies
# with uv (recommended) uv sync # or with pip pip install -r requirements.txt -
Set up environment variables Create a
.envin the project root:# Server and scheduling RUN_EVERY_N_MINUTES=60 RUN_EVEN_WHEN_MARKET_IS_CLOSED=false USE_MANY_MODELS=false MAX_ITERATIONS=1 # Market data POLYGON_API_KEY= POLYGON_PLAN=free # free | paid | realtime # Research tools BRAVE_API_KEY= # Model providers (use any you plan to call) DEEPSEEK_API_KEY= GOOGLE_API_KEY= GROK_API_KEY= OPENROUTER_API_KEY= # Push notifications (optional) PUSHOVER_USER= PUSHOVER_TOKEN=
🚀 Usage
Run the Gradio Dashboard
uv run app.py
- Opens the dashboard in your browser. It auto-refreshes logs (~0.5s) and portfolio/chart/holdings/transactions (~120s). Adjust timers in
app.pyif needed.
Run Traders on a Schedule
# run once (default MAX_ITERATIONS=1)
uv run trading_floor.py
# run N iterations
MAX_ITERATIONS=3 uv run trading_floor.py
# run continuously every N minutes
MAX_ITERATIONS=1000000 RUN_EVERY_N_MINUTES=60 uv run trading_floor.py
- Press Ctrl+C to stop when running continuously.
📁 Project Structure
trader-floor-ai-simulator/
├── accounts.py # Account model and operations
├── accounts_client.py # MCP client for accounts server
├── accounts_server.py # MCP server exposing account tools/resources
├── account.db # SQLite database (ignored by git)
├── app.py # Gradio UI
├── database.py # SQLite setup and CRUD helpers
├── market.py # Market data integration (Polygon or fallback)
├── market_server.py # Local MCP server for market data
├── mcp_params.py # MCP server parameters (accounts, push, market)
├── push_server.py # Pushover MCP server (optional)
├── traders.py # Trader and Researcher agent glue
├── trading_floor.py # Scheduler to run traders periodically
├── requirements.txt / pyproject.toml
└── README.md
🔧 Configuration
- Scheduling:
RUN_EVERY_N_MINUTES,MAX_ITERATIONS,RUN_EVEN_WHEN_MARKET_IS_CLOSED - Models: Toggle
USE_MANY_MODELSto run traders with multiple model backends - Market Data: Set
POLYGON_PLANtofree,paid, orrealtime; providePOLYGON_API_KEY - Push: Provide
PUSHOVER_USERandPUSHOVER_TOKENto enable notifications - Memory (MCP): Local memory DBs are created under
memory/automatically
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
📄 License
This project is licensed under the MIT License — add a LICENSE file if missing.
🐛 Troubleshooting
Common Issues
Failed to spawn: accounts_server.py: Ensure file exists andmcp_params.pyreferencesaccounts_server.pyUnable to open connection to local database ./memory/<name>.db: 14:- Ensure the
memory/folder exists (the app now creates it automatically) - Use absolute
LIBSQL_URLif running tools elsewhere
- Ensure the
- Polygon API errors: Set
POLYGON_API_KEYandPOLYGON_PLAN - UI not updating: Lower timers in
app.pyor trigger a new trader run
Debug Mode
Enable additional logging in your shell as needed (example):
export MAX_ITERATIONS=1
export RUN_EVERY_N_MINUTES=1
🔄 Future Enhancements
- [ ] Migrate UI to Vue.js/Nuxt.js
- [ ] Export reports (CSV/PDF)
📞 Support
- Open an issue with logs, steps to reproduce, and environment details.