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!