trading212-api

This 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", "get positions", "view

By trading212-labs · 400 installs

npx skills add trading212-labs/agent-skills --skill trading212-api

Source repository · Upstream listing

Trading 212 API Note: The Trading 212 API is currently in beta and under active development. Some endpoints or behaviors may change. Quick Reference Environments Environment Base URL Purpose Demo https://demo.trading212.com/api/v0 Paper trading test without real funds Live https://live.trading212.com/api/v0 Real money trading Order Quantity Convention Positive quantity = BUY (e.g., 10 buys 10 shares) Negative quantity = SELL (e.g., 10 sells 10 shares) Account Types Only Invest and Stocks ISA accounts are supported. Instrument Identifiers Trading 212 uses custom tickers as unique identifiers for instruments. Always search for the Trading 212 ticker before making instrument requests. Authentication HTTP Basic Auth with API Key (username) and API Secret (password). Check Existing Setup First Before guiding the user through authentication setup, check if credentials are already configured: 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. 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. 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. API Keys Are Environment Specific API keys are tied to a specific environment and cannot be used across environments. API Key Created In Works With Does NOT Work With LIVE account live.trading212.com demo.trading212.com DEMO account demo.trading212.com live.trading212.com If you get a 401 error, verify that: 1. You're using the correct API key for the target environment 2. The API key was generated in the same environment (LIVE or DEMO) you're trying to access Get Credentials 1. Decide which environment to use LIVE (real money) or DEMO (paper trading) 2. Open Trading 212 app (mobile or web) 3. Switch to the correct account Make sure you're in LIVE or DEMO mode matching your target environment 4. Navigate to Settings API 5. Generate a new API key pair you'll receive: API Key (ID) (e.g., 35839398ZFVKUxpHzPiVsxKdOtZdaDJSrvyPF ) API Secret (e.g., 7MOzYJlVJgxoPjdZJCEH3fO9ee7A0NzLylFFD4 3tlo ) 6. Store the credentials separately for each environment if you use both Building the Auth Header Combine your API Key (ID) and Secret with a colon, base64 encode, and prefix with Basic for the Authorization header. Optional: To precompute the header from key/secret, you can set: Otherwise, the agent builds the header from T212 API KEY and T212 API SECRET when making requests. Manual (placeholders): Making Requests 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): If T212 AUTH HEADER and T212 BASE URL are set: use them in requests. Else 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 w 0) and base URL as https://${T212 ENV: live}.trading212.com . Do not guide the user to derive or merge; you do it. Else 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 . Else 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. Else 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. Use the T212 AUTH HEADER value in the Authorization header when it is set: When only primary vars are set, use the inline form in the curl: Warning: T212 AUTH HEADER must be the full header value including the Basic prefix. Environment Variables 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. Primary (single account): Set these for consistent setup with the plugin README: Account 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: For both accounts, set both pairs: Optional – 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. Alternative (manual): If you prefer not to store key/secret in env, set derived vars directly. Remember: API keys only work with their matching environment. Tip: If you use both environments, use separate variable names: Common Auth Errors Code Cause Solution 401 Invalid credentials Check API key/secret, ensure no extra whitespace 401 Environment mismatch LIVE API keys don't work with DEMO and vice versa verify key matches target environment 403 Missing permissions Check API permissions in Trading 212 settings 408 Request timed out Retry the request 429 Rate limit exceeded Wait for x ratelimit reset timestamp Account Get Account Summary GET /api/v0/equity/account/summary (1 req/5s) Response Schema: Account Fields Field Type Description id integer Primary trading account number currency string Primary account currency (ISO 4217) totalValue number Total account value in primary currency cash.availableToTrade number Funds available for investing cash.reservedForOrders number Cash reserved for pending orders cash.inPies number Uninvested cash inside pies investments.currentValue number Current value of all investments investments.totalCost number Cost basis of current investments investments.realizedProfitLoss number All time realized P&L investments.unrealizedProfitLoss number Potential P&L if sold now Orders Order Types Type Endpoint Availability Description Market /api/v0/equity/orders/market Demo + Live Execute immediately at best price Limit /api/v0/equity/orders/limit Demo + Live Execute at limit price or better Stop /api/v0/equity/orders/stop Demo + Live Market order when stop price reached StopLimit /api/v0/equity/orders/stop limit Demo + Live Limit order when stop price reached Order Statuses Status Description LOCAL Order created locally, not yet sent UNCONFIRMED Sent to exchange, awaiting confirmation CONFIRMED Confirmed by exchange NEW Active and awaiting execution CANCELLING Cancel request in progress CANCELLED Successfully cancelled PARTIALLY FILLED Some shares executed FILLED Completely executed REJECTED Rejected by exchange REPLACING Modification in progress REPLACED Successfully modified Time Validity Value Description DAY Expires at midnight in exchange timezone GOOD TILL CANCEL Active until filled or cancelled (default) Order Strategy Value Description QUANTITY Order by number of shares (API supported) VALUE Order by monetary value (not supported via API) Initiated From Value Description API Placed via this API IOS iOS app ANDROID Android app WEB Web platform SYSTEM System generated AUTOINVEST Autoinvest feature Place Market Order POST /api/v0/equity/orders/market (50 req/min) Request Fields: Field Type Required Description ticker string Yes Instrument ticker (e.g., AAPL US EQ ) quantity number Yes Positive for buy, negative for sell extendedHours boolean No Set true to allow execution in pre market (4:00 9:30 ET) and after hours (16:00 20:00 ET) sessions. Default: false Response: Place Limit Order POST /api/v0/equity/orders/limit (