Interact with Trading 212 investment accounts for portfolio and order management.
Trading 212 MCP Server
A comprehensive Model Context Protocol (MCP) server for seamless integration with the Trading 212 API. This server enables AI assistants like Claude to interact with your Trading 212 investment account, providing full access to account management, portfolio tracking, order execution, and historical data analysis.
Deployment Options:
- Local installation with Node.js
- Docker container (production-ready)
- Docker Compose for easy orchestration
Features
š¦ Account Management
- Get account information (currency, ID)
- View cash balances (free, invested, blocked, total)
- Retrieve comprehensive account summaries
š Portfolio Management
- List all open positions
- Get detailed position information by ticker
- Real-time profit/loss tracking
š Order Management
- View all active orders
- Place market, limit, stop, and stop-limit orders
- Cancel pending orders
- Support for DAY and GTC (Good Till Cancelled) orders
- Extended hours trading support
š Market Data & Instruments
- Search and filter thousands of tradeable instruments
- Access instrument metadata (ISIN, currency, type, trading schedules)
- View exchange information and trading hours
š„§ Investment Pies
- List all investment pies (portfolio buckets)
- Create new pies with custom allocations
- Update and delete existing pies
- Configure dividend reinvestment settings
š Historical Data
- Access order history with pagination
- Retrieve dividend payment records
- View complete transaction history
- Export data to CSV for specified time periods
ā” Performance & Observability
- Automatic rate limit tracking and headers
- Zod schema validation for type safety
- Comprehensive error handling with custom error classes
- Production-grade structured logging (Pino)
- Support for both demo and live environments
- Debug mode for API request/response inspection
Installation
Prerequisites
- Node.js 24+ installed
- Trading 212 account (Invest or ISA)
- Trading 212 API key (see Setup Guide)
Option 1: Docker (Recommended for Production)
The easiest way to deploy the MCP server is using Docker:
# Clone the repository
git clone https://github.com/enderekici/trading212-mcp.git
cd trading212-mcp
# Create .env file with your API key
echo "TRADING212_API_KEY=your_api_key_here" > .env
echo "TRADING212_ENVIRONMENT=demo" >> .env
# Start with Docker Compose
docker-compose up -d
See DOCKER.md for comprehensive Docker deployment guide.
Option 2: Local Installation
Install and build from source:
# Install dependencies
npm install
# Build the project
npm run build
Configuration
Getting Your API Key
- Open the Trading 212 app (mobile or web)
- Navigate to Settings ā API (Beta)
- Click Generate API Key
- Configure permissions:
- ā Account data (read) - View account information
- ā History (read) - Access historical data
- ā Orders (read/write) - View and place orders
- ā Portfolio (read) - View positions
- (Optional) Set IP address whitelist for additional security
- Copy your API key and store it securely
ā ļø Security Warning: Never commit your API key to version control or share it publicly.
Environment Variables
Create a .env file in the project root:
# Required: Your Trading 212 API key
TRADING212_API_KEY=your_api_key_here
# Optional: Environment (demo or live), defaults to demo
TRADING212_ENVIRONMENT=demo
# Optional: Log level (trace, debug, info, warn, error, fatal), defaults to info
LOG_LEVEL=info
# Optional: Node environment (development or production), defaults to development
NODE_ENV=development
Environments:
demo- Paper trading environment (recommended for testing)- API Base URL:
https://demo.trading212.com/api/v0 - Uses paper trading account (no real money)
- Safe for testing and development
- Default value if not specified
- API Base URL:
live- Real money trading environment- API Base URL:
https://live.trading212.com/api/v0 - Uses real money trading account
- Use with caution
- API Base URL:
ā ļø Important: Your API key is environment-specific. A demo API key only works with TRADING212_ENVIRONMENT=demo, and a live API key only works with TRADING212_ENVIRONMENT=live. You cannot mix them.
š For detailed information about environments, see ENVIRONMENTS.md
Log Levels:
trace- Most
Tools (5)
get_account_infoRetrieve account information including currency, ID, and cash balances.list_positionsList all open investment positions with real-time profit/loss tracking.place_orderPlace market, limit, stop, or stop-limit orders for tradeable instruments.list_piesList all investment pies and their current allocations.get_historyRetrieve order, dividend, or transaction history for specified periods.Environment Variables
TRADING212_API_KEYrequiredYour Trading 212 API key generated from the app settings.TRADING212_ENVIRONMENTThe environment to connect to: demo or live.LOG_LEVELLogging verbosity (trace, debug, info, warn, error, fatal).NODE_ENVNode environment (development or production).Configuration
{"mcpServers": {"trading212": {"command": "node", "args": ["/path/to/trading212-mcp/build/index.js"], "env": {"TRADING212_API_KEY": "your_api_key_here", "TRADING212_ENVIRONMENT": "demo"}}}}