New Equity Trading API in Beta - Try it Out in Practice Mode!

Thanks for the update!

Please reach out to me when you continue working on the API and need feedback from integrators. I have built popular SDKs for Coinbase & Binance in TypeScript.

I have also implemented every Trading 212 endpoint in my npm library for JavaScript/TypeScript (including payload validation & request limits :metal:): GitHub - bennycode/trading212-api

Excited to see your development progressing!

Best,
Benny

1 Like

Hey @KrisG,

Apparently the order of dividend payments from the /api/v0/history/dividends has changed, was that on purpose?

Before, the response would have the dividend payments in order of latest payment to oldest.

Example of how it was
{
    "items": [
        { "paidOn": "2024-06-13T12:00:00.000+03:00", ... },
        { "paidOn": "2024-06-13T11:00:00.000+03:00", ... },
        { "paidOn": "2024-06-12T14:00:00.000+03:00", ... },
        ...
        { "paidOn": "2024-05-28T09:00:00.000+03:00", ... },
        { "paidOn": "2024-05-02T15:00:00.000+03:00", ... },
        ...
    ],
    "nextPagePath": "..."
}

And now the order seems random, with dividends from the previous month sometimes mixed in with dividends from this month.

Example of how it is right now
{
    "items": [
        { "paidOn": "2024-05-02T15:00:00.000+03:00", ... },
        { "paidOn": "2024-06-12T14:00:00.000+03:00", ... },
        { "paidOn": "2024-06-13T11:00:00.000+03:00", ... },
        { "paidOn": "2024-05-28T09:00:00.000+03:00", ... },
        { "paidOn": "2024-06-13T12:00:00.000+03:00", ... },
        ...
    ],
    "nextPagePath": "..."
}

In my current use case, I get the amount of dividends received in the last X months.
Before, I just had to iterate over the payments endpoint’s pages until a date outside of my range was reached, then I could safely stop paginating it.
If I want to implement this now, I’ll have to iterate over all the pages in the endpoint to make sure that I won’t miss any payment that’s in my desired range, and that isn’t good for any of us.

Could you please reset the sorting to how it was?


EDIT: Actually, the pagination is flat out broken: it returns repeated payments. Here are real responses, slightly redacted:

GET /api/v0/history/dividends?limit=5
{
  "items": [
    {
      "ticker": "SHELLa_EQ",
      "reference": "f5731a42-21a6-4b97-9164-13e61dafadca",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.3166,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-28T17:20:07.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "QCOM_US_EQ",
      "reference": "e411284f-fa30-41be-ad43-841d109a9d8e",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.85,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-20T12:45:58.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "GRMN_US_EQ",
      "reference": "50589886-5db4-4725-bed0-a9de5964bd97",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.75,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-28T17:03:12.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "NVDA_US_EQ",
      "reference": "f79bce10-b9e6-433a-a331-7583d0cd4e88",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.01,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-28T18:24:03.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "DLR_US_EQ",
      "reference": "ba10b27f-3739-422c-b4bf-38c4a4aa9c8a",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 1.22,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-28T18:16:03.000+03:00",
      "type": "DIVIDEND"
    }
  ],
  "nextPagePath": "/api/v0/history/dividends?limit=5&cursor=70172961"
}

Now, using the cursor to fetch the next page, 3 of the payments returned were also part of the previous response and the provided cursor for the next page does not change:

GET /api/v0/history/dividends?limit=5&cursor=70172961
{
  "items": [
    {
      "ticker": "TEFe_EQ",
      "reference": "3cbd278e-1f93-4911-a17b-8d9e84b18963",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.15,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-20T12:44:12.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "SHELLa_EQ",
      "reference": "f5731a42-21a6-4b97-9164-13e61dafadca", // <-- repeated
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.3166,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-28T17:20:07.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "QCOM_US_EQ",
      "reference": "e411284f-fa30-41be-ad43-841d109a9d8e", // <-- repeated
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.85,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-20T12:45:58.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "GRMN_US_EQ",
      "reference": "50589886-5db4-4725-bed0-a9de5964bd97", // <-- repeated
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.75,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-28T17:03:12.000+03:00",
      "type": "DIVIDEND"
    },
    {
      "ticker": "GOOGL_US_EQ",
      "reference": "3fffb566-edc9-4664-9cca-8518ecf6c265",
      "quantity": {{redacted}},
      "amount": {{redacted}},
      "grossAmountPerShare": 0.2,
      "amountInEuro": {{redacted}},
      "paidOn": "2024-06-17T16:14:12.000+03:00",
      "type": "DIVIDEND"
    }
  ],
  "nextPagePath": "/api/v0/history/dividends?limit=5&cursor=70172961"
}
1 Like

My order history is completely inaccessible. Other parts of the API work with the same authorisation details.

HTTP/1.1 403 Forbidden
Content-Length: 0
x-envoy-upstream-service-time: 1
Expires: Tue, 02 Jul 2024 20:26:50 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Tue, 02 Jul 2024 20:26:50 GMT
Connection: keep-alive
Strict-Transport-Security: max-age=31536000 ; preload

It doesn’t matter how I try to format the URL it is always forbidden.

curl -iH "Authorization: $(<${HOME}/.config/T212)" 'https://live.trading212.com/api/v0/equity/history/orders?limit=10'

Working example:

$ curl -iH "Authorization: $(<${HOME}/.config/T212)" 'https://live.trading212.com/api/v0/equity/portfolio/GSKl_EQ'
HTTP/1.1 200 OK
Content-Type: application/json
x-envoy-upstream-service-time: 8
Expires: Tue, 02 Jul 2024 20:29:34 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Tue, 02 Jul 2024 20:29:34 GMT
Content-Length: 271
Connection: keep-alive
Strict-Transport-Security: max-age=31536000 ; preload

Thank you for the detailed reports, everyone :pray:

I have forwarded the information to our team, and the reported issues will be reviewed. I’ll let you know once there are any updates.

1 Like

What base URL are you using with the production (non-practice mode) API keys? Surely prod is not on demo.trading212.com/api too?

EDIT - just tested, prod API keys work fine for me on live.trading212.com

EDIT AGAIN - looks like the guy asking why his prod API keys weren’t working against the demo API for 3 months decided that instead of acknowledging where he was going wrong, it would be better to just delete his posts and disappear. For the benefit of others, the base url for the demo API is demo(dot)trading212(dot)com, whereas the live API is live(dot)trading212(dot)com.

Hello, thank you for working on the API functionality.

The feature to import investments (into an already existing pie) is highly requested.

This is already implemented: More Actions: Import shares into Pies – Trading 212

Yes, of course, the functionality is available, but the API is not yet accessible as mentioned in the API documentation.

1 Like

Ah, my bad, I forgot the topic we’re on :upside_down_face:

Is there any news when CFD data will be added to the API?

Not at the moment. When we resume work on the API, we’ll be able to set clear priorities.

Did you find a solution? I’m also getting

Both or none of cursorId and time must be provided

Has anyone been able to get value orders to work? I am following a plan from my advisory software which emails when the plan has fired and would love to automate it using the T212 API. Of course, this is being tested in the demo version for now until T212 release the equity orders to the Live Account.

I have been able to get the code to sell all holdings, however when buying, I want the order to be a value order instead of a quantity order.

Also another question… when will the equity order feature be available for the live account? :eyes:

@KrisG there is a bug with the pies.
I fetch my pies thorugh the API, all looking good. So there are 4 items.
Then I use {{baseUrl}}/api/v0/equity/pies/:id to fetch the details of the pie.
The first and the last one works. Second or third somehow is not fetching.
Even though, I can see their ids, when I query them I get this error;

{
    "code": "Pie not found"
}

PS: In the web version, I can see all requests are find but could not figure out what cause this issue.

I have even enabled sharing on all of them did not change the result.
Are you aware of the issue?

Thanks!

Please fix situation with cursor in get historical orders endpoint, API endpoint doesn’t return all historical orders which I have. Example: when I get info about all historical orders (going through all pages using cursor) I receive only one order for ticker X, when I call the same endpoint with ticker filtering, I’m getting 3 orders

1 Like

Heya … is there any update on this. In particular I am missing the following :

  1. Ability to trigger a pie rebalancing via the API
  2. Ability to identify if a stock is available for fractional buy before moving it into a pie.

Thanks for the amazing work

The ‘portfolio’ endpoint has been working fine… until I bought some HBR shares. When I hit the endpoint it returns “ticker” => “PMOl_EQ” – it has attached the ‘PMO’ symbol when it should be using ‘HBR’ (as confirmed in the UI).

This works really well in demo mode.
When is your target release date for live.

Hi all,
I’ve been writing an app script to use in a google spreadsheet to query the avg price of all stock in my portfolio using this api: https://live.trading212.com/api/v0/equity/portfolio/{ticker}
I frequently get the 429 too many requests error and I haven’t managed to find a solution to that. It seems that:

  1. the rate limit is imposed by cloudflare CDN. I lookup online and I found this " The global rate limit for the Cloudflare API is 1200 requests per five minutes per user, and applies cumulatively regardless of whether the request is made via the dashboard, API key, or API token. If you exceed this limit, all API calls for the next five minutes will be blocked, receiving a HTTP 429 response ." I do not believe that google spreadsheets surpass this limit as I’ve configured the api to execute at document open. Is there a way I can monitor the request that start client side and those that actually arrive on server? Anyone knows? Cloudflare policy blocks you for five minutes and this seem to be working as stated. So I tried by randoming delaying invocation using a sleep method but this also is not working around my problem completely. Anyone found any elegant solutions? Custom function in Google need to complete within 30 secs or get sacked by default. My impression is that Google sends too many request of that function. I only have 50 rows in the table where I use the function so it is unlikely that I go over the stated 1200 request per user limit.
  2. Meta and Booking new tickers (META and BKNG) don’t work via API, you have to use old tickers PCLN and FB respectively.

Thank you in advance for any help coming this way.

1 Like

I need API to fetch stock latest price and historical price.

1 Like