A simulation of AI agents trading stocks on your behalf, with a local market, accounts, and trader behaviors orchestrated behind a simple app entrypoint. :contentReference[oaicite:0]{index=0}
Live demo: https://huggingface.co/spaces/Anindhya/MCP_TradingAgents
This project models a miniature trading ecosystem:
- Market services provide prices and order matching.
- Accounts services hold cash/positions.
- Trader agents decide what to buy/sell and submit orders to the market.
- A lightweight UI (via Gradio) lets you launch and observe the system. The repository metadata on GitHub shows the Space-style config for Gradio with
app.pyandsdk_version: 5.42.0. :contentReference[oaicite:2]{index=2}
- Multiple services: market, accounts, and a push/notification layer
- Agent-based traders with pluggable strategies
- Local persistence: lightweight SQLite (
accounts.db) for state - Composable modules: clean separation between data, services, and agents
- Gradio UI: quick local run via
app.pyto simulate and observe trades :contentReference[oaicite:3]{index=3}
app.py— App entrypoint (Gradio-based UI wrapper) :contentReference[oaicite:4]{index=4}trading_floor.py— Orchestrates traders, market, and accounts (simulation loop)traders.py— Trader agent behaviors/strategiesmarket.py,market_server.py— Market model and service endpointsaccounts.py,accounts_server.py,accounts_client.py— Account model/service and clientpush_server.py— Push/notification mechanism between componentsdatabase.py— DB helpers (SQLite)templates.py— Reusable message/order templatesmcp_params.py— Tunable parameters for the simulationtracers.py— Logging/tracing utilitiesutil.py— Shared helpersreset.py— Utilities to reset data/staterequirements.txt— Python dependencies :contentReference[oaicite:5]{index=5}
The file list above is derived from the repo’s “Code” tab file tree. :contentReference[oaicite:6]{index=6}
- Python 3.10+
- Gradio for the local UI launched by
app.py:contentReference[oaicite:7]{index=7} - SQLite for lightweight persistence (
accounts.db) - Requests / HTTP for service-style modules (market/accounts/push)
- Structured modules for clear separation of concerns
Clone the repository: git clone https://github.com/anindhya1/mcp_trading_agents.git cd mcp_trading_agents
Install dependencies: pip install -r requirements.txt # see requirements.txt in the repo :contentReference[oaicite:8]{index=8}
(Optional) If you run into platform-specific issues, create and activate a virtual environment before installing.
Start the app locally: python app.py
Then open the printed local URL in your browser (typically http://127.0.0.1:7860/) to interact with the simulation UI. The GitHub metadata indicates the app is Gradio-based and uses app.py as the entrypoint. :contentReference[oaicite:9]{index=9}
If you prefer running services explicitly (instead of letting the app orchestrate):
-
Start Accounts service: python accounts_server.py
-
Start Market service: python market_server.py
-
Start Push/notification service: python push_server.py
-
Run the Trading Floor (agents and strategies): python trading_floor.py
You can then watch logs (via tracers.py integration) and inspect accounts.db for balances and positions.
Most knobs live in:
mcp_params.py— simulation parameters (e.g., tick interval, symbols, spreads)templates.py— message/order templatesutil.py— shared helpers
For a clean slate: python reset.py
-
Market Loop
- The market service produces prices/ticks, accepts orders, and fills them based on simple microstructure assumptions.
-
Accounts & Ledger
- The accounts service tracks cash, positions, realized P&L, and updates the SQLite database (
accounts.db).
- The accounts service tracks cash, positions, realized P&L, and updates the SQLite database (
-
Trader Agents
- Each trader agent (in
traders.py) implements a strategy (e.g., trend-following, mean-reversion, random baseline). - The
trading_floor.pyorchestrator coordinates agent decisions and sends orders to the market.
- Each trader agent (in
-
UI & Control
app.py(Gradio) provides a minimal control surface to start/stop a simulation run and inspect status. The repo’s GitHub page explicitly listsapp.pyas the app file for a Gradio setup. :contentReference[oaicite:10]{index=10}
- Add a new strategy: implement a class/function in
traders.py, wire it intotrading_floor.py. - Change market dynamics: adjust logic in
market.py(spreads, fills, tick generation). - Augment account rules: customize
accounts.py(margin rules, fees/commissions). - Observability: add spans/events in
tracers.pyfor richer logs or metrics. - Parameters: centralize tunables in
mcp_params.py.
- This is a simulation for experimentation and learning—not financial advice and not connected to live brokerage APIs.
- Market/strategy logic is intentionally simplified to keep the code approachable.
- SQLite is used for convenience; consider Postgres for heavier workloads.
- Real-time concurrency is limited in the basic run mode; service mode can be extended with async or multiprocessing.
- Richer price processes and order book simulation
- Portfolio-level risk constraints and position limits
- Async I/O and streaming tick pipelines
- Strategy plug-ins with config-driven selection
- Web dashboard for historical P&L, drawdowns, and exposure
MIT (or your preferred license). Add a LICENSE file if not present.
- Gradio for the local app wrapper (as indicated by repo metadata) :contentReference[oaicite:11]{index=11}
- Python ecosystem for batteries-included simulation building blocks