Export your Trading 212 portfolio to a beautifully formatted markdown file with profit/loss calculations and visual indicators.
- 📊 Fetches real-time portfolio data from Trading 212 API
- 💰 Calculates profit/loss for each position in £ and %
- 🟢🔴 Visual indicators for gains and losses
- 📋 Generates a clean markdown table with all positions
- 📈 Includes portfolio summary with total results
- 🔒 Secure API key handling via environment variables
- ⏱️ Built-in rate limiting to respect API limits
pip install -r requirements.txt- Get your API key from Trading 212 Settings
- Copy
.env.exampleto.env:cp .env.example .env
- Edit
.envand add your API key:API_KEY=your_actual_api_key_here
python export_portfolio.pyThe script will generate a portfolio.md file in the same directory.
The generated markdown file includes:
- Portfolio Positions Table: All your holdings with current values and P&L
- Summary Section: Total portfolio value, cash balance, and overall profit/loss
This script uses the Trading 212 Public API. For more details, see the official API documentation.
The script includes comprehensive error handling for:
- Missing API key
- Network errors
- API rate limits (automatic retry with backoff)
- Invalid API responses
- Python 3.6+
- Trading 212 account with API access enabled
- Valid API key