$npx -y skills add trading212-labs/agent-skills --skill trading212-apiThis skill should be used when the user asks to "connect to Trading 212", "authenticate Trading 212 API", "place a trade", "buy stock", "sell shares", "place market order",, "place pending order", "place limit order", "cancel order", "check my balance", "view account summary", "g
| 1 | # Trading 212 API |
| 2 | |
| 3 | > **Note:** The Trading 212 API is currently in **beta** and under active development. Some endpoints or behaviors may change. |
| 4 | |
| 5 | ## Quick Reference |
| 6 | |
| 7 | ### Environments |
| 8 | |
| 9 | | Environment | Base URL | Purpose | |
| 10 | | ----------- | ------------------------------------ | --------------------------------------- | |
| 11 | | Demo | `https://demo.trading212.com/api/v0` | Paper trading - test without real funds | |
| 12 | | Live | `https://live.trading212.com/api/v0` | Real money trading | |
| 13 | |
| 14 | ### Order Quantity Convention |
| 15 | |
| 16 | - **Positive quantity = BUY** (e.g., `10` buys 10 shares) |
| 17 | - **Negative quantity = SELL** (e.g., `-10` sells 10 shares) |
| 18 | |
| 19 | ### Account Types |
| 20 | |
| 21 | Only **Invest** and **Stocks ISA** accounts are supported. |
| 22 | |
| 23 | ### Instrument Identifiers |
| 24 | |
| 25 | Trading 212 uses custom tickers as unique identifiers for instruments. |
| 26 | Always search for the Trading 212 ticker before making instrument requests. |
| 27 | |
| 28 | --- |
| 29 | |
| 30 | ## Authentication |
| 31 | |
| 32 | HTTP Basic Auth with API Key (username) and API Secret (password). |
| 33 | |
| 34 | ### Check Existing Setup First |
| 35 | |
| 36 | Before guiding the user through authentication setup, check if credentials are already configured: |
| 37 | |
| 38 | **Semantic rule:** Credentials are configured when **at least one complete set** is present: a complete set is key + secret for the same account (e.g. `T212_API_KEY` + `T212_API_SECRET`, or `T212_API_KEY_INVEST` + `T212_API_SECRET_INVEST`, or `T212_API_KEY_STOCKS_ISA` + `T212_API_SECRET_STOCKS_ISA`). You do not need all four account-specific vars; having only the Invest pair or only the Stocks ISA pair is enough. Check for any combination that gives at least one usable key+secret pair. |
| 39 | |
| 40 | ```bash |
| 41 | # Example: configured if any complete credential set exists |
| 42 | if [ -n "$T212_AUTH_HEADER" ] && [ -n "$T212_BASE_URL" ]; then |
| 43 | echo "Configured (derived vars)" |
| 44 | elif [ -n "$T212_API_KEY" ] && [ -n "$T212_API_SECRET" ]; then |
| 45 | echo "Configured (single account)" |
| 46 | elif [ -n "$T212_API_KEY_INVEST" ] && [ -n "$T212_API_SECRET_INVEST" ]; then |
| 47 | echo "Configured (Invest); Stocks ISA also if T212_API_KEY_STOCKS_ISA and T212_API_SECRET_STOCKS_ISA are set" |
| 48 | elif [ -n "$T212_API_KEY_STOCKS_ISA" ] && [ -n "$T212_API_SECRET_STOCKS_ISA" ]; then |
| 49 | echo "Configured (Stocks ISA); Invest also if T212_API_KEY_INVEST and T212_API_SECRET_INVEST are set" |
| 50 | else |
| 51 | echo "No complete credential set found" |
| 52 | fi |
| 53 | ``` |
| 54 | |
| 55 | If any complete set is present, skip the full setup and proceed with API calls; when making requests, use the resolution order in "Making Requests" below (pick the pair that matches the user's account context when multiple sets exist). Do not ask the user to run derivation one-liners or merge keys into a header. Only guide users through the full setup process below when no complete credential set exists. |
| 56 | |
| 57 | > **Important:** Before making any API calls, always ask the user which environment they want to use: **LIVE** (real money) or **DEMO** (paper trading). Do not assume the environment. |
| 58 | |
| 59 | ### API Keys Are Environment-Specific |
| 60 | |
| 61 | **API keys are tied to a specific environment and cannot be used across environments.** |
| 62 | |
| 63 | | API Key Created In | Works With | Does NOT Work With | |
| 64 | | ------------------ | --------------------- | --------------------- | |
| 65 | | LIVE account | `live.trading212.com` | `demo.trading212.com` | |
| 66 | | DEMO account | `demo.trading212.com` | `live.trading212.com` | |
| 67 | |
| 68 | If you get a 401 error, verify that: |
| 69 | |
| 70 | 1. You're using the correct API key for the target environment |
| 71 | 2. The API key was generated in the same environment (LIVE or DEMO) you're trying to access |
| 72 | |
| 73 | ### Get Credentials |
| 74 | |
| 75 | 1. **Decide which environment to use** - LIVE (real money) or DEMO (paper trading) |
| 76 | 2. Open Trading 212 app (mobile or web) |
| 77 | 3. **Switch to the correct account** - Make sure you're in LIVE or DEMO mode matching your target environment |
| 78 | 4. Navigate to **Settings** > **API** |
| 79 | 5. Generate a new API key pair - you'll receive: |
| 80 | - **API Key (ID)** (e.g., `35839398ZFVKUxpHzPiVsxKdOtZdaDJSrvyPF`) |
| 81 | - **API Secret** (e.g., `7MOzYJlVJgxoPjdZJCEH3fO9ee7A0NzLylFFD4-3tlo`) |
| 82 | 6. **Store the credentials separately** for each environment if you use both |
| 83 | |
| 84 | ### Building the Auth Header |
| 85 | |
| 86 | Combine your API Key (ID) and Secret with a colon, base64 |