{
  "schemaVersion": "1.0",
  "item": {
    "slug": "trading212-api",
    "name": "Trading212 API",
    "source": "tencent",
    "type": "skill",
    "category": "开发工具",
    "sourceUrl": "https://clawhub.ai/tsvetelin-kulinski/trading212-api",
    "canonicalUrl": "https://clawhub.ai/tsvetelin-kulinski/trading212-api",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/trading212-api",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=trading212-api",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "SKILL.md"
    ],
    "primaryDoc": "SKILL.md",
    "quickSetup": [
      "Download the package from Yavira.",
      "Extract the archive and review SKILL.md first.",
      "Import or place the package into your OpenClaw setup."
    ],
    "agentAssist": {
      "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
      "steps": [
        "Download the package from Yavira.",
        "Extract it into a folder your agent can access.",
        "Paste one of the prompts below and point your agent at the extracted folder."
      ],
      "prompts": [
        {
          "label": "New install",
          "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
        },
        {
          "label": "Upgrade existing",
          "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
        }
      ]
    },
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-05-07T17:22:31.273Z",
      "expiresAt": "2026-05-14T17:22:31.273Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=afrexai-annual-report",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=afrexai-annual-report",
        "contentDisposition": "attachment; filename=\"afrexai-annual-report-1.0.0.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/trading212-api"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    },
    "downloadPageUrl": "https://openagent3.xyz/downloads/trading212-api",
    "agentPageUrl": "https://openagent3.xyz/skills/trading212-api/agent",
    "manifestUrl": "https://openagent3.xyz/skills/trading212-api/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/trading212-api/agent.md"
  },
  "agentAssist": {
    "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
    "steps": [
      "Download the package from Yavira.",
      "Extract it into a folder your agent can access.",
      "Paste one of the prompts below and point your agent at the extracted folder."
    ],
    "prompts": [
      {
        "label": "New install",
        "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
      },
      {
        "label": "Upgrade existing",
        "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
      }
    ]
  },
  "documentation": {
    "source": "clawhub",
    "primaryDoc": "SKILL.md",
    "sections": [
      {
        "title": "Trading 212 API",
        "body": "Note: The Trading 212 API is currently in beta and under active development. Some endpoints or behaviors may change."
      },
      {
        "title": "Environments",
        "body": "EnvironmentBase URLPurposeDemohttps://demo.trading212.com/api/v0Paper trading - test without real fundsLivehttps://live.trading212.com/api/v0Real money trading"
      },
      {
        "title": "Order Quantity Convention",
        "body": "Positive quantity = BUY (e.g., 10 buys 10 shares)\nNegative quantity = SELL (e.g., -10 sells 10 shares)"
      },
      {
        "title": "Account Types",
        "body": "Only Invest and Stocks ISA accounts are supported."
      },
      {
        "title": "Instrument Identifiers",
        "body": "Trading 212 uses custom tickers as unique identifiers for instruments.\nAlways search for the Trading 212 ticker before making instrument requests."
      },
      {
        "title": "Authentication",
        "body": "HTTP Basic Auth with API Key (username) and API Secret (password)."
      },
      {
        "title": "Check Existing Setup First",
        "body": "Before guiding the user through authentication setup, check if credentials are already configured:\n\nSemantic 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.\n\n# Example: configured if any complete credential set exists\nif [ -n \"$T212_AUTH_HEADER\" ] && [ -n \"$T212_BASE_URL\" ]; then\n  echo \"Configured (derived vars)\"\nelif [ -n \"$T212_API_KEY\" ] && [ -n \"$T212_API_SECRET\" ]; then\n  echo \"Configured (single account)\"\nelif [ -n \"$T212_API_KEY_INVEST\" ] && [ -n \"$T212_API_SECRET_INVEST\" ]; then\n  echo \"Configured (Invest); Stocks ISA also if T212_API_KEY_STOCKS_ISA and T212_API_SECRET_STOCKS_ISA are set\"\nelif [ -n \"$T212_API_KEY_STOCKS_ISA\" ] && [ -n \"$T212_API_SECRET_STOCKS_ISA\" ]; then\n  echo \"Configured (Stocks ISA); Invest also if T212_API_KEY_INVEST and T212_API_SECRET_INVEST are set\"\nelse\n  echo \"No complete credential set found\"\nfi\n\nIf 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.\n\nImportant: 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."
      },
      {
        "title": "API Keys Are Environment-Specific",
        "body": "API keys are tied to a specific environment and cannot be used across environments.\n\nAPI Key Created InWorks WithDoes NOT Work WithLIVE accountlive.trading212.comdemo.trading212.comDEMO accountdemo.trading212.comlive.trading212.com\n\nIf you get a 401 error, verify that:\n\nYou're using the correct API key for the target environment\nThe API key was generated in the same environment (LIVE or DEMO) you're trying to access"
      },
      {
        "title": "Get Credentials",
        "body": "Decide which environment to use - LIVE (real money) or DEMO (paper trading)\nOpen Trading 212 app (mobile or web)\nSwitch to the correct account - Make sure you're in LIVE or DEMO mode matching your target environment\nNavigate to Settings > API\nGenerate a new API key pair - you'll receive:\n\nAPI Key (ID) (e.g., 35839398ZFVKUxpHzPiVsxKdOtZdaDJSrvyPF)\nAPI Secret (e.g., 7MOzYJlVJgxoPjdZJCEH3fO9ee7A0NzLylFFD4-3tlo)\n\n\nStore the credentials separately for each environment if you use both"
      },
      {
        "title": "Building the Auth Header",
        "body": "Combine your API Key (ID) and Secret with a colon, base64 encode, and prefix with Basic  for the Authorization header.\n\nOptional: To precompute the header from key/secret, you can set:\n\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64)\"\n\nOtherwise, the agent builds the header from T212_API_KEY and T212_API_SECRET when making requests.\n\nManual (placeholders):\n\n# Format: T212_AUTH_HEADER = \"Basic \" + base64(API_KEY_ID:API_SECRET)\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"<YOUR_API_KEY_ID>:<YOUR_API_SECRET>\" | base64)\"\n\n# Example with sample credentials:\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"35839398ZFVKUxpHzPiVsxKdOtZdaDJSrvyPF:7MOzYJlVJgxoPjdZJCEH3fO9ee7A0NzLylFFD4-3tlo\" | base64)\""
      },
      {
        "title": "Making Requests",
        "body": "When making API calls, use the first option that applies (semantically: pick the credential set that matches the user's account, or the only set present):\n\nIf T212_AUTH_HEADER and T212_BASE_URL are set: use them in requests.\nElse if T212_API_KEY and T212_API_SECRET are set: use this pair (single account). Build header as Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64) and base URL as https://${T212_ENV:-live}.trading212.com. Do not guide the user to derive or merge; you do it.\nElse if both account-specific pairs are set (T212_API_KEY_INVEST/T212_API_SECRET_INVEST and T212_API_KEY_STOCKS_ISA/T212_API_SECRET_STOCKS_ISA): the user must clearly specify which account to target (Invest or Stocks ISA), unless they ask for information for all accounts. Use the Invest pair when the user refers to Invest, and the Stocks ISA pair when the user refers to ISA/Stocks ISA. If the user wants information for all accounts, make multiple API calls—one per account (Invest and Stocks ISA)—and present or aggregate the results for both. If it is not clear from context which account to use (and they did not ask for all accounts), ask for confirmation before making API calls (e.g. \"Which account should I use — Invest or Stocks ISA?\"). Do not assume. Build the header from the chosen key/secret and base URL as https://${T212_ENV:-live}.trading212.com.\nElse if only the Invest pair is set (T212_API_KEY_INVEST and T212_API_SECRET_INVEST): use this pair for requests; if the user asks about Stocks ISA, only the Invest account is configured.\nElse if only the Stocks ISA pair is set (T212_API_KEY_STOCKS_ISA and T212_API_SECRET_STOCKS_ISA): use this pair for requests; if the user asks about Invest, only the Stocks ISA account is configured.\n\nUse the T212_AUTH_HEADER value in the Authorization header when it is set:\n\n# When T212_AUTH_HEADER and T212_BASE_URL are set:\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"${T212_BASE_URL}/api/v0/equity/account/summary\"\n\nWhen only primary vars are set, use the inline form in the curl:\n\n# When only T212_API_KEY, T212_API_SECRET, T212_ENV are set:\ncurl -H \"Authorization: Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64)\" \\\n  \"https://${T212_ENV:-live}.trading212.com/api/v0/equity/account/summary\"\n\nWarning: T212_AUTH_HEADER must be the full header value including the Basic  prefix.\n# WRONG - raw base64 without \"Basic \" prefix\ncurl -H \"Authorization: <base64-only>\" ...  # This will NOT work!\n\n# CORRECT - use T212_AUTH_HEADER (contains \"Basic <base64>\")\ncurl -H \"Authorization: $T212_AUTH_HEADER\" ...  # This works"
      },
      {
        "title": "Environment Variables",
        "body": "Single account vs all accounts: API keys are for a single account. One key/secret pair (T212_API_KEY + T212_API_SECRET) = one account (Invest or Stocks ISA). To use all accounts (Invest and Stocks ISA), the user must set two sets of key/secret: T212_API_KEY_INVEST / T212_API_SECRET_INVEST and T212_API_KEY_STOCKS_ISA / T212_API_SECRET_STOCKS_ISA. When both pairs are set, the user must clearly specify which account to target; if it is not clear from context, ask for confirmation (Invest or Stocks ISA) before making API calls.\n\nPrimary (single account): Set these for consistent setup with the plugin README:\n\nexport T212_API_KEY=\"your-api-key\"       # API Key (ID) from Trading 212\nexport T212_API_SECRET=\"your-api-secret\"\nexport T212_ENV=\"demo\"                   # or \"live\" (defaults to \"live\" if unset)\n\nAccount-specific (Invest and/or Stocks ISA): Set only the pair(s) you use. One complete set (key + secret for the same account) is enough. For example, only Invest:\n\nexport T212_API_KEY_INVEST=\"your-invest-api-key\"\nexport T212_API_SECRET_INVEST=\"your-invest-api-secret\"\nexport T212_ENV=\"demo\"                   # or \"live\"\n\nFor both accounts, set both pairs:\n\nexport T212_API_KEY_INVEST=\"your-invest-api-key\"\nexport T212_API_SECRET_INVEST=\"your-invest-api-secret\"\nexport T212_API_KEY_STOCKS_ISA=\"your-stocks-isa-api-key\"\nexport T212_API_SECRET_STOCKS_ISA=\"your-stocks-isa-api-secret\"\nexport T212_ENV=\"demo\"                   # or \"live\" (applies to both)\n\nOptional – precomputed (for scripts or if the user prefers): The user can set the auth header and base URL from the primary vars, but they do not need to; when making API calls you (the agent) must build the header and base URL from primary vars if these are not set.\n\n# Build auth header and base URL from T212_API_KEY, T212_API_SECRET, T212_ENV\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64)\"\nexport T212_BASE_URL=\"https://${T212_ENV:-live}.trading212.com\"\n\nAlternative (manual): If you prefer not to store key/secret in env, set derived vars directly. Remember: API keys only work with their matching environment.\n\n# For DEMO (paper trading)\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"<DEMO_API_KEY_ID>:<DEMO_API_SECRET>\" | base64)\"\nexport T212_BASE_URL=\"https://demo.trading212.com\"\n\n# For LIVE (real money) - generate separate credentials in LIVE account\n# export T212_AUTH_HEADER=\"Basic $(echo -n \"<LIVE_API_KEY_ID>:<LIVE_API_SECRET>\" | base64)\"\n# export T212_BASE_URL=\"https://live.trading212.com\"\n\nTip: If you use both environments, use separate variable names:\n\n# Demo credentials\nexport T212_DEMO_AUTH_HEADER=\"Basic $(echo -n \"<DEMO_KEY_ID>:<DEMO_SECRET>\" | base64)\"\n\n# Live credentials\nexport T212_LIVE_AUTH_HEADER=\"Basic $(echo -n \"<LIVE_KEY_ID>:<LIVE_SECRET>\" | base64)\""
      },
      {
        "title": "Common Auth Errors",
        "body": "CodeCauseSolution401Invalid credentialsCheck API key/secret, ensure no extra whitespace401Environment mismatchLIVE API keys don't work with DEMO and vice versa - verify key matches target environment403Missing permissionsCheck API permissions in Trading 212 settings408Request timed outRetry the request429Rate limit exceededWait for x-ratelimit-reset timestamp"
      },
      {
        "title": "Get Account Summary",
        "body": "GET /api/v0/equity/account/summary (1 req/5s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/account/summary\"\n\nResponse Schema:\n\n{\n  \"id\": 12345678,\n  \"currency\": \"GBP\",\n  \"totalValue\": 15250.75,\n  \"cash\": {\n    \"availableToTrade\": 2500.5,\n    \"reservedForOrders\": 150.0,\n    \"inPies\": 500.0\n  },\n  \"investments\": {\n    \"currentValue\": 12100.25,\n    \"totalCost\": 10500.0,\n    \"realizedProfitLoss\": 850.5,\n    \"unrealizedProfitLoss\": 1600.25\n  }\n}"
      },
      {
        "title": "Account Fields",
        "body": "FieldTypeDescriptionidintegerPrimary trading account numbercurrencystringPrimary account currency (ISO 4217)totalValuenumberTotal account value in primary currencycash.availableToTradenumberFunds available for investingcash.reservedForOrdersnumberCash reserved for pending orderscash.inPiesnumberUninvested cash inside piesinvestments.currentValuenumberCurrent value of all investmentsinvestments.totalCostnumberCost basis of current investmentsinvestments.realizedProfitLossnumberAll-time realized P&Linvestments.unrealizedProfitLossnumberPotential P&L if sold now"
      },
      {
        "title": "Order Types",
        "body": "TypeEndpointAvailabilityDescriptionMarket/api/v0/equity/orders/marketDemo + LiveExecute immediately at best priceLimit/api/v0/equity/orders/limitDemo + LiveExecute at limit price or betterStop/api/v0/equity/orders/stopDemo + LiveMarket order when stop price reachedStopLimit/api/v0/equity/orders/stop_limitDemo + LiveLimit order when stop price reached"
      },
      {
        "title": "Order Statuses",
        "body": "StatusDescriptionLOCALOrder created locally, not yet sentUNCONFIRMEDSent to exchange, awaiting confirmationCONFIRMEDConfirmed by exchangeNEWActive and awaiting executionCANCELLINGCancel request in progressCANCELLEDSuccessfully cancelledPARTIALLY_FILLEDSome shares executedFILLEDCompletely executedREJECTEDRejected by exchangeREPLACINGModification in progressREPLACEDSuccessfully modified"
      },
      {
        "title": "Time Validity",
        "body": "ValueDescriptionDAYExpires at midnight in exchange timezoneGOOD_TILL_CANCELActive until filled or cancelled (default)"
      },
      {
        "title": "Order Strategy",
        "body": "ValueDescriptionQUANTITYOrder by number of shares (API supported)VALUEOrder by monetary value (not supported via API)"
      },
      {
        "title": "Initiated From",
        "body": "ValueDescriptionAPIPlaced via this APIIOSiOS appANDROIDAndroid appWEBWeb platformSYSTEMSystem-generatedAUTOINVESTAutoinvest feature"
      },
      {
        "title": "Place Market Order",
        "body": "POST /api/v0/equity/orders/market (50 req/min)\n\n# Buy 5 shares\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/market\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": 5}'\n\n# Sell 3 shares (negative quantity)\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/market\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": -3}'\n\n# Buy with extended hours enabled\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/market\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": 5, \"extendedHours\": true}'\n\nRequest Fields:\n\nFieldTypeRequiredDescriptiontickerstringYesInstrument ticker (e.g., AAPL_US_EQ)quantitynumberYesPositive for buy, negative for sellextendedHoursbooleanNoSet true to allow execution in pre-market (4:00-9:30 ET) and after-hours (16:00-20:00 ET) sessions. Default: false\n\nResponse:\n\n{\n  \"id\": 123456789,\n  \"type\": \"MARKET\",\n  \"ticker\": \"AAPL_US_EQ\",\n  \"instrument\": {\n    \"ticker\": \"AAPL_US_EQ\",\n    \"name\": \"Apple Inc\",\n    \"isin\": \"US0378331005\",\n    \"currency\": \"USD\"\n  },\n  \"quantity\": 5,\n  \"filledQuantity\": 0,\n  \"status\": \"NEW\",\n  \"side\": \"BUY\",\n  \"strategy\": \"QUANTITY\",\n  \"initiatedFrom\": \"API\",\n  \"extendedHours\": false,\n  \"createdAt\": \"2024-01-15T10:30:00Z\"\n}"
      },
      {
        "title": "Place Limit Order",
        "body": "POST /api/v0/equity/orders/limit (1 req/2s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/limit\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": 5, \"limitPrice\": 150.00, \"timeValidity\": \"DAY\"}'\n\nRequest Fields:\n\nFieldTypeRequiredDescriptiontickerstringYesInstrument tickerquantitynumberYesPositive for buy, negative for selllimitPricenumberYesMaximum price for buy, minimum for selltimeValiditystringNoDAY (default) or GOOD_TILL_CANCEL"
      },
      {
        "title": "Place Stop Order",
        "body": "POST /api/v0/equity/orders/stop (1 req/2s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/stop\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": -5, \"stopPrice\": 140.00, \"timeValidity\": \"GOOD_TILL_CANCEL\"}'\n\nRequest Fields:\n\nFieldTypeRequiredDescriptiontickerstringYesInstrument tickerquantitynumberYesPositive for buy, negative for sellstopPricenumberYesTrigger price (based on Last Traded Price)timeValiditystringNoDAY (default) or GOOD_TILL_CANCEL"
      },
      {
        "title": "Place Stop-Limit Order",
        "body": "POST /api/v0/equity/orders/stop_limit (1 req/2s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/stop_limit\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": -5, \"stopPrice\": 145.00, \"limitPrice\": 140.00, \"timeValidity\": \"DAY\"}'\n\nRequest Fields:\n\nFieldTypeRequiredDescriptiontickerstringYesInstrument tickerquantitynumberYesPositive for buy, negative for sellstopPricenumberYesTrigger price to activate limit orderlimitPricenumberYesLimit price for the resulting ordertimeValiditystringNoDAY (default) or GOOD_TILL_CANCEL"
      },
      {
        "title": "Get Pending Orders",
        "body": "GET /api/v0/equity/orders (1 req/5s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders\"\n\nReturns array of Order objects with status NEW, PARTIALLY_FILLED, etc."
      },
      {
        "title": "Get Order by ID",
        "body": "GET /api/v0/equity/orders/{id} (1 req/1s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/123456789\""
      },
      {
        "title": "Cancel Order",
        "body": "DELETE /api/v0/equity/orders/{id} (50 req/min)\n\ncurl -X DELETE -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/123456789\"\n\nReturns 200 OK if cancellation request accepted. Order may already be filled."
      },
      {
        "title": "Common Order Errors",
        "body": "ErrorCauseSolutionInsufficientFreeForStocksBuyNot enough cashCheck cash.availableToTradeSellingEquityNotOwnedSelling more than ownedCheck quantityAvailableForTradingMarketClosedOutside trading hoursCheck exchange schedule"
      },
      {
        "title": "Get All Positions",
        "body": "GET /api/v0/equity/positions (1 req/1s)\n\nQuery Parameters:\n\nParameterTypeRequiredDescriptiontickerstringNoFilter by specific ticker (e.g., AAPL_US_EQ)\n\n# All positions\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/positions\"\n\n# Filter by ticker\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/positions?ticker=AAPL_US_EQ\"\n\nResponse Schema:\n\n[\n  {\n    \"instrument\": {\n      \"ticker\": \"AAPL_US_EQ\",\n      \"name\": \"Apple Inc\",\n      \"isin\": \"US0378331005\",\n      \"currency\": \"USD\"\n    },\n    \"quantity\": 15.5,\n    \"quantityAvailableForTrading\": 12.5,\n    \"quantityInPies\": 3,\n    \"currentPrice\": 185.5,\n    \"averagePricePaid\": 170.25,\n    \"createdAt\": \"2024-01-10T09:15:00Z\",\n    \"walletImpact\": {\n      \"currency\": \"GBP\",\n      \"totalCost\": 2089.45,\n      \"currentValue\": 2275.1,\n      \"unrealizedProfitLoss\": 185.65,\n      \"fxImpact\": 12.3\n    }\n  }\n]"
      },
      {
        "title": "Position Fields",
        "body": "FieldTypeDescriptionquantitynumberTotal shares ownedquantityAvailableForTradingnumberShares available to sellquantityInPiesnumberShares allocated to piescurrentPricenumberCurrent price (instrument currency)averagePricePaidnumberAverage cost per sharecreatedAtdatetimePosition open datewalletImpact.currencystringAccount currencywalletImpact.totalCostnumberTotal cost in account currencywalletImpact.currentValuenumberCurrent value in account currencywalletImpact.unrealizedProfitLossnumberP&L in account currencywalletImpact.fxImpactnumberCurrency rate impact on value"
      },
      {
        "title": "Position Quantity Scenarios",
        "body": "ScenarioquantityquantityAvailableForTradingquantityInPiesAll direct holdings10100Some in pie1073All in pie10010\n\nImportant: Always check quantityAvailableForTrading before placing sell orders."
      },
      {
        "title": "Ticker Lookup Workflow",
        "body": "When users reference instruments by common names (e.g., \"SAP\", \"Apple\", \"AAPL\"), you must look up the exact Trading 212 ticker before making any order, position, or historical data queries. Never construct ticker formats manually.\n\nCACHE FIRST: Always check /tmp/t212_instruments.json before calling the API. The instruments endpoint has a 50-second rate limit and returns ~5MB. Only call the API if cache is missing or older than 1 hour.\n\nGeneric search: Match the user's search term in the three meaningful fields: ticker, name, or shortName. Use one variable (e.g. SEARCH_TERM) with test($q; \"i\") on each field so \"TSLA\", \"Tesla\", \"TL0\", etc. match efficiently. For regional filtering (e.g. \"US stocks\", \"European SAP\"), use the ISIN prefix (first 2 characters) for country code or currencyCode after the grep.\n\nIMPORTANT: Never auto-select instruments. If multiple options exist, you are required to ask the user for their preference.\n\n# SEARCH_TERM = user query (e.g. TSLA, Tesla, AAPL, SAP)\nSEARCH_TERM=\"TSLA\"\nCACHE_FILE=\"/tmp/t212_instruments.json\"\nif [ -f \"$CACHE_FILE\" ] && [ $(($(date +%s) - $(stat -f %m \"$CACHE_FILE\" 2>/dev/null || stat -c %Y \"$CACHE_FILE\"))) -lt 3600 ]; then\n  # Search ticker, name, or shortName fields\n  jq --arg q \"$SEARCH_TERM\" '[.[] | select((.ticker // \"\" | test($q; \"i\")) or (.name // \"\" | test($q; \"i\")) or (.shortName // \"\" | test($q; \"i\")))]' \"$CACHE_FILE\"\nelse\n  curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL/api/v0/equity/metadata/instruments\" > \"$CACHE_FILE\"\nfi"
      },
      {
        "title": "Get All Instruments",
        "body": "GET /api/v0/equity/metadata/instruments (1 req/50s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/metadata/instruments\"\n\nResponse Schema:\n\n[\n  {\n    \"ticker\": \"AAPL_US_EQ\",\n    \"name\": \"Apple Inc\",\n    \"shortName\": \"AAPL\",\n    \"isin\": \"US0378331005\",\n    \"currencyCode\": \"USD\",\n    \"type\": \"STOCK\",\n    \"maxOpenQuantity\": 10000,\n    \"extendedHours\": true,\n    \"workingScheduleId\": 123,\n    \"addedOn\": \"2020-01-15T00:00:00Z\"\n  }\n]"
      },
      {
        "title": "Instrument Fields",
        "body": "FieldTypeDescriptiontickerstringUnique instrument identifiernamestringFull instrument nameshortNamestringShort symbol (e.g., AAPL)isinstringInternational Securities IDcurrencyCodestringTrading currency (ISO 4217)typestringInstrument type (see below)maxOpenQuantitynumberMaximum position size allowedextendedHoursbooleanWhether extended hours trading is availableworkingScheduleIdintegerReference to exchange scheduleaddedOndatetimeWhen added to platform"
      },
      {
        "title": "Instrument Types",
        "body": "TypeDescriptionSTOCKCommon stockETFExchange-traded fundCRYPTOCURRENCYCryptocurrencyCRYPTOCrypto assetFOREXForeign exchangeFUTURESFutures contractINDEXIndexWARRANTWarrantCVRContingent value rightCORPACTCorporate action"
      },
      {
        "title": "Ticker Format",
        "body": "{SYMBOL}_{EXCHANGE}_{TYPE} - Examples:\n\nAAPL_US_EQ - Apple on US exchange\nVUSA_LSE_EQ - Vanguard S&P 500 on London\nBTC_CRYPTO - Bitcoin"
      },
      {
        "title": "Get Exchange Metadata",
        "body": "GET /api/v0/equity/metadata/exchanges (1 req/30s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/metadata/exchanges\"\n\nResponse Schema:\n\n[\n  {\n    \"id\": 123,\n    \"name\": \"NASDAQ\",\n    \"workingSchedules\": [\n      {\n        \"id\": 456,\n        \"timeEvents\": [\n          { \"type\": \"PRE_MARKET_OPEN\", \"date\": \"2024-01-15T09:00:00Z\" },\n          { \"type\": \"OPEN\", \"date\": \"2024-01-15T14:30:00Z\" },\n          { \"type\": \"CLOSE\", \"date\": \"2024-01-15T21:00:00Z\" },\n          { \"type\": \"AFTER_HOURS_CLOSE\", \"date\": \"2024-01-15T01:00:00Z\" }\n        ]\n      }\n    ]\n  }\n]"
      },
      {
        "title": "Time Event Types",
        "body": "TypeDescriptionPRE_MARKET_OPENPre-market session startsOPENRegular trading startsBREAK_STARTTrading break beginsBREAK_ENDTrading break endsCLOSERegular trading endsAFTER_HOURS_OPENAfter-hours session startsAFTER_HOURS_CLOSEAfter-hours session endsOVERNIGHT_OPENOvernight session starts"
      },
      {
        "title": "Historical Data",
        "body": "All historical endpoints use cursor-based pagination with nextPagePath."
      },
      {
        "title": "Pagination Parameters",
        "body": "ParameterTypeDefaultMaxDescriptionlimitinteger2050Items per pagecursorstring/number--Pagination cursor (used in nextPagePath)tickerstring--Filter by ticker (orders, dividends)timedatetime--Pagination time (used in nextPagePath for transactions)"
      },
      {
        "title": "Pagination Example",
        "body": "#!/bin/bash\n# Fetch all historical orders with pagination\n\nNEXT_PATH=\"/api/v0/equity/history/orders?limit=50\"\n\nwhile [ -n \"$NEXT_PATH\" ]; do\n  echo \"Fetching: $NEXT_PATH\"\n\n  RESPONSE=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL$NEXT_PATH\")\n\n  # Process items (e.g., save to file)\n  echo \"$RESPONSE\" | jq '.items[]' >> orders.json\n\n  # Get next page path (null if no more pages)\n  NEXT_PATH=$(echo \"$RESPONSE\" | jq -r '.nextPagePath // empty')\n\n  # Wait 1 second between requests (50 req/min limit)\n  if [ -n \"$NEXT_PATH\" ]; then\n    sleep 1\n  fi\ndone\n\necho \"Done fetching all orders\""
      },
      {
        "title": "Historical Orders",
        "body": "GET /api/v0/equity/history/orders (50 req/min)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/orders?limit=50\"\n\n# Filter by ticker\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/orders?ticker=AAPL_US_EQ&limit=50\"\n\nResponse Schema:\n\n{\n  \"items\": [\n    {\n      \"order\": {\n        \"id\": 123456789,\n        \"type\": \"MARKET\",\n        \"ticker\": \"AAPL_US_EQ\",\n        \"instrument\": {\n          \"ticker\": \"AAPL_US_EQ\",\n          \"name\": \"Apple Inc\",\n          \"isin\": \"US0378331005\",\n          \"currency\": \"USD\"\n        },\n        \"quantity\": 5,\n        \"filledQuantity\": 5,\n        \"status\": \"FILLED\",\n        \"side\": \"BUY\",\n        \"createdAt\": \"2024-01-15T10:30:00Z\"\n      },\n      \"fill\": {\n        \"id\": 987654321,\n        \"type\": \"TRADE\",\n        \"quantity\": 5,\n        \"price\": 185.5,\n        \"filledAt\": \"2024-01-15T10:30:05Z\",\n        \"tradingMethod\": \"TOTV\",\n        \"walletImpact\": {\n          \"currency\": \"GBP\",\n          \"fxRate\": 0.79,\n          \"netValue\": 732.72,\n          \"realisedProfitLoss\": 0,\n          \"taxes\": [\n            { \"name\": \"STAMP_DUTY\", \"quantity\": 3.66, \"currency\": \"GBP\" }\n          ]\n        }\n      }\n    }\n  ],\n  \"nextPagePath\": \"/api/v0/equity/history/orders?limit=50&cursor=1705326600000\"\n}"
      },
      {
        "title": "Fill Types",
        "body": "TypeDescriptionTRADERegular trade executionSTOCK_SPLITStock split adjustmentSTOCK_DISTRIBUTIONStock distributionFOPFree of payment transferFOP_CORRECTIONFOP correctionCUSTOM_STOCK_DISTRIBUTIONCustom stock distributionEQUITY_RIGHTSEquity rights issue"
      },
      {
        "title": "Trading Methods",
        "body": "MethodDescriptionTOTVTraded on trading venueOTCOver-the-counter"
      },
      {
        "title": "Tax Types (walletImpact.taxes)",
        "body": "TypeDescriptionCOMMISSION_TURNOVERCommission on turnoverCURRENCY_CONVERSION_FEEFX conversion feeFINRA_FEEFINRA trading activity feeFRENCH_TRANSACTION_TAXFrench FTTPTM_LEVYPanel on Takeovers levySTAMP_DUTYUK stamp dutySTAMP_DUTY_RESERVE_TAXUK SDRTTRANSACTION_FEEGeneral transaction fee"
      },
      {
        "title": "Historical Dividends",
        "body": "GET /api/v0/equity/history/dividends (50 req/min)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/dividends?limit=50\"\n\n# Filter by ticker\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/dividends?ticker=AAPL_US_EQ&limit=50\"\n\nResponse Schema:\n\n{\n  \"items\": [\n    {\n      \"ticker\": \"AAPL_US_EQ\",\n      \"instrument\": {\n        \"ticker\": \"AAPL_US_EQ\",\n        \"name\": \"Apple Inc\",\n        \"isin\": \"US0378331005\",\n        \"currency\": \"USD\"\n      },\n      \"type\": \"ORDINARY\",\n      \"amount\": 12.5,\n      \"amountInEuro\": 14.7,\n      \"currency\": \"GBP\",\n      \"tickerCurrency\": \"USD\",\n      \"grossAmountPerShare\": 0.24,\n      \"quantity\": 65.5,\n      \"paidOn\": \"2024-02-15T00:00:00Z\",\n      \"reference\": \"DIV-123456\"\n    }\n  ],\n  \"nextPagePath\": null\n}"
      },
      {
        "title": "Dividend Types (Common)",
        "body": "TypeDescriptionORDINARYRegular dividendBONUSBonus dividendINTERESTInterest paymentDIVIDENDGeneric dividendCAPITAL_GAINSCapital gains distributionRETURN_OF_CAPITALReturn of capitalPROPERTY_INCOMEProperty income (REITs)DEMERGERDemerger distributionQUALIFIED_INVESTMENT_ENTITYQIE distributionTRUST_DISTRIBUTIONTrust distribution\n\nNote: Many additional US tax-specific types exist for 1042-S reporting."
      },
      {
        "title": "Account Transactions",
        "body": "GET /api/v0/equity/history/transactions (50 req/min)\n\nPagination:\n\nFirst request: Must use only the limit parameter (no cursor, no timestamp)\nSubsequent requests: Use the nextPagePath from the previous response, which includes cursor and timestamp automatically\nTime filtering: Transactions cannot be filtered by time - pagination is the only way to navigate through historical data\n\n# First request - use only limit\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/transactions?limit=50\"\n\nResponse Schema:\n\n{\n  \"items\": [\n    {\n      \"type\": \"DEPOSIT\",\n      \"amount\": 1000.0,\n      \"currency\": \"GBP\",\n      \"dateTime\": \"2024-01-10T14:30:00Z\",\n      \"reference\": \"TXN-123456\"\n    }\n  ],\n  \"nextPagePath\": null\n}"
      },
      {
        "title": "Transaction Types",
        "body": "TypeDescriptionDEPOSITFunds deposited to accountWITHDRAWFunds withdrawn from accountFEEFee chargedTRANSFERInternal transfer"
      },
      {
        "title": "CSV Reports",
        "body": "Request report: POST /api/v0/equity/history/exports (1 req/30s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/exports\" \\\n  -d '{\n    \"dataIncluded\": {\n      \"includeDividends\": true,\n      \"includeInterest\": true,\n      \"includeOrders\": true,\n      \"includeTransactions\": true\n    },\n    \"timeFrom\": \"2024-01-01T00:00:00Z\",\n    \"timeTo\": \"2024-12-31T23:59:59Z\"\n  }'\n\nResponse:\n\n{\n  \"reportId\": 12345\n}\n\nPoll for completion: GET /api/v0/equity/history/exports (1 req/min)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/exports\"\n\nResponse:\n\n[\n  {\n    \"reportId\": 12345,\n    \"status\": \"Finished\",\n    \"dataIncluded\": {\n      \"includeDividends\": true,\n      \"includeInterest\": true,\n      \"includeOrders\": true,\n      \"includeTransactions\": true\n    },\n    \"timeFrom\": \"2024-01-01T00:00:00Z\",\n    \"timeTo\": \"2024-12-31T23:59:59Z\",\n    \"downloadLink\": \"https://trading212-reports.s3.amazonaws.com/...\"\n  }\n]\n\nDownload the report:\n\n# Get the download link from the response\nDOWNLOAD_URL=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/exports\" | jq -r '.[0].downloadLink')\n\n# Download the CSV file\ncurl -o trading212_report.csv \"$DOWNLOAD_URL\""
      },
      {
        "title": "Report Status Values",
        "body": "StatusDescriptionQueuedReport request receivedProcessingReport generation startedRunningReport actively generatingFinishedComplete - downloadLink availableCanceledReport cancelledFailedGeneration failed"
      },
      {
        "title": "Before BUY - Check Available Funds",
        "body": "#!/bin/bash\n# Validate funds before placing a buy order\n\nTICKER=\"AAPL_US_EQ\"\nQUANTITY=10\nESTIMATED_PRICE=185.00\nESTIMATED_COST=$(echo \"$QUANTITY * $ESTIMATED_PRICE\" | bc)\n\n# Get available funds\nAVAILABLE=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/account/summary\" | jq '.cash.availableToTrade')\n\necho \"Estimated cost: $ESTIMATED_COST\"\necho \"Available funds: $AVAILABLE\"\n\nif (( $(echo \"$ESTIMATED_COST > $AVAILABLE\" | bc -l) )); then\n  echo \"ERROR: Insufficient funds\"\n  exit 1\nfi\n\necho \"OK: Funds available, proceeding with order\""
      },
      {
        "title": "Before SELL - Check Available Shares",
        "body": "#!/bin/bash\n# Validate position before placing a sell order\n\nTICKER=\"AAPL_US_EQ\"\nSELL_QUANTITY=5\n\n# Get position for the ticker\nPOSITION=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/positions?ticker=$TICKER\")\n\nAVAILABLE_QTY=$(echo \"$POSITION\" | jq '.[0].quantityAvailableForTrading // 0')\n\necho \"Sell quantity: $SELL_QUANTITY\"\necho \"Available to sell: $AVAILABLE_QTY\"\n\nif (( $(echo \"$SELL_QUANTITY > $AVAILABLE_QTY\" | bc -l) )); then\n  echo \"ERROR: Insufficient shares (some may be in pies)\"\n  exit 1\nfi\n\necho \"OK: Shares available, proceeding with order\""
      },
      {
        "title": "Understanding Rate Limits",
        "body": "Rate limits are per-account, not per API key or IP address. If you have multiple applications using the same Trading 212 account, they share the same rate limit pool."
      },
      {
        "title": "Response Headers",
        "body": "Every API response includes rate limit headers:\n\nHeaderDescriptionx-ratelimit-limitTotal requests allowed in periodx-ratelimit-periodTime period in secondsx-ratelimit-remainingRequests remainingx-ratelimit-resetUnix timestamp when limit resetsx-ratelimit-usedRequests already made"
      },
      {
        "title": "Avoid Burst Requests to avoid Rate Limiting",
        "body": "Do not send requests in bursts. Even if an endpoint allows 50 requests per minute, sending them all at once can trigger rate limiting and degrade performance.\nPace your requests evenly, for example, by making one call every 1.2 seconds, ensuring you always stay within the limit.\n\nBad approach (bursting):\n\n# DON'T DO THIS - sends all requests at once\nfor ticker in AAPL_US_EQ MSFT_US_EQ GOOGL_US_EQ; do\n  curl -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL/api/v0/equity/positions?ticker=$ticker\" &\ndone\nwait\n\nGood approach (paced):\n\n# DO THIS - space requests evenly\nfor ticker in AAPL_US_EQ MSFT_US_EQ GOOGL_US_EQ; do\n  curl -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL/api/v0/equity/positions?ticker=$ticker\"\n  sleep 1.2  # 1.2 second between requests for 50 req/m limit\ndone"
      },
      {
        "title": "Caching Strategy",
        "body": "For data that doesn't change frequently, cache locally to reduce API calls:\n\n#!/bin/bash\n# Cache instruments list (changes rarely)\n\nCACHE_FILE=\"/tmp/t212_instruments.json\"\nCACHE_MAX_AGE=3600  # 1 hour\n\nif [ -f \"$CACHE_FILE\" ]; then\n  CACHE_AGE=$(($(date +%s) - $(stat -f %m \"$CACHE_FILE\")))\n  if [ \"$CACHE_AGE\" -lt \"$CACHE_MAX_AGE\" ]; then\n    cat \"$CACHE_FILE\"\n    exit 0\n  fi\nfi\n\n# Cache expired or doesn't exist - fetch fresh data\ncurl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/metadata/instruments\" > \"$CACHE_FILE\"\n\ncat \"$CACHE_FILE\""
      },
      {
        "title": "Safety Guidelines",
        "body": "Test in demo first - Always validate workflows before live trading\nValidate before ordering - Check funds (cash.availableToTrade) before buy, positions (quantityAvailableForTrading) before sell\nConfirm destructive actions - Order placement and cancellation are irreversible\nAPI is not idempotent - Duplicate requests may create duplicate orders\nNever log credentials - Use environment variables\nRespect rate limits - Space requests evenly, never burst\nMax 50 pending orders - Per ticker, per account\nCache metadata - Instruments and exchanges change rarely"
      }
    ],
    "body": "Trading 212 API\n\nNote: The Trading 212 API is currently in beta and under active development. Some endpoints or behaviors may change.\n\nQuick Reference\nEnvironments\nEnvironment\tBase URL\tPurpose\nDemo\thttps://demo.trading212.com/api/v0\tPaper trading - test without real funds\nLive\thttps://live.trading212.com/api/v0\tReal money trading\nOrder Quantity Convention\nPositive quantity = BUY (e.g., 10 buys 10 shares)\nNegative quantity = SELL (e.g., -10 sells 10 shares)\nAccount Types\n\nOnly Invest and Stocks ISA accounts are supported.\n\nInstrument Identifiers\n\nTrading 212 uses custom tickers as unique identifiers for instruments. Always search for the Trading 212 ticker before making instrument requests.\n\nAuthentication\n\nHTTP Basic Auth with API Key (username) and API Secret (password).\n\nCheck Existing Setup First\n\nBefore guiding the user through authentication setup, check if credentials are already configured:\n\nSemantic 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.\n\n# Example: configured if any complete credential set exists\nif [ -n \"$T212_AUTH_HEADER\" ] && [ -n \"$T212_BASE_URL\" ]; then\n  echo \"Configured (derived vars)\"\nelif [ -n \"$T212_API_KEY\" ] && [ -n \"$T212_API_SECRET\" ]; then\n  echo \"Configured (single account)\"\nelif [ -n \"$T212_API_KEY_INVEST\" ] && [ -n \"$T212_API_SECRET_INVEST\" ]; then\n  echo \"Configured (Invest); Stocks ISA also if T212_API_KEY_STOCKS_ISA and T212_API_SECRET_STOCKS_ISA are set\"\nelif [ -n \"$T212_API_KEY_STOCKS_ISA\" ] && [ -n \"$T212_API_SECRET_STOCKS_ISA\" ]; then\n  echo \"Configured (Stocks ISA); Invest also if T212_API_KEY_INVEST and T212_API_SECRET_INVEST are set\"\nelse\n  echo \"No complete credential set found\"\nfi\n\n\nIf 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.\n\nImportant: 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.\n\nAPI Keys Are Environment-Specific\n\nAPI keys are tied to a specific environment and cannot be used across environments.\n\nAPI Key Created In\tWorks With\tDoes NOT Work With\nLIVE account\tlive.trading212.com\tdemo.trading212.com\nDEMO account\tdemo.trading212.com\tlive.trading212.com\n\nIf you get a 401 error, verify that:\n\nYou're using the correct API key for the target environment\nThe API key was generated in the same environment (LIVE or DEMO) you're trying to access\nGet Credentials\nDecide which environment to use - LIVE (real money) or DEMO (paper trading)\nOpen Trading 212 app (mobile or web)\nSwitch to the correct account - Make sure you're in LIVE or DEMO mode matching your target environment\nNavigate to Settings > API\nGenerate a new API key pair - you'll receive:\nAPI Key (ID) (e.g., 35839398ZFVKUxpHzPiVsxKdOtZdaDJSrvyPF)\nAPI Secret (e.g., 7MOzYJlVJgxoPjdZJCEH3fO9ee7A0NzLylFFD4-3tlo)\nStore the credentials separately for each environment if you use both\nBuilding the Auth Header\n\nCombine your API Key (ID) and Secret with a colon, base64 encode, and prefix with Basic for the Authorization header.\n\nOptional: To precompute the header from key/secret, you can set:\n\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64)\"\n\n\nOtherwise, the agent builds the header from T212_API_KEY and T212_API_SECRET when making requests.\n\nManual (placeholders):\n\n# Format: T212_AUTH_HEADER = \"Basic \" + base64(API_KEY_ID:API_SECRET)\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"<YOUR_API_KEY_ID>:<YOUR_API_SECRET>\" | base64)\"\n\n# Example with sample credentials:\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"35839398ZFVKUxpHzPiVsxKdOtZdaDJSrvyPF:7MOzYJlVJgxoPjdZJCEH3fO9ee7A0NzLylFFD4-3tlo\" | base64)\"\n\nMaking Requests\n\nWhen making API calls, use the first option that applies (semantically: pick the credential set that matches the user's account, or the only set present):\n\nIf T212_AUTH_HEADER and T212_BASE_URL are set: use them in requests.\nElse if T212_API_KEY and T212_API_SECRET are set: use this pair (single account). Build header as Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64) and base URL as https://${T212_ENV:-live}.trading212.com. Do not guide the user to derive or merge; you do it.\nElse if both account-specific pairs are set (T212_API_KEY_INVEST/T212_API_SECRET_INVEST and T212_API_KEY_STOCKS_ISA/T212_API_SECRET_STOCKS_ISA): the user must clearly specify which account to target (Invest or Stocks ISA), unless they ask for information for all accounts. Use the Invest pair when the user refers to Invest, and the Stocks ISA pair when the user refers to ISA/Stocks ISA. If the user wants information for all accounts, make multiple API calls—one per account (Invest and Stocks ISA)—and present or aggregate the results for both. If it is not clear from context which account to use (and they did not ask for all accounts), ask for confirmation before making API calls (e.g. \"Which account should I use — Invest or Stocks ISA?\"). Do not assume. Build the header from the chosen key/secret and base URL as https://${T212_ENV:-live}.trading212.com.\nElse if only the Invest pair is set (T212_API_KEY_INVEST and T212_API_SECRET_INVEST): use this pair for requests; if the user asks about Stocks ISA, only the Invest account is configured.\nElse if only the Stocks ISA pair is set (T212_API_KEY_STOCKS_ISA and T212_API_SECRET_STOCKS_ISA): use this pair for requests; if the user asks about Invest, only the Stocks ISA account is configured.\n\nUse the T212_AUTH_HEADER value in the Authorization header when it is set:\n\n# When T212_AUTH_HEADER and T212_BASE_URL are set:\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"${T212_BASE_URL}/api/v0/equity/account/summary\"\n\n\nWhen only primary vars are set, use the inline form in the curl:\n\n# When only T212_API_KEY, T212_API_SECRET, T212_ENV are set:\ncurl -H \"Authorization: Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64)\" \\\n  \"https://${T212_ENV:-live}.trading212.com/api/v0/equity/account/summary\"\n\n\nWarning: T212_AUTH_HEADER must be the full header value including the Basic prefix.\n\n# WRONG - raw base64 without \"Basic \" prefix\ncurl -H \"Authorization: <base64-only>\" ...  # This will NOT work!\n\n# CORRECT - use T212_AUTH_HEADER (contains \"Basic <base64>\")\ncurl -H \"Authorization: $T212_AUTH_HEADER\" ...  # This works\n\nEnvironment Variables\n\nSingle account vs all accounts: API keys are for a single account. One key/secret pair (T212_API_KEY + T212_API_SECRET) = one account (Invest or Stocks ISA). To use all accounts (Invest and Stocks ISA), the user must set two sets of key/secret: T212_API_KEY_INVEST / T212_API_SECRET_INVEST and T212_API_KEY_STOCKS_ISA / T212_API_SECRET_STOCKS_ISA. When both pairs are set, the user must clearly specify which account to target; if it is not clear from context, ask for confirmation (Invest or Stocks ISA) before making API calls.\n\nPrimary (single account): Set these for consistent setup with the plugin README:\n\nexport T212_API_KEY=\"your-api-key\"       # API Key (ID) from Trading 212\nexport T212_API_SECRET=\"your-api-secret\"\nexport T212_ENV=\"demo\"                   # or \"live\" (defaults to \"live\" if unset)\n\n\nAccount-specific (Invest and/or Stocks ISA): Set only the pair(s) you use. One complete set (key + secret for the same account) is enough. For example, only Invest:\n\nexport T212_API_KEY_INVEST=\"your-invest-api-key\"\nexport T212_API_SECRET_INVEST=\"your-invest-api-secret\"\nexport T212_ENV=\"demo\"                   # or \"live\"\n\n\nFor both accounts, set both pairs:\n\nexport T212_API_KEY_INVEST=\"your-invest-api-key\"\nexport T212_API_SECRET_INVEST=\"your-invest-api-secret\"\nexport T212_API_KEY_STOCKS_ISA=\"your-stocks-isa-api-key\"\nexport T212_API_SECRET_STOCKS_ISA=\"your-stocks-isa-api-secret\"\nexport T212_ENV=\"demo\"                   # or \"live\" (applies to both)\n\n\nOptional – precomputed (for scripts or if the user prefers): The user can set the auth header and base URL from the primary vars, but they do not need to; when making API calls you (the agent) must build the header and base URL from primary vars if these are not set.\n\n# Build auth header and base URL from T212_API_KEY, T212_API_SECRET, T212_ENV\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"$T212_API_KEY:$T212_API_SECRET\" | base64)\"\nexport T212_BASE_URL=\"https://${T212_ENV:-live}.trading212.com\"\n\n\nAlternative (manual): If you prefer not to store key/secret in env, set derived vars directly. Remember: API keys only work with their matching environment.\n\n# For DEMO (paper trading)\nexport T212_AUTH_HEADER=\"Basic $(echo -n \"<DEMO_API_KEY_ID>:<DEMO_API_SECRET>\" | base64)\"\nexport T212_BASE_URL=\"https://demo.trading212.com\"\n\n# For LIVE (real money) - generate separate credentials in LIVE account\n# export T212_AUTH_HEADER=\"Basic $(echo -n \"<LIVE_API_KEY_ID>:<LIVE_API_SECRET>\" | base64)\"\n# export T212_BASE_URL=\"https://live.trading212.com\"\n\n\nTip: If you use both environments, use separate variable names:\n\n# Demo credentials\nexport T212_DEMO_AUTH_HEADER=\"Basic $(echo -n \"<DEMO_KEY_ID>:<DEMO_SECRET>\" | base64)\"\n\n# Live credentials\nexport T212_LIVE_AUTH_HEADER=\"Basic $(echo -n \"<LIVE_KEY_ID>:<LIVE_SECRET>\" | base64)\"\n\nCommon Auth Errors\nCode\tCause\tSolution\n401\tInvalid credentials\tCheck API key/secret, ensure no extra whitespace\n401\tEnvironment mismatch\tLIVE API keys don't work with DEMO and vice versa - verify key matches target environment\n403\tMissing permissions\tCheck API permissions in Trading 212 settings\n408\tRequest timed out\tRetry the request\n429\tRate limit exceeded\tWait for x-ratelimit-reset timestamp\nAccount\nGet Account Summary\n\nGET /api/v0/equity/account/summary (1 req/5s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/account/summary\"\n\n\nResponse Schema:\n\n{\n  \"id\": 12345678,\n  \"currency\": \"GBP\",\n  \"totalValue\": 15250.75,\n  \"cash\": {\n    \"availableToTrade\": 2500.5,\n    \"reservedForOrders\": 150.0,\n    \"inPies\": 500.0\n  },\n  \"investments\": {\n    \"currentValue\": 12100.25,\n    \"totalCost\": 10500.0,\n    \"realizedProfitLoss\": 850.5,\n    \"unrealizedProfitLoss\": 1600.25\n  }\n}\n\nAccount Fields\nField\tType\tDescription\nid\tinteger\tPrimary trading account number\ncurrency\tstring\tPrimary account currency (ISO 4217)\ntotalValue\tnumber\tTotal account value in primary currency\ncash.availableToTrade\tnumber\tFunds available for investing\ncash.reservedForOrders\tnumber\tCash reserved for pending orders\ncash.inPies\tnumber\tUninvested cash inside pies\ninvestments.currentValue\tnumber\tCurrent value of all investments\ninvestments.totalCost\tnumber\tCost basis of current investments\ninvestments.realizedProfitLoss\tnumber\tAll-time realized P&L\ninvestments.unrealizedProfitLoss\tnumber\tPotential P&L if sold now\nOrders\nOrder Types\nType\tEndpoint\tAvailability\tDescription\nMarket\t/api/v0/equity/orders/market\tDemo + Live\tExecute immediately at best price\nLimit\t/api/v0/equity/orders/limit\tDemo + Live\tExecute at limit price or better\nStop\t/api/v0/equity/orders/stop\tDemo + Live\tMarket order when stop price reached\nStopLimit\t/api/v0/equity/orders/stop_limit\tDemo + Live\tLimit order when stop price reached\nOrder Statuses\nStatus\tDescription\nLOCAL\tOrder created locally, not yet sent\nUNCONFIRMED\tSent to exchange, awaiting confirmation\nCONFIRMED\tConfirmed by exchange\nNEW\tActive and awaiting execution\nCANCELLING\tCancel request in progress\nCANCELLED\tSuccessfully cancelled\nPARTIALLY_FILLED\tSome shares executed\nFILLED\tCompletely executed\nREJECTED\tRejected by exchange\nREPLACING\tModification in progress\nREPLACED\tSuccessfully modified\nTime Validity\nValue\tDescription\nDAY\tExpires at midnight in exchange timezone\nGOOD_TILL_CANCEL\tActive until filled or cancelled (default)\nOrder Strategy\nValue\tDescription\nQUANTITY\tOrder by number of shares (API supported)\nVALUE\tOrder by monetary value (not supported via API)\nInitiated From\nValue\tDescription\nAPI\tPlaced via this API\nIOS\tiOS app\nANDROID\tAndroid app\nWEB\tWeb platform\nSYSTEM\tSystem-generated\nAUTOINVEST\tAutoinvest feature\nPlace Market Order\n\nPOST /api/v0/equity/orders/market (50 req/min)\n\n# Buy 5 shares\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/market\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": 5}'\n\n# Sell 3 shares (negative quantity)\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/market\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": -3}'\n\n# Buy with extended hours enabled\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/market\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": 5, \"extendedHours\": true}'\n\n\nRequest Fields:\n\nField\tType\tRequired\tDescription\nticker\tstring\tYes\tInstrument ticker (e.g., AAPL_US_EQ)\nquantity\tnumber\tYes\tPositive for buy, negative for sell\nextendedHours\tboolean\tNo\tSet true to allow execution in pre-market (4:00-9:30 ET) and after-hours (16:00-20:00 ET) sessions. Default: false\n\nResponse:\n\n{\n  \"id\": 123456789,\n  \"type\": \"MARKET\",\n  \"ticker\": \"AAPL_US_EQ\",\n  \"instrument\": {\n    \"ticker\": \"AAPL_US_EQ\",\n    \"name\": \"Apple Inc\",\n    \"isin\": \"US0378331005\",\n    \"currency\": \"USD\"\n  },\n  \"quantity\": 5,\n  \"filledQuantity\": 0,\n  \"status\": \"NEW\",\n  \"side\": \"BUY\",\n  \"strategy\": \"QUANTITY\",\n  \"initiatedFrom\": \"API\",\n  \"extendedHours\": false,\n  \"createdAt\": \"2024-01-15T10:30:00Z\"\n}\n\nPlace Limit Order\n\nPOST /api/v0/equity/orders/limit (1 req/2s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/limit\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": 5, \"limitPrice\": 150.00, \"timeValidity\": \"DAY\"}'\n\n\nRequest Fields:\n\nField\tType\tRequired\tDescription\nticker\tstring\tYes\tInstrument ticker\nquantity\tnumber\tYes\tPositive for buy, negative for sell\nlimitPrice\tnumber\tYes\tMaximum price for buy, minimum for sell\ntimeValidity\tstring\tNo\tDAY (default) or GOOD_TILL_CANCEL\nPlace Stop Order\n\nPOST /api/v0/equity/orders/stop (1 req/2s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/stop\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": -5, \"stopPrice\": 140.00, \"timeValidity\": \"GOOD_TILL_CANCEL\"}'\n\n\nRequest Fields:\n\nField\tType\tRequired\tDescription\nticker\tstring\tYes\tInstrument ticker\nquantity\tnumber\tYes\tPositive for buy, negative for sell\nstopPrice\tnumber\tYes\tTrigger price (based on Last Traded Price)\ntimeValidity\tstring\tNo\tDAY (default) or GOOD_TILL_CANCEL\nPlace Stop-Limit Order\n\nPOST /api/v0/equity/orders/stop_limit (1 req/2s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/stop_limit\" \\\n  -d '{\"ticker\": \"AAPL_US_EQ\", \"quantity\": -5, \"stopPrice\": 145.00, \"limitPrice\": 140.00, \"timeValidity\": \"DAY\"}'\n\n\nRequest Fields:\n\nField\tType\tRequired\tDescription\nticker\tstring\tYes\tInstrument ticker\nquantity\tnumber\tYes\tPositive for buy, negative for sell\nstopPrice\tnumber\tYes\tTrigger price to activate limit order\nlimitPrice\tnumber\tYes\tLimit price for the resulting order\ntimeValidity\tstring\tNo\tDAY (default) or GOOD_TILL_CANCEL\nGet Pending Orders\n\nGET /api/v0/equity/orders (1 req/5s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders\"\n\n\nReturns array of Order objects with status NEW, PARTIALLY_FILLED, etc.\n\nGet Order by ID\n\nGET /api/v0/equity/orders/{id} (1 req/1s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/123456789\"\n\nCancel Order\n\nDELETE /api/v0/equity/orders/{id} (50 req/min)\n\ncurl -X DELETE -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/orders/123456789\"\n\n\nReturns 200 OK if cancellation request accepted. Order may already be filled.\n\nCommon Order Errors\nError\tCause\tSolution\nInsufficientFreeForStocksBuy\tNot enough cash\tCheck cash.availableToTrade\nSellingEquityNotOwned\tSelling more than owned\tCheck quantityAvailableForTrading\nMarketClosed\tOutside trading hours\tCheck exchange schedule\nPositions\nGet All Positions\n\nGET /api/v0/equity/positions (1 req/1s)\n\nQuery Parameters:\n\nParameter\tType\tRequired\tDescription\nticker\tstring\tNo\tFilter by specific ticker (e.g., AAPL_US_EQ)\n# All positions\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/positions\"\n\n# Filter by ticker\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/positions?ticker=AAPL_US_EQ\"\n\n\nResponse Schema:\n\n[\n  {\n    \"instrument\": {\n      \"ticker\": \"AAPL_US_EQ\",\n      \"name\": \"Apple Inc\",\n      \"isin\": \"US0378331005\",\n      \"currency\": \"USD\"\n    },\n    \"quantity\": 15.5,\n    \"quantityAvailableForTrading\": 12.5,\n    \"quantityInPies\": 3,\n    \"currentPrice\": 185.5,\n    \"averagePricePaid\": 170.25,\n    \"createdAt\": \"2024-01-10T09:15:00Z\",\n    \"walletImpact\": {\n      \"currency\": \"GBP\",\n      \"totalCost\": 2089.45,\n      \"currentValue\": 2275.1,\n      \"unrealizedProfitLoss\": 185.65,\n      \"fxImpact\": 12.3\n    }\n  }\n]\n\nPosition Fields\nField\tType\tDescription\nquantity\tnumber\tTotal shares owned\nquantityAvailableForTrading\tnumber\tShares available to sell\nquantityInPies\tnumber\tShares allocated to pies\ncurrentPrice\tnumber\tCurrent price (instrument currency)\naveragePricePaid\tnumber\tAverage cost per share\ncreatedAt\tdatetime\tPosition open date\nwalletImpact.currency\tstring\tAccount currency\nwalletImpact.totalCost\tnumber\tTotal cost in account currency\nwalletImpact.currentValue\tnumber\tCurrent value in account currency\nwalletImpact.unrealizedProfitLoss\tnumber\tP&L in account currency\nwalletImpact.fxImpact\tnumber\tCurrency rate impact on value\nPosition Quantity Scenarios\nScenario\tquantity\tquantityAvailableForTrading\tquantityInPies\nAll direct holdings\t10\t10\t0\nSome in pie\t10\t7\t3\nAll in pie\t10\t0\t10\n\nImportant: Always check quantityAvailableForTrading before placing sell orders.\n\nInstruments\nTicker Lookup Workflow\n\nWhen users reference instruments by common names (e.g., \"SAP\", \"Apple\", \"AAPL\"), you must look up the exact Trading 212 ticker before making any order, position, or historical data queries. Never construct ticker formats manually.\n\nCACHE FIRST: Always check /tmp/t212_instruments.json before calling the API. The instruments endpoint has a 50-second rate limit and returns ~5MB. Only call the API if cache is missing or older than 1 hour.\n\nGeneric search: Match the user's search term in the three meaningful fields: ticker, name, or shortName. Use one variable (e.g. SEARCH_TERM) with test($q; \"i\") on each field so \"TSLA\", \"Tesla\", \"TL0\", etc. match efficiently. For regional filtering (e.g. \"US stocks\", \"European SAP\"), use the ISIN prefix (first 2 characters) for country code or currencyCode after the grep.\n\nIMPORTANT: Never auto-select instruments. If multiple options exist, you are required to ask the user for their preference.\n\n# SEARCH_TERM = user query (e.g. TSLA, Tesla, AAPL, SAP)\nSEARCH_TERM=\"TSLA\"\nCACHE_FILE=\"/tmp/t212_instruments.json\"\nif [ -f \"$CACHE_FILE\" ] && [ $(($(date +%s) - $(stat -f %m \"$CACHE_FILE\" 2>/dev/null || stat -c %Y \"$CACHE_FILE\"))) -lt 3600 ]; then\n  # Search ticker, name, or shortName fields\n  jq --arg q \"$SEARCH_TERM\" '[.[] | select((.ticker // \"\" | test($q; \"i\")) or (.name // \"\" | test($q; \"i\")) or (.shortName // \"\" | test($q; \"i\")))]' \"$CACHE_FILE\"\nelse\n  curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL/api/v0/equity/metadata/instruments\" > \"$CACHE_FILE\"\nfi\n\nGet All Instruments\n\nGET /api/v0/equity/metadata/instruments (1 req/50s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/metadata/instruments\"\n\n\nResponse Schema:\n\n[\n  {\n    \"ticker\": \"AAPL_US_EQ\",\n    \"name\": \"Apple Inc\",\n    \"shortName\": \"AAPL\",\n    \"isin\": \"US0378331005\",\n    \"currencyCode\": \"USD\",\n    \"type\": \"STOCK\",\n    \"maxOpenQuantity\": 10000,\n    \"extendedHours\": true,\n    \"workingScheduleId\": 123,\n    \"addedOn\": \"2020-01-15T00:00:00Z\"\n  }\n]\n\nInstrument Fields\nField\tType\tDescription\nticker\tstring\tUnique instrument identifier\nname\tstring\tFull instrument name\nshortName\tstring\tShort symbol (e.g., AAPL)\nisin\tstring\tInternational Securities ID\ncurrencyCode\tstring\tTrading currency (ISO 4217)\ntype\tstring\tInstrument type (see below)\nmaxOpenQuantity\tnumber\tMaximum position size allowed\nextendedHours\tboolean\tWhether extended hours trading is available\nworkingScheduleId\tinteger\tReference to exchange schedule\naddedOn\tdatetime\tWhen added to platform\nInstrument Types\nType\tDescription\nSTOCK\tCommon stock\nETF\tExchange-traded fund\nCRYPTOCURRENCY\tCryptocurrency\nCRYPTO\tCrypto asset\nFOREX\tForeign exchange\nFUTURES\tFutures contract\nINDEX\tIndex\nWARRANT\tWarrant\nCVR\tContingent value right\nCORPACT\tCorporate action\nTicker Format\n\n{SYMBOL}_{EXCHANGE}_{TYPE} - Examples:\n\nAAPL_US_EQ - Apple on US exchange\nVUSA_LSE_EQ - Vanguard S&P 500 on London\nBTC_CRYPTO - Bitcoin\nGet Exchange Metadata\n\nGET /api/v0/equity/metadata/exchanges (1 req/30s)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/metadata/exchanges\"\n\n\nResponse Schema:\n\n[\n  {\n    \"id\": 123,\n    \"name\": \"NASDAQ\",\n    \"workingSchedules\": [\n      {\n        \"id\": 456,\n        \"timeEvents\": [\n          { \"type\": \"PRE_MARKET_OPEN\", \"date\": \"2024-01-15T09:00:00Z\" },\n          { \"type\": \"OPEN\", \"date\": \"2024-01-15T14:30:00Z\" },\n          { \"type\": \"CLOSE\", \"date\": \"2024-01-15T21:00:00Z\" },\n          { \"type\": \"AFTER_HOURS_CLOSE\", \"date\": \"2024-01-15T01:00:00Z\" }\n        ]\n      }\n    ]\n  }\n]\n\nTime Event Types\nType\tDescription\nPRE_MARKET_OPEN\tPre-market session starts\nOPEN\tRegular trading starts\nBREAK_START\tTrading break begins\nBREAK_END\tTrading break ends\nCLOSE\tRegular trading ends\nAFTER_HOURS_OPEN\tAfter-hours session starts\nAFTER_HOURS_CLOSE\tAfter-hours session ends\nOVERNIGHT_OPEN\tOvernight session starts\nHistorical Data\n\nAll historical endpoints use cursor-based pagination with nextPagePath.\n\nPagination Parameters\nParameter\tType\tDefault\tMax\tDescription\nlimit\tinteger\t20\t50\tItems per page\ncursor\tstring/number\t-\t-\tPagination cursor (used in nextPagePath)\nticker\tstring\t-\t-\tFilter by ticker (orders, dividends)\ntime\tdatetime\t-\t-\tPagination time (used in nextPagePath for transactions)\nPagination Example\n#!/bin/bash\n# Fetch all historical orders with pagination\n\nNEXT_PATH=\"/api/v0/equity/history/orders?limit=50\"\n\nwhile [ -n \"$NEXT_PATH\" ]; do\n  echo \"Fetching: $NEXT_PATH\"\n\n  RESPONSE=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL$NEXT_PATH\")\n\n  # Process items (e.g., save to file)\n  echo \"$RESPONSE\" | jq '.items[]' >> orders.json\n\n  # Get next page path (null if no more pages)\n  NEXT_PATH=$(echo \"$RESPONSE\" | jq -r '.nextPagePath // empty')\n\n  # Wait 1 second between requests (50 req/min limit)\n  if [ -n \"$NEXT_PATH\" ]; then\n    sleep 1\n  fi\ndone\n\necho \"Done fetching all orders\"\n\nHistorical Orders\n\nGET /api/v0/equity/history/orders (50 req/min)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/orders?limit=50\"\n\n# Filter by ticker\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/orders?ticker=AAPL_US_EQ&limit=50\"\n\n\nResponse Schema:\n\n{\n  \"items\": [\n    {\n      \"order\": {\n        \"id\": 123456789,\n        \"type\": \"MARKET\",\n        \"ticker\": \"AAPL_US_EQ\",\n        \"instrument\": {\n          \"ticker\": \"AAPL_US_EQ\",\n          \"name\": \"Apple Inc\",\n          \"isin\": \"US0378331005\",\n          \"currency\": \"USD\"\n        },\n        \"quantity\": 5,\n        \"filledQuantity\": 5,\n        \"status\": \"FILLED\",\n        \"side\": \"BUY\",\n        \"createdAt\": \"2024-01-15T10:30:00Z\"\n      },\n      \"fill\": {\n        \"id\": 987654321,\n        \"type\": \"TRADE\",\n        \"quantity\": 5,\n        \"price\": 185.5,\n        \"filledAt\": \"2024-01-15T10:30:05Z\",\n        \"tradingMethod\": \"TOTV\",\n        \"walletImpact\": {\n          \"currency\": \"GBP\",\n          \"fxRate\": 0.79,\n          \"netValue\": 732.72,\n          \"realisedProfitLoss\": 0,\n          \"taxes\": [\n            { \"name\": \"STAMP_DUTY\", \"quantity\": 3.66, \"currency\": \"GBP\" }\n          ]\n        }\n      }\n    }\n  ],\n  \"nextPagePath\": \"/api/v0/equity/history/orders?limit=50&cursor=1705326600000\"\n}\n\nFill Types\nType\tDescription\nTRADE\tRegular trade execution\nSTOCK_SPLIT\tStock split adjustment\nSTOCK_DISTRIBUTION\tStock distribution\nFOP\tFree of payment transfer\nFOP_CORRECTION\tFOP correction\nCUSTOM_STOCK_DISTRIBUTION\tCustom stock distribution\nEQUITY_RIGHTS\tEquity rights issue\nTrading Methods\nMethod\tDescription\nTOTV\tTraded on trading venue\nOTC\tOver-the-counter\nTax Types (walletImpact.taxes)\nType\tDescription\nCOMMISSION_TURNOVER\tCommission on turnover\nCURRENCY_CONVERSION_FEE\tFX conversion fee\nFINRA_FEE\tFINRA trading activity fee\nFRENCH_TRANSACTION_TAX\tFrench FTT\nPTM_LEVY\tPanel on Takeovers levy\nSTAMP_DUTY\tUK stamp duty\nSTAMP_DUTY_RESERVE_TAX\tUK SDRT\nTRANSACTION_FEE\tGeneral transaction fee\nHistorical Dividends\n\nGET /api/v0/equity/history/dividends (50 req/min)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/dividends?limit=50\"\n\n# Filter by ticker\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/dividends?ticker=AAPL_US_EQ&limit=50\"\n\n\nResponse Schema:\n\n{\n  \"items\": [\n    {\n      \"ticker\": \"AAPL_US_EQ\",\n      \"instrument\": {\n        \"ticker\": \"AAPL_US_EQ\",\n        \"name\": \"Apple Inc\",\n        \"isin\": \"US0378331005\",\n        \"currency\": \"USD\"\n      },\n      \"type\": \"ORDINARY\",\n      \"amount\": 12.5,\n      \"amountInEuro\": 14.7,\n      \"currency\": \"GBP\",\n      \"tickerCurrency\": \"USD\",\n      \"grossAmountPerShare\": 0.24,\n      \"quantity\": 65.5,\n      \"paidOn\": \"2024-02-15T00:00:00Z\",\n      \"reference\": \"DIV-123456\"\n    }\n  ],\n  \"nextPagePath\": null\n}\n\nDividend Types (Common)\nType\tDescription\nORDINARY\tRegular dividend\nBONUS\tBonus dividend\nINTEREST\tInterest payment\nDIVIDEND\tGeneric dividend\nCAPITAL_GAINS\tCapital gains distribution\nRETURN_OF_CAPITAL\tReturn of capital\nPROPERTY_INCOME\tProperty income (REITs)\nDEMERGER\tDemerger distribution\nQUALIFIED_INVESTMENT_ENTITY\tQIE distribution\nTRUST_DISTRIBUTION\tTrust distribution\n\nNote: Many additional US tax-specific types exist for 1042-S reporting.\n\nAccount Transactions\n\nGET /api/v0/equity/history/transactions (50 req/min)\n\nPagination:\n\nFirst request: Must use only the limit parameter (no cursor, no timestamp)\nSubsequent requests: Use the nextPagePath from the previous response, which includes cursor and timestamp automatically\nTime filtering: Transactions cannot be filtered by time - pagination is the only way to navigate through historical data\n# First request - use only limit\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/transactions?limit=50\"\n\n\nResponse Schema:\n\n{\n  \"items\": [\n    {\n      \"type\": \"DEPOSIT\",\n      \"amount\": 1000.0,\n      \"currency\": \"GBP\",\n      \"dateTime\": \"2024-01-10T14:30:00Z\",\n      \"reference\": \"TXN-123456\"\n    }\n  ],\n  \"nextPagePath\": null\n}\n\nTransaction Types\nType\tDescription\nDEPOSIT\tFunds deposited to account\nWITHDRAW\tFunds withdrawn from account\nFEE\tFee charged\nTRANSFER\tInternal transfer\nCSV Reports\n\nRequest report: POST /api/v0/equity/history/exports (1 req/30s)\n\ncurl -X POST -H \"Authorization: $T212_AUTH_HEADER\" \\\n  -H \"Content-Type: application/json\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/exports\" \\\n  -d '{\n    \"dataIncluded\": {\n      \"includeDividends\": true,\n      \"includeInterest\": true,\n      \"includeOrders\": true,\n      \"includeTransactions\": true\n    },\n    \"timeFrom\": \"2024-01-01T00:00:00Z\",\n    \"timeTo\": \"2024-12-31T23:59:59Z\"\n  }'\n\n\nResponse:\n\n{\n  \"reportId\": 12345\n}\n\n\nPoll for completion: GET /api/v0/equity/history/exports (1 req/min)\n\ncurl -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/exports\"\n\n\nResponse:\n\n[\n  {\n    \"reportId\": 12345,\n    \"status\": \"Finished\",\n    \"dataIncluded\": {\n      \"includeDividends\": true,\n      \"includeInterest\": true,\n      \"includeOrders\": true,\n      \"includeTransactions\": true\n    },\n    \"timeFrom\": \"2024-01-01T00:00:00Z\",\n    \"timeTo\": \"2024-12-31T23:59:59Z\",\n    \"downloadLink\": \"https://trading212-reports.s3.amazonaws.com/...\"\n  }\n]\n\n\nDownload the report:\n\n# Get the download link from the response\nDOWNLOAD_URL=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/history/exports\" | jq -r '.[0].downloadLink')\n\n# Download the CSV file\ncurl -o trading212_report.csv \"$DOWNLOAD_URL\"\n\nReport Status Values\nStatus\tDescription\nQueued\tReport request received\nProcessing\tReport generation started\nRunning\tReport actively generating\nFinished\tComplete - downloadLink available\nCanceled\tReport cancelled\nFailed\tGeneration failed\nPre-Order Validation\nBefore BUY - Check Available Funds\n#!/bin/bash\n# Validate funds before placing a buy order\n\nTICKER=\"AAPL_US_EQ\"\nQUANTITY=10\nESTIMATED_PRICE=185.00\nESTIMATED_COST=$(echo \"$QUANTITY * $ESTIMATED_PRICE\" | bc)\n\n# Get available funds\nAVAILABLE=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/account/summary\" | jq '.cash.availableToTrade')\n\necho \"Estimated cost: $ESTIMATED_COST\"\necho \"Available funds: $AVAILABLE\"\n\nif (( $(echo \"$ESTIMATED_COST > $AVAILABLE\" | bc -l) )); then\n  echo \"ERROR: Insufficient funds\"\n  exit 1\nfi\n\necho \"OK: Funds available, proceeding with order\"\n\nBefore SELL - Check Available Shares\n#!/bin/bash\n# Validate position before placing a sell order\n\nTICKER=\"AAPL_US_EQ\"\nSELL_QUANTITY=5\n\n# Get position for the ticker\nPOSITION=$(curl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/positions?ticker=$TICKER\")\n\nAVAILABLE_QTY=$(echo \"$POSITION\" | jq '.[0].quantityAvailableForTrading // 0')\n\necho \"Sell quantity: $SELL_QUANTITY\"\necho \"Available to sell: $AVAILABLE_QTY\"\n\nif (( $(echo \"$SELL_QUANTITY > $AVAILABLE_QTY\" | bc -l) )); then\n  echo \"ERROR: Insufficient shares (some may be in pies)\"\n  exit 1\nfi\n\necho \"OK: Shares available, proceeding with order\"\n\nRate Limit Handling\nUnderstanding Rate Limits\n\nRate limits are per-account, not per API key or IP address. If you have multiple applications using the same Trading 212 account, they share the same rate limit pool.\n\nResponse Headers\n\nEvery API response includes rate limit headers:\n\nHeader\tDescription\nx-ratelimit-limit\tTotal requests allowed in period\nx-ratelimit-period\tTime period in seconds\nx-ratelimit-remaining\tRequests remaining\nx-ratelimit-reset\tUnix timestamp when limit resets\nx-ratelimit-used\tRequests already made\nAvoid Burst Requests to avoid Rate Limiting\n\nDo not send requests in bursts. Even if an endpoint allows 50 requests per minute, sending them all at once can trigger rate limiting and degrade performance. Pace your requests evenly, for example, by making one call every 1.2 seconds, ensuring you always stay within the limit.\n\nBad approach (bursting):\n\n# DON'T DO THIS - sends all requests at once\nfor ticker in AAPL_US_EQ MSFT_US_EQ GOOGL_US_EQ; do\n  curl -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL/api/v0/equity/positions?ticker=$ticker\" &\ndone\nwait\n\n\nGood approach (paced):\n\n# DO THIS - space requests evenly\nfor ticker in AAPL_US_EQ MSFT_US_EQ GOOGL_US_EQ; do\n  curl -H \"Authorization: $T212_AUTH_HEADER\" \\\n    \"$T212_BASE_URL/api/v0/equity/positions?ticker=$ticker\"\n  sleep 1.2  # 1.2 second between requests for 50 req/m limit\ndone\n\nCaching Strategy\n\nFor data that doesn't change frequently, cache locally to reduce API calls:\n\n#!/bin/bash\n# Cache instruments list (changes rarely)\n\nCACHE_FILE=\"/tmp/t212_instruments.json\"\nCACHE_MAX_AGE=3600  # 1 hour\n\nif [ -f \"$CACHE_FILE\" ]; then\n  CACHE_AGE=$(($(date +%s) - $(stat -f %m \"$CACHE_FILE\")))\n  if [ \"$CACHE_AGE\" -lt \"$CACHE_MAX_AGE\" ]; then\n    cat \"$CACHE_FILE\"\n    exit 0\n  fi\nfi\n\n# Cache expired or doesn't exist - fetch fresh data\ncurl -s -H \"Authorization: $T212_AUTH_HEADER\" \\\n  \"$T212_BASE_URL/api/v0/equity/metadata/instruments\" > \"$CACHE_FILE\"\n\ncat \"$CACHE_FILE\"\n\nSafety Guidelines\nTest in demo first - Always validate workflows before live trading\nValidate before ordering - Check funds (cash.availableToTrade) before buy, positions (quantityAvailableForTrading) before sell\nConfirm destructive actions - Order placement and cancellation are irreversible\nAPI is not idempotent - Duplicate requests may create duplicate orders\nNever log credentials - Use environment variables\nRespect rate limits - Space requests evenly, never burst\nMax 50 pending orders - Per ticker, per account\nCache metadata - Instruments and exchanges change rarely"
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/tsvetelin-kulinski/trading212-api",
    "publisherUrl": "https://clawhub.ai/tsvetelin-kulinski/trading212-api",
    "owner": "tsvetelin-kulinski",
    "version": "1.0.0",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/trading212-api",
    "downloadUrl": "https://openagent3.xyz/downloads/trading212-api",
    "agentUrl": "https://openagent3.xyz/skills/trading212-api/agent",
    "manifestUrl": "https://openagent3.xyz/skills/trading212-api/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/trading212-api/agent.md"
  }
}