Get the FREE Ultimate OpenClaw Setup Guide →

ai-trader

Backtrader-powered backtesting framework for algorithmic trading, featuring 20+ strategies, multi-market support, CLI tools, and an integrated MCP server for professional traders.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio whchien-ai-trader python -m ai_trader.mcp \
  --env PYTHONWARNINGS="ignore" \
  --env AI_TRADER_CONFIG="Path to configuration files if needed"

How to use

AI-Trader exposes a Model Context Protocol (MCP) server that lets AI assistants interact with a configurable backtesting engine built on Backtrader. Once the MCP server is running, you can issue natural language prompts to drive backtests, fetch historical data, list available strategies, and run or refine experiments. The server accepts commands through Claude-like or other MCP-enabled assistants and returns structured results such as backtest metrics, trade logs, and configuration details. It’s designed to be easily integrated into your existing workflow so you can prototype trading ideas with minimal friction while maintaining reproducible configurations.

How to install

Prerequisites:

  • Python 3.11+ installed on your system
  • A working environment with access to install Python packages
  • Optional: Claude Desktop or another MCP-enabled assistant for best experience

Install from PyPI (recommended if you want CLI access and library usage):

pip install ai-trader

Install from source (recommended for examples, config templates, and contribution):

git clone https://github.com/whchien/ai-trader.git
cd ai-trader
pip install -e .

Run the MCP server locally to enable LLM interaction with the backtesting engine:

python -m ai_trader.mcp

If you are integrating with Claude Desktop, add the MCP server to your Claude configuration (see the README example) under mcpServers with the following settings:

{
  "mcpServers": {
    "ai-trader": {
      "command": "python3",
      "args": ["-m", "ai_trader.mcp"],
      "cwd": "/path/to/ai-trader"
    }
  }
}

Additional notes

Tips:

  • The MCP server runs the Python module ai_trader.mcp; ensure your working directory points to the project root so imports resolve correctly.
  • If you use a virtual environment, set the full path to the python executable in the command (e.g., /path/to/.venv/bin/python3).
  • After changing MCP config files (e.g., Claude config), restart Claude Desktop to pick up updates.
  • The server supports commands like running backtests via YAML configs, listing strategies, and fetching market data. Leverage the built-in config templates under config/backtest/ for reproducible experiments.
  • For reproduction in CI or other automation, pin dependency versions and consider using Poetry or a virtual environment manager as described in the project docs.

Related MCP Servers

Sponsor this space

Reach thousands of developers