### Fetch Transaction History with Pagination Source: https://docs.trading212.com/api/section/pagination/example This example demonstrates how to fetch transaction history using pagination. It shows how to make the initial request, interpret the response to get the next page path, and use it for subsequent requests until all data is retrieved. ```APIDOC ## GET /api/v0/equity/history/orders ### Description Fetches a paginated list of transaction orders. ### Method GET ### Endpoint /api/v0/equity/history/orders ### Query Parameters - **limit** (integer) - Optional - The maximum number of items to return per page. - **cursor** (string) - Optional - A cursor for fetching the next page of results. This is typically provided in the `nextPagePath` from a previous response. ### Request Example ```bash curl -X GET "https://demo.trading212.com/api/v0/equity/history/orders?limit=2" \ -u "API_KEY:API_SECRET" ``` ### Response #### Success Response (200) - **items** (array) - A list of transaction order objects. - **nextPagePath** (string or null) - The full path to the next page of results, or null if this is the last page. #### Response Example ```json { "items": [ { "id": 987654321, "ticker": "AAPL_US_EQ", ... }, { "id": 987654320, "ticker": "MSFT_US_EQ", ... } ], "nextPagePath": "/api/v0/equity/history/orders?limit=2&cursor=1760346100000" } ``` ### Usage Example To paginate through all transactions, make an initial request without a `cursor`. Then, use the `nextPagePath` provided in the response for subsequent requests until `nextPagePath` is null. ``` -------------------------------- ### Get Account Summary Source: https://docs.trading212.com/api.md This example demonstrates how to retrieve your account summary using cURL. It requires Base64-encoded API credentials in the Authorization header. ```APIDOC ## GET /equity/account/summary ### Description Retrieves a summary of your trading account. ### Method GET ### Endpoint `https://live.trading212.com/api/v0/equity/account/summary` ### Parameters #### Headers - **Authorization** (string) - Required - Basic authentication token. ### Request Example ```bash CREDENTIALS=$(echo -n ":" | base64) curl -X GET "https://live.trading212.com/api/v0/equity/account/summary" \ -H "Authorization: Basic $CREDENTIALS" ``` ### Response #### Success Response (200) - **account_id** (string) - The unique identifier for the account. - **account_currency** (string) - The primary currency of the account. - **equity** (number) - The total equity of the account. - **cash** (number) - The available cash balance in the account. - **market_value** (number) - The current market value of all holdings. - **unrealized_pnl** (number) - The unrealized profit or loss. - **realized_pnl** (number) - The realized profit or loss. #### Response Example ```json { "account_id": "acc_12345abc", "account_currency": "GBP", "equity": 15000.50, "cash": 5000.00, "market_value": 10000.50, "unrealized_pnl": 250.75, "realized_pnl": -100.20 } ``` ``` -------------------------------- ### Final Response Example Source: https://docs.trading212.com/api When there are no more pages, the nextPagePath field in the response will be null. ```json { "items": [ { "id": 987654317, "ticker": "AMZN_US_EQ", ... } ], "nextPagePath": null } ``` -------------------------------- ### Fetch First Page of Transactions Source: https://docs.trading212.com/api/section/pagination/example Use this request to get the first batch of transaction data. The response includes a nextPagePath if more data is available. ```bash curl -X GET "https://demo.trading212.com/api/v0/equity/history/orders?limit=2" \ -u "API_KEY:API_SECRET" ``` -------------------------------- ### Retrieve Account Summary Source: https://docs.trading212.com/api/section/general-information/quickstart This example demonstrates how to retrieve your account summary using cURL. It includes steps for generating API keys and making the authenticated API call. ```APIDOC ## Retrieve Account Summary This endpoint retrieves a summary of your Trading 212 account. ### Method GET ### Endpoint /api/v0/equity/account/summary ### Authentication Requires Basic Authentication with API Key and API Secret, Base64 encoded. ### Request Example ```bash # Step 1: Replace with your actual credentials and Base64-encode them. # The -n is important as it prevents adding a newline character. CREDENTIALS=$(echo -n ":" | base64) # Step 2: Make the API call to the live environment using the encoded credentials. curl -X GET "https://live.trading212.com/api/v0/equity/account/summary" \ -H "Authorization: Basic $CREDENTIALS" ``` ### Response #### Success Response (200) (Response structure not provided in source text) #### Error Response (Error handling details not provided in source text) ``` -------------------------------- ### Get Account Summary Source: https://docs.trading212.com/api Retrieves a summary of your Trading 212 account. This is a basic example to get started with the API. ```APIDOC ## GET /equity/account/summary ### Description Retrieves a summary of your Trading 212 account. ### Method GET ### Endpoint https://live.trading212.com/api/v0/equity/account/summary ### Parameters #### Headers - **Authorization** (string) - Required - Basic authentication token. ### Request Example ```bash CREDENTIALS=$(echo -n ":" | base64) curl -X GET "https://live.trading212.com/api/v0/equity/account/summary" \ -H "Authorization: Basic $CREDENTIALS" ``` ### Response #### Success Response (200) - **account_currency** (string) - The primary currency of the account. - **equity** (number) - The total equity in the account. - **cash** (number) - The available cash balance. - **realized_pnl** (number) - The realized profit and loss. - **unrealized_pnl** (number) - The unrealized profit and loss. #### Response Example ```json { "account_currency": "GBP", "equity": 10000.50, "cash": 5000.25, "realized_pnl": 150.75, "unrealized_pnl": -50.25 } ``` ``` -------------------------------- ### Generate Authorization Header Source: https://docs.trading212.com/api Examples of how to generate the Base64 encoded Authorization header required for API requests. ```APIDOC ## Authentication Header Generation ### Description This section provides examples for generating the `Authorization` header using your API Key and API Secret. ### Method N/A (Client-side generation) ### Endpoint N/A ### Parameters - **API_KEY** (string) - Your Trading 212 API Key. - **API_SECRET** (string) - Your Trading 212 API Secret. ### Code Examples **Linux or macOS (Terminal)** ```bash # This command outputs the required Base64-encoded string for your header. echo -n ":" | base64 ``` **Python** ```python import base64 api_key = "" api_secret = "" credentials_string = f"{api_key}:{api_secret}" encoded_credentials = base64.b64encode(credentials_string.encode('utf-8')).decode('utf-8') auth_header = f"Basic {encoded_credentials}" print(auth_header) ``` ``` -------------------------------- ### Get account summary Source: https://docs.trading212.com/api/accounts Provides a breakdown of your account's cash and investment metrics, including available funds, invested capital, and total account value. ```APIDOC ## GET /api/v0/equity/account/summary ### Description Provides a breakdown of your account's cash and investment metrics, including available funds, invested capital, and total account value. ### Method GET ### Endpoint /api/v0/equity/account/summary ### Rate Limit 1 req / 5s ``` -------------------------------- ### Get all available instruments Source: https://docs.trading212.com/api/instruments Retrieves all accessible instruments. Data is refreshed every 10 minutes. ```APIDOC ## GET /api/v0/equity/metadata/instruments ### Description Retrieves all accessible instruments. ### Method GET ### Endpoint /api/v0/equity/metadata/instruments ### Rate Limit 1 req / 50s ``` -------------------------------- ### Response Example with nextPagePath Source: https://docs.trading212.com/api The API response includes a nextPagePath field. If this field is not null, it contains the URL for the next page of results, including the cursor. ```json { "items": [ { "id": 987654321, "ticker": "AAPL_US_EQ", ... }, { "id": 987654320, "ticker": "MSFT_US_EQ", ... } ], "nextPagePath": "/api/v0/equity/history/orders?limit=2&cursor=1760346100000" } ``` -------------------------------- ### Get All Instruments Source: https://docs.trading212.com/api/instruments/instruments.md Retrieves all accessible instruments. Data is refreshed every 10 minutes. Rate limit: 1 req / 50s. ```APIDOC ## GET /api/v0/equity/metadata/instruments ### Description Retrieves all accessible instruments. Data is refreshed every 10 minutes. ### Method GET ### Endpoint /api/v0/equity/metadata/instruments ### Response #### Success Response (200) - **addedOn** (string) - On the platform since - **currencyCode** (string) - ISO 4217. Example: "USD" - **extendedHours** (boolean) - **isin** (string) - **maxOpenQuantity** (number) - **name** (string) - **shortName** (string) - **ticker** (string) - Unique identifier. Example: "AAPL_US_EQ" - **type** (string) - Enum: "CRYPTOCURRENCY", "ETF", "FOREX", "FUTURES", "INDEX", "STOCK", "WARRANT", "CRYPTO", "CVR", "CORPACT" - **workingScheduleId** (integer) - Get items in the /exchanges endpoint #### Response Example { "addedOn": "2023-01-01T10:00:00Z", "currencyCode": "USD", "extendedHours": true, "isin": "US0378331005", "maxOpenQuantity": 1000, "name": "Apple Inc.", "shortName": "Apple", "ticker": "AAPL_US_EQ", "type": "STOCK", "workingScheduleId": 1 } ``` -------------------------------- ### Get Paid Out Dividends Source: https://docs.trading212.com/api/historical-events Retrieves a list of all paid out dividends. ```APIDOC ## GET /api/v0/equity/history/dividends ### Description Retrieves a list of all paid out dividends. ### Method GET ### Endpoint /api/v0/equity/history/dividends ### Rate Limit 6 req / 1m0s ``` -------------------------------- ### Retrieve Account Summary with cURL Source: https://docs.trading212.com/api/section/general-information/quickstart Use this cURL command to fetch your account summary. Ensure you replace placeholders with your actual API key and secret, and that they are properly Base64 encoded. The `-n` flag is crucial to prevent an extra newline character in the credentials. ```bash # Step 1: Replace with your actual credentials and Base64-encode them. # The -n is important as it prevents adding a newline character. CREDENTIALS=$(echo -n ":" | base64) # Step 2: Make the API call to the live environment using the encoded credentials. curl -X GET "https://live.trading212.com/api/v0/equity/account/summary" \ -H "Authorization: Basic $CREDENTIALS" ``` -------------------------------- ### Get Transactions Source: https://docs.trading212.com/api/historical-events Fetches superficial information about movements to and from your account. ```APIDOC ## GET /api/v0/equity/history/transactions ### Description Fetches superficial information about movements to and from your account. ### Method GET ### Endpoint /api/v0/equity/history/transactions ### Rate Limit 6 req / 1m0s ``` -------------------------------- ### Create pie Source: https://docs.trading212.com/api/pies-%28deprecated%29 Creates a pie for the account by given parameters. Rate limit: 1 req / 5s ```APIDOC ## Create pie (deprecated) ### Description Creates a pie for the account by given parameters. ### Method POST ### Endpoint /api/v0/equity/pies ### Rate Limit 1 req / 5s ``` -------------------------------- ### Get historical orders data Source: https://docs.trading212.com/api.md Retrieves historical order data. ```APIDOC ## GET /api/v0/equity/history/orders ### Description Get historical orders data. ### Method GET ### Endpoint /api/v0/equity/history/orders ``` -------------------------------- ### Place a Market order Source: https://docs.trading212.com/api/orders Creates a new Market order, which is an instruction to trade a security immediately at the next available price. Orders can be executed only in the main account currency. This endpoint is not idempotent in the beta version. ```APIDOC ## POST /api/v0/equity/orders/market ### Description Creates a new Market order, which is an instruction to trade a security immediately at the next available price. To place a buy order, use a positive quantity. To place a sell order, use a negative quantity. Set extendedHours to true to allow the order to be filled outside of the standard trading session. If placed when the market is closed, the order will be queued to execute when the market next opens. ### Method POST ### Endpoint /api/v0/equity/orders/market ### Parameters #### Query Parameters - **extendedHours** (boolean) - Optional - Set to true to allow the order to be filled outside of the standard trading session. ### Order Limitations Orders can be executed only in the main account currency. ### Warning Market orders can be subject to price slippage, where the final execution price may differ from the price at the time of order placement. ### Important In this beta version, this endpoint is not idempotent. Sending the same request multiple times may result in duplicate orders. ### Rate Limit 50 req / 1m0s ``` -------------------------------- ### Create Pie Source: https://docs.trading212.com/api/pies-%28deprecated%29/create.md This endpoint creates a pie for an investment account. It accepts various parameters to define the pie's composition, goal, and settings. Note that this endpoint is deprecated. ```APIDOC ## POST /api/v0/equity/pies ### Description Creates a pie for the account by given params. This endpoint is deprecated. ### Method POST ### Endpoint /api/v0/equity/pies ### Parameters #### Request Body (application/json) - **dividendCashAction** (string) - Optional - Enum: "REINVEST", "TO_ACCOUNT_CASH" - **endDate** (string) - Optional - **goal** (number) - Optional - Total desired value of the pie in account currency - **icon** (string) - Optional - **instrumentShares** (object) - Optional - Example: {"AAPL_US_EQ":0.5,"MSFT_US_EQ":0.5} - **name** (string) - Optional ### Response #### Success Response (200) (application/json) - **instruments** (array) - Details about the instruments in the pie. - **instruments.currentShare** (number) - **instruments.expectedShare** (number) - **instruments.issues** (array) - List of issues related to the instrument. - **instruments.issues.name** (string) - Enum: "DELISTED", "SUSPENDED", "NO_LONGER_TRADABLE", "MAX_POSITION_SIZE_REACHED", "APPROACHING_MAX_POSITION_SIZE", "COMPLEX_INSTRUMENT_APP_TEST_REQUIRED", "PRICE_TOO_LOW" - **instruments.issues.severity** (string) - Enum: "IRREVERSIBLE", "REVERSIBLE", "INFORMATIVE" - **instruments.ownedQuantity** (number) - **instruments.result** (object) - Calculation results for the instrument. - **instruments.result.priceAvgInvestedValue** (number) - **instruments.result.priceAvgResult** (number) - **instruments.result.priceAvgResultCoef** (number) - **instruments.result.priceAvgValue** (number) - **instruments.ticker** (string) - **settings** (object) - Settings related to the pie creation. - **settings.creationDate** (string) - **settings.dividendCashAction** (string) - Enum: "REINVEST", "TO_ACCOUNT_CASH" - **settings.endDate** (string) - **settings.goal** (number) - **settings.icon** (string) - **settings.id** (integer) - **settings.initialInvestment** (number) - **settings.instrumentShares** (object) - **settings.name** (string) - **settings.publicUrl** (string) #### Error Responses - **400**: Bad Request - **401**: Unauthorized - **403**: Forbidden - **408**: Request Timeout - **429**: Too Many Requests ``` -------------------------------- ### Get Transactions Source: https://docs.trading212.com/api/historical-events/transactions Fetches a list of transactions with optional filtering and pagination. ```APIDOC ## GET /api/v0/equity/history/transactions ### Description Fetch superficial information about movements to and from your account. ### Method GET ### Endpoint /api/v0/equity/history/transactions ### Query Parameters #### cursor (string) - Optional - Pagination cursor #### time (string) - Optional - Retrieve transactions starting from the specified time #### limit (integer) - Optional - Max items: 50. Example: 21 ### Response #### Success Response (200) (application/json) - items (array) - List of transactions. - items.amount (number) - Amount in the currency of the transaction. - items.currency (string) - Currency of the transaction. - items.dateTime (string) - items.reference (string) - ID. - items.type (string) - Enum: "WITHDRAW", "DEPOSIT", "FEE", "TRANSFER". - nextPagePath (string) #### Error Responses - 400 Bad Request - 401 Unauthorized - 403 Forbidden - 408 Request Timeout - 429 Too Many Requests ``` -------------------------------- ### Generate Authorization Header in Python Source: https://docs.trading212.com/api/section/authentication/building-the-authorization-header This Python snippet demonstrates how to combine your API key and secret, encode them using Base64, and format the final 'Basic' authentication header. Ensure you have the `base64` module available. ```python import base64 # 1. Your credentials api_key = "" api_secret = "" # 2. Combine them into a single string credentials_string = f"{api_key}:{api_secret}" # 3. Encode the string to bytes, then Base64 encode it encoded_credentials = base64.b64encode(credentials_string.encode('utf-8')).decode('utf-8') # 4. The final header value auth_header = f"Basic {encoded_credentials}" print(auth_header) ``` -------------------------------- ### Get Historical Orders Data Source: https://docs.trading212.com/api/historical-events Retrieves historical orders data for the account. ```APIDOC ## GET /api/v0/equity/history/orders ### Description Retrieves historical orders data for the account. ### Method GET ### Endpoint /api/v0/equity/history/orders ### Rate Limit 6 req / 1m0s ``` -------------------------------- ### Get Paid Out Dividends Source: https://docs.trading212.com/api/historical-events/dividends Fetches a list of dividends paid out. Supports filtering by ticker and pagination. ```APIDOC ## Get Paid Out Dividends ### Description Retrieves a paginated list of dividend payouts. You can filter the results by a specific stock ticker. ### Method GET ### Endpoint /api/v0/equity/history/dividends ### Query Parameters - **cursor** (integer) - Optional - Pagination cursor. Use the `nextPagePath` from the previous response to fetch the next page. - **ticker** (string) - Optional - Filters dividends for a specific stock ticker. - **limit** (integer) - Optional - The maximum number of items to return per page. Defaults to 50, with a maximum of 50. ### Response #### Success Response (200) - **items** (array) - A list of dividend payout objects. - **items.amount** (number) - The dividend amount in the account's primary currency. - **items.amountInEuro** (number) - The dividend amount converted to EUR. - **items.currency** (string) - The currency of the account's primary currency. - **items.grossAmountPerShare** (number) - The gross dividend amount per share in the instrument's currency. - **items.instrument** (object) - Information about the financial instrument. - **items.instrument.currency** (string) - The instrument's currency in ISO 4217 format. - **items.instrument.isin** (string) - The International Securities Identification Number (ISIN) of the instrument. - **items.instrument.name** (string) - The name of the instrument. - **items.instrument.ticker** (string) - The unique ticker symbol for the instrument (e.g., "AAPL_US_EQ"). - **items.paidOn** (string) - The date the dividend was paid. - **items.quantity** (number) - The number of shares for which the dividend was paid. - **items.reference** (string) - A reference identifier for the dividend payment. - **items.ticker** (string) - The ticker symbol of the instrument. - **items.tickerCurrency** (string) - The currency of the instrument's ticker. - **items.type** (string) - The type of dividend payment. Refer to the API documentation for a full list of possible enum values. - **nextPagePath** (string) - A path to retrieve the next page of results, or null if this is the last page. ### Response Example ```json { "items": [ { "amount": 10.50, "amountInEuro": 9.80, "currency": "USD", "grossAmountPerShare": 0.25, "instrument": { "currency": "USD", "isin": "US0378331005", "name": "Apple Inc.", "ticker": "AAPL_US_EQ" }, "paidOn": "2023-01-15T00:00:00Z", "quantity": 42, "reference": "DIV-12345", "ticker": "AAPL_US_EQ", "tickerCurrency": "USD", "type": "ORDINARY" } ], "nextPagePath": "/api/v0/equity/history/dividends?cursor=12345&limit=50" } ``` ``` -------------------------------- ### Get Pending Order by ID Source: https://docs.trading212.com/api/orders/orderbyid Retrieves a single pending order using its unique numerical ID. ```APIDOC ## GET /api/v0/equity/orders/{id} ### Description Retrieves a single pending order using its unique numerical ID. This is useful for checking the status of a specific order you have previously placed. ### Method GET ### Endpoint /api/v0/equity/orders/{id} ### Parameters #### Path Parameters - **id** (integer, required) - The unique identifier of the order you want to retrieve. ### Response #### Success Response (200) - **createdAt** (string) - The ISO 8601 formatted date of when the order was created. - **currency** (string) - The currency used for the order in ISO 4217 format. - **extendedHours** (boolean) - If true, the order is eligible for execution outside regular trading hours. - **filledQuantity** (number) - The number of shares that have been successfully executed. Applicable to quantity orders. - **filledValue** (number) - The total monetary value of the executed portion of the order. Applicable to orders placed by value. - **id** (integer) - A unique, system-generated identifier for the order. - **initiatedFrom** (string) - How the order was initiated. Enum: "API", "IOS", "ANDROID", "WEB", "SYSTEM", "AUTOINVEST", "INSTRUMENT_AUTOINVEST" - **instrument** (object) - Instrument information as given by /instruments endpoint. - **instrument.currency** (string) - Instrument currency in ISO 4217 format. - **instrument.isin** (string) - ISIN of the instrument. - **instrument.name** (string) - Name of the instrument. - **instrument.ticker** (string) - Unique instrument identifier. Example: "AAPL_US_EQ" - **limitPrice** (number) - Applicable to LIMIT and STOP_LIMIT orders. - **quantity** (number) - The total number of shares requested. Applicable to quantity orders. - **side** (string) - Indicates whether the order is BUY or SELL. Enum: "BUY", "SELL" - **status** (string) - The current state of the order in its lifecycle. Enum: "LOCAL", "UNCONFIRMED", "CONFIRMED", "NEW", "CANCELLING", "CANCELLED", "PARTIALLY_FILLED", "FILLED", "REJECTED", "REPLACING", "REPLACED" - **stopPrice** (number) - Applicable to STOP and STOP_LIMIT orders. - **strategy** (string) - The strategy used to place the order, either by QUANTITY or VALUE. Enum: "QUANTITY", "VALUE" - **ticker** (string) - Unique instrument identifier. Get from the /instruments endpoint Example: "AAPL_US_EQ" - **timeInForce** (string) - Specifies how long the order remains active: * DAY: The order will automatically expire if not executed by midnight in the time zone of the instrument's exchange. * GOOD_TILL_CANCEL: The order remains active indefinitely until it is either filled or explicitly cancelled by you. Enum: "DAY", "GOOD_TILL_CANCEL" - **type** (string) - Enum: "LIMIT", "STOP", "MARKET", "STOP_LIMIT" - **value** (number) - The total monetary value of the order. Applicable to value orders. ``` -------------------------------- ### Generate Authorization Header on Linux/macOS Source: https://docs.trading212.com/api/section/authentication/building-the-authorization-header Use the `echo` command with the `-n` flag to prevent trailing newlines, and pipe the output to `base64` for encoding. This is useful for quick generation in a terminal environment. ```bash # This command outputs the required Base64-encoded string for your header. echo -n ":" | base64 ``` -------------------------------- ### Get exchanges metadata Source: https://docs.trading212.com/api/instruments Retrieves all accessible exchanges and their corresponding working schedules. Data is refreshed every 10 minutes. ```APIDOC ## GET /api/v0/equity/metadata/exchanges ### Description Retrieves all accessible exchanges and their corresponding working schedules. ### Method GET ### Endpoint /api/v0/equity/metadata/exchanges ### Rate Limit 1 req / 30s ``` -------------------------------- ### Create pie (deprecated) Source: https://docs.trading212.com/api Creates a pie for the account by given parameters. This endpoint is deprecated and will not be further supported or updated. ```APIDOC ## POST /api/v0/equity/pies ### Description Creates a pie for the account by given parameters. This endpoint is deprecated and will not be further supported or updated. ### Method POST ### Endpoint /api/v0/equity/pies ``` -------------------------------- ### Fetch all open positions Source: https://docs.trading212.com/api/positions Retrieve a list of all currently open positions in your account. This endpoint provides real-time data for each position. ```APIDOC ## GET /api/v0/equity/positions ### Description Fetch all open positions for your account. ### Method GET ### Endpoint /api/v0/equity/positions ### Rate Limit 1 req / 1s ``` -------------------------------- ### Get Exchanges Metadata Source: https://docs.trading212.com/api/instruments/exchanges Retrieves a list of all accessible exchanges and their working schedules. This endpoint is rate-limited to 1 request per 30 seconds. ```APIDOC ## GET /api/v0/equity/metadata/exchanges ### Description Retrieves all accessible exchanges and their corresponding working schedules. Data is refreshed every 10 minutes. ### Method GET ### Endpoint /api/v0/equity/metadata/exchanges ### Security - authWithSecretKey - legacyApiKeyHeader ### Rate Limit 1 req / 30s ### Response 200 fields (application/json) - `id` (integer) - Unique identifier for the exchange. - `name` (string) - The name of the exchange. - `workingSchedules` (array) - An array of working schedules for the exchange. - `id` (integer) - Identifier for the working schedule. - `timeEvents` (array) - An array of time events within the schedule. - `date` (string) - The date of the time event (ISO 8601 format). - `type` (string) - The type of time event. Enum: "OPEN", "CLOSE", "BREAK_START", "BREAK_END", "PRE_MARKET_OPEN", "AFTER_HOURS_OPEN", "AFTER_HOURS_CLOSE", "OVERNIGHT_OPEN" ### Response Examples #### Success Response (200) ```json { "exchanges": [ { "id": 1, "name": "NYSE", "workingSchedules": [ { "id": 101, "timeEvents": [ { "date": "2023-10-27T09:30:00Z", "type": "OPEN" }, { "date": "2023-10-27T12:00:00Z", "type": "BREAK_START" }, { "date": "2023-10-27T12:30:00Z", "type": "BREAK_END" }, { "date": "2023-10-27T16:00:00Z", "type": "CLOSE" } ] } ] } ] } ``` ### Error Responses - **401**: Unauthorized - **403**: Forbidden - **408**: Request Timeout - **429**: Too Many Requests ``` -------------------------------- ### Fetch a pie Source: https://docs.trading212.com/api/pies-%28deprecated%29 Fetches a pie for the account with detailed information. Rate limit: 1 req / 5s ```APIDOC ## Fetch a pie (deprecated) ### Description Fetches a pie for the account with detailed information. ### Method GET ### Endpoint /api/v0/equity/pies/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the pie to fetch. ### Rate Limit 1 req / 5s ``` -------------------------------- ### Fetch Next Page of Transactions Source: https://docs.trading212.com/api/section/pagination/example Use the full nextPagePath from the previous response to retrieve the next set of transaction data. This process is repeated until nextPagePath is null. ```bash curl -X GET "https://demo.trading212.com/api/v0/equity/history/orders?limit=2&cursor=1760346100000" \ -u "API_KEY:API_SECRET" ``` -------------------------------- ### Place a Limit order Source: https://docs.trading212.com/api/orders Creates a new Limit order, which executes at a specified price or better. Orders can be executed only in the main account currency. This endpoint is not idempotent in the beta version. ```APIDOC ## POST /api/v0/equity/orders/limit ### Description Creates a new Limit order, which executes at a specified price or better. To place a buy order, use a positive quantity. The order will fill at the limitPrice or lower. To place a sell order, use a negative quantity. The order will fill at the limitPrice or higher. ### Method POST ### Endpoint /api/v0/equity/orders/limit ### Order Limitations Orders can be executed only in the main account currency. ### Important In this beta version, this endpoint is not idempotent. Sending the same request multiple times may result in duplicate orders. ### Rate Limit 1 req / 2s ``` -------------------------------- ### Get Reports Source: https://docs.trading212.com/api/historical-events/getreports Periodically call this endpoint to check the status of your requested reports. Once the status is 'Finished', the 'downloadLink' field will contain a URL to download the CSV file. ```APIDOC ## GET /api/v0/equity/history/exports ### Description Retrieves a list of all requested CSV reports and their current status. ### Method GET ### Endpoint /api/v0/equity/history/exports ### Query Parameters - **reportId** (integer) - Optional - The ID of the report to check the status for. ### Response #### Success Response (200) - **dataIncluded** (object) - Information about what data was included in the report. - **includeDividends** (boolean) - **includeInterest** (boolean) - **includeOrders** (boolean) - **includeTransactions** (boolean) - **downloadLink** (string) - URL to download the CSV report if status is 'Finished'. - **reportId** (integer) - The unique identifier for the report. - **status** (string) - The current status of the report. Enum: "Queued", "Processing", "Running", "Canceled", "Failed", "Finished". - **timeFrom** (string) - The start date for the report data. - **timeTo** (string) - The end date for the report data. #### Response Example (200) ```json { "dataIncluded": { "includeDividends": true, "includeInterest": false, "includeOrders": true, "includeTransactions": false }, "downloadLink": "https://example.com/download/report.csv", "reportId": 12345, "status": "Finished", "timeFrom": "2023-01-01", "timeTo": "2023-12-31" } ``` ``` -------------------------------- ### Pagination with Cursor Source: https://docs.trading212.com/api.md All list endpoints use cursor-based pagination to handle large datasets. Use the `nextPagePath` returned in the response to fetch subsequent pages. ```APIDOC # Pagination All list endpoints in the API that return a collection of items (such as historical orders, dividends, and transactions) use **cursor-based pagination** to handle large data sets. ### Parameters * **`limit`** (integer): Specifies the maximum number of items to return in a single request. * **Default:** 20 * **Maximum:** 50 * **`cursor`** (string | number): A pointer to a specific item in the dataset. This tells the API where to start the next page of results. ### How to Paginate The easiest way to paginate is by using the `nextPagePath` field returned in the response. 1. Make your initial request to a list endpoint (e.g., `/api/v0/equity/history/orders`) with an optional `limit` parameter. Do not include a `cursor`. 2. The API will return a response object. This object will contain a list of `items` and a `nextPagePath` field. 3. If the `nextPagePath` field is `null`, you have reached the end of the data, and there are no more pages. 4. If `nextPagePath` is not `null`, **use the entire string value of `nextPagePath`** as the path for your next request. This string contains all the necessary parameters (like `limit` and `cursor`) to get the next page. 5. Repeat this process until `nextPagePath` is `null`. ### Example Here is a step-by-step example of fetching all transactions, 2 at a time. **Request 1: Get the first page** ```bash curl -X GET "https://demo.trading212.com/api/v0/equity/history/orders?limit=2" \ -u "API_KEY:API_SECRET" ``` **Response 1: Note the nextPagePath** ```json { "items": [ { "id": 987654321, "ticker": "AAPL_US_EQ", ... }, { "id": 987654320, "ticker": "MSFT_US_EQ", ... } ], "nextPagePath": "/api/v0/equity/history/orders?limit=2&cursor=1760346100000" } ``` **Request 2: Use the full nextPagePath for the next request** ```bash curl -X GET "https://demo.trading212.com/api/v0/equity/history/orders?limit=2&cursor=1760346100000" \ -u "API_KEY:API_SECRET" ``` **Response 2: Get the next page (and a new nextPagePath)** ```json { "items": [ { "id": 987654319, "ticker": "AAPL_US_EQ", ... }, { "id": 987654320, "987654318": "MSFT_US_EQ", ... } ], "nextPagePath": "/api/v0/equity/history/orders?limit=2&cursor=1660015723000" } ``` **Request 3: Get the final page** ```bash curl -X GET "https://demo.trading212.com/api/v0/equity/history/orders?limit=2&cursor=1660015723000" \ -u "API_KEY:API_SECRET" ``` Response 3: nextPagePath is null, indicating the end ```json { "items": [ { "id": 987654317, "ticker": "AMZN_US_EQ", ... } ], "nextPagePath": null } ``` ``` -------------------------------- ### Request CSV Report Source: https://docs.trading212.com/api/historical-events/requestreport Generates a CSV report with historical account data. Use the returned reportId to track the generation status via GET /history/exports. ```APIDOC ## POST /api/v0/equity/history/exports ### Description Initiates the generation of a CSV report containing historical account data. This is an asynchronous operation. The response will include a reportId which you can use to track the status of the generation process using the GET /history/exports endpoint. Rate limit: 1 req / 30s ### Method POST ### Endpoint /api/v0/equity/history/exports ### Parameters #### Request Body - **dataIncluded** (object) - Optional - Specifies which data to include in the report. - **dataIncluded.includeDividends** (boolean) - Optional - Include dividend information. - **dataIncluded.includeInterest** (boolean) - Optional - Include interest information. - **dataIncluded.includeOrders** (boolean) - Optional - Include order information. - **dataIncluded.includeTransactions** (boolean) - Optional - Include transaction information. - **timeFrom** (string) - Optional - The start of the time range for the report (e.g., 'YYYY-MM-DD'). - **timeTo** (string) - Optional - The end of the time range for the report (e.g., 'YYYY-MM-DD'). ### Response #### Success Response (200) - **reportId** (integer) - The ID of the generated report. #### Error Responses - **400**: Bad Request - **401**: Unauthorized - **403**: Forbidden - **408**: Request Timeout - **429**: Too Many Requests ``` -------------------------------- ### Get Historical Orders Source: https://docs.trading212.com/api/historical-events/orders_1 Fetches a list of historical orders. Supports filtering by ticker and pagination using a cursor. The response contains detailed information about each order fill and the order itself. ```APIDOC ## GET /api/v0/equity/history/orders ### Description Retrieves historical order data with optional filtering and pagination. ### Method GET ### Endpoint /api/v0/equity/history/orders ### Query Parameters - **cursor** (integer) - Optional - Pagination cursor. - **ticker** (string) - Optional - Ticker filter for specific instruments. - **limit** (integer) - Optional - Maximum number of items to return. Max: 50. Example: 21 ### Response 200 Fields (application/json) - **items** (array) - List of historical order fills. - **items.fill** (object) - Details about the order fill. - **items.fill.filledAt** (string) - Timestamp when the order was filled. - **items.fill.id** (integer) - Unique identifier for the fill. - **items.fill.price** (number) - The price at which the order was filled. - **items.fill.quantity** (number) - The quantity of the instrument filled. - **items.fill.tradingMethod** (string) - Enum: "TOTV", "OTC" - **items.fill.type** (string) - Enum: "TRADE", "STOCK_SPLIT", "STOCK_DISTRIBUTION", "FOP", "FOP_CORRECTION", "CUSTOM_STOCK_DISTRIBUTION", "EQUITY_RIGHTS", "SCRIP_STOCK_DIVIDENDS", "STOCK_DIVIDENDS", "STOCK_ACQUISITION", "CASH_AND_STOCK_ACQUISITION", "SPIN_OFF" - **items.fill.walletImpact** (object) - Impact of the fill on the user's wallet. - **items.fill.walletImpact.currency** (string) - Currency of the wallet impact. - **items.fill.walletImpact.fxRate** (number) - Foreign exchange rate applied. - **items.fill.walletImpact.netValue** (number) - Net value of the impact. - **items.fill.walletImpact.realisedProfitLoss** (number) - Realised profit or loss from the fill. - **items.fill.walletImpact.taxes** (array) - List of taxes applied to the fill. - **items.fill.walletImpact.taxes.chargedAt** (string) - Timestamp when the tax was charged. - **items.fill.walletImpact.taxes.currency** (string) - Currency of the tax. - **items.fill.walletImpact.taxes.name** (string) - Enum: "COMMISSION_TURNOVER", "CURRENCY_CONVERSION_FEE", "FINRA_FEE", "FRENCH_TRANSACTION_TAX", "PTM_LEVY", "STAMP_DUTY", "STAMP_DUTY_RESERVE_TAX", "TRANSACTION_FEE" - **items.fill.walletImpact.taxes.quantity** (number) - Amount of the tax. - **items.order** (object) - Details about the original order. - **items.order.createdAt** (string) - The ISO 8601 formatted date of when the order was created. - **items.order.currency** (string) - The currency used for the order in ISO 4217 format. - **items.order.extendedHours** (boolean) - If true, the order is eligible for execution outside regular trading hours. - **items.order.filledQuantity** (number) - The number of shares that have been successfully executed. - **items.order.filledValue** (number) - The total monetary value of the executed portion of the order. - **items.order.id** (integer) - A unique, system-generated identifier for the order. - **items.order.initiatedFrom** (string) - Enum: "API", "IOS", "ANDROID", "WEB", "SYSTEM", "AUTOINVEST", "INSTRUMENT_AUTOINVEST" - **items.order.instrument** (object) - Instrument information. - **items.order.instrument.currency** (string) - Instrument currency in ISO 4217 format. - **items.order.instrument.isin** (string) - ISIN of the instrument. - **items.order.instrument.name** (string) - Name of the instrument. - **items.order.instrument.ticker** (string) - Unique instrument identifier. Example: "AAPL_US_EQ" - **items.order.limitPrice** (number) - Applicable to LIMIT and STOP_LIMIT orders. - **items.order.quantity** (number) - The total number of shares requested. - **items.order.side** (string) - Enum: "BUY", "SELL" - **items.order.status** (string) - Enum: "LOCAL", "UNCONFIRMED", "CONFIRMED", "NEW", "CANCELLING", "CANCELLED", "PARTIALLY_FILLED", "FILLED", "REJECTED", "REPLACING", "REPLACED" - **items.order.stopPrice** (number) - Applicable to STOP and STOP_LIMIT orders. - **items.order.strategy** (string) - Enum: "QUANTITY", "VALUE" - **items.order.ticker** (string) - Unique instrument identifier. Example: "AAPL_US_EQ" - **items.order.timeInForce** (string) - Enum: "DAY", "GOOD_TILL_CANCEL" - **items.order.type** (string) - Enum: "LIMIT", "STOP", "MARKET", "STOP_LIMIT" - **items.order.value** (number) - The total monetary value of the order. - **nextPagePath** (string) - Path to the next page of results. ### Error Responses - **400**: Bad Request - **401**: Unauthorized - **403**: Forbidden - **408**: Request Timeout - **429**: Too Many Requests ```