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

Hey @Momchil.G ,

Thanks very much for the reply.

OK. Understood. I was simply making a total novice’s leap of logic.

Right. I can see I’m on the verge of a very deep Rabbit hole here. I have my work cut out for me no doubt.

Thanks again for your help. Much appreciated.

CT

Hi @ s2409,

The following code has been successfully tested with the live and not the demo version, but it should work as well.

function T212APICall(url) {
  const params = {
    "method":"GET",
    "headers":{
      "Authorization":T212_API_KEY
    },
    "muteHttpExceptions":false
  };

  let response = null;
  let respCode;
  try {
    response = UrlFetchApp.fetch(url, params);
    respCode = response.getResponseCode();
  } catch (e) {
    respCode = parseInt(e.message.replace(/^.+?returned code (\d+)/g, '$1'));
  }
  return {'error': respCode, 'response': response};
}

Needless to say, one must replace T212_API_KEY with the actual key.

Hope this helps.

1 Like

Hello, could you please add value/filled value to API response when making market orders so that its easier to know at wich exact price was the share bought/sold ? Thank You {
“strategy”: “QUANTITY”,
“id”: 27150016439,
“type”: “MARKET”,
“ticker”: “PLTR_US_EQ”,
“quantity”: -0.1,
“filledQuantity”: 0,
“limitPrice”: null,
“stopPrice”: null,
“status”: “NEW”,
“creationTime”: “2025-02-20T21:31:06.498+02:00”,
“value”: null,
** “filledValue”: null**
}

I fully agree. The date of XTB end of API Support is March 14 (2025)

Your swagger file has seemingly not been tested, and is unfortunately invalid. It’s not an OpenAPI spec.

You have spaces in object names – not allowed:

Line 244: “$ref”: “#/components/schemas/Tradeable instrument”
Line 2270: “Tradeable instrument”

These should, presumable, read TradingInstrument or similar.

Is there any way to extract the debit spending with all the information regarding the debit spending using the trading 212 card using the API?

I tried everything, but nothing seemed to work.
The only way I can get this information is by going to the app or website and manually selecting the export button and selecting transactions.

Is this something that will be added later into the API data?

Currently, order execution isn’t available, but we plan to enable it soon.

Hello, is this going to be enabled anytime soon ? 2 years has passed since you announced it would be soon :slight_smile:

Trading212 enabling the Live API will be an industry game changer for sure.
However, it is related to number of problems, obstacles, correct limitations and security concerns so it is not an easy thing to release for sure.

Hi, I think it would be great if Trading212 could expose company stats via an API endpoint as itt would help users to programatically evaluate a stock. Do you think this is possible?

Thanks,
Adam

I am regularly checking this thread for any news on the live API, seems like it is no longer a priority to implement it.

2 Likes

hello,
I have one case:
+“type”: “MARKET”
+“id”: 29056570142
+“fillId”: 29056570144
+“parentOrder”: 29056570134
+“ticker”: “MSFT_US_EQ”
+“orderedQuantity”: null
+“filledQuantity”: null
+“limitPrice”: null
+“stopPrice”: null
+“timeValidity”: null
+“orderedValue”: 1582.67
+“filledValue”: 1582.67
+“executor”: “ANDROID”
+“dateModified”: “2025-03-04T16:42:11.000Z”
+“dateExecuted”: null
+“dateCreated”: “2025-03-04T16:42:11.000Z”
+“fillResult”: null
+“fillPrice”: 385.95
+“fillCost”: null
+“taxes”:
+“fillType”: “OTC”
+“status”: “FILLED”

filledQuantity still is empty

The order history API endpoint returns a cursor for the next page, but having run several tests comparing this with data returned via the CSV export, I am certain that the API is missing blocks of orders consistently. The size of the blocks varies depending on the size of the limit, e.g. if the limit is 50, then the no. of orders skipped is under 50, and if the size of the limit is 20 (the default), then the number of orders skipped is under 20. Different orders are skipped depending on the limit size, but if it is re-run with the same limit size, the same orders are skipped. I think what is happening is that in the API backend, when the cursor is being calculated, it is filtering to filled orders only, and returning the cursor based on that. However, the data being returned contains both filled and cancelled orders. The result is that the cursor moves too far ahead, skipping data completely. Given the other parameters available for the orders history API, and the fact that it works through the data in reverse chronological order, there is no client side workaround possible insofar as I can see to be able to retrieve and update a complete order history via the API as things stand (except in an account that has only ever had filled orders, potentially). Has anyone found the same or found a workaround?

thank you for building the API. Few requests in decreasing order of criticality:

  1. May I please highlight a need for historical orders to return exchange rate applied. you have it on web ui/mobile, but without it the historical orders API is kind of useless.

  2. for some reason transaction history returns 99 transactions over the last couple of months, but does not return 6 transactions i had before that

  3. pagination setup in not consistent between endpoints. some endpoints give relative url in the nextPage field, some give only query string

Thank you!
Alex

2 Likes

Also, filledQuantity is null for historical market orders, which is pretty critical.

In general, it would be great if you could bring historical api functionality to be at par with history csv export.

Alex

1 Like

unfortunately it’s filled only when you buy or sell a specific quantity. Otherwise it could be calculated from the purchased value (filledValue), but that is not accurate either.

I do it in such a way that the current quantity is stored in my own application, I make a request over API and the difference will be the purchased quantity.

  1. There are some system related transaction what are still not appears in the API, eg. splits
  2. the pagination in order history is wrong, eg:
    “/api/v0/equity/history/orders?cursor=1745305780000&limit=50&instrumentCode”
    It will skip some orders/pages.

I’m calculating the cursor value based on the last element ‘dateModified’ value in the result array, converting this value into microtime and using for the next request.

Hello,

I’ve made an account here specifically for the API feature in the hopes that development time can be allocated to this again.

It would be very useful if there was a version of the Stocks ISA’s Fetch account cash for the other account types as well. Particularly the Cash ISA.

Cheers,
dans

I found a bug when using the api /v0/equity/history/orders on currency exchange.

I make orders using the EUR currency and when i buy a NASDAQ stock in US dollars the order that is comes from the api does not have the exchange rate but in the app on the history it does exist

EX json object:

{
      "type": "MARKET",
      "id": 31204824293,
      "fillId": 31204824295,
      "parentOrder": 31201253414,
      "ticker": "PSEC_US_EQ",
      "orderedQuantity": null,
      "filledQuantity": null,
      "limitPrice": null,
      "stopPrice": null,
      "timeValidity": null,
      "orderedValue": 8.510000,
      "filledValue": 8.510000,
      "executor": "AUTOINVEST",
      "dateModified": "2025-04-16T18:32:37.000Z",
      "dateExecuted": null,
      "dateCreated": "2025-04-16T18:32:31.000Z",
      "fillResult": null,
      "fillPrice": 3.510000,
      "fillCost": null,
      "taxes": [
         {
             "fillId": "31204824295",
             "name": "CURRENCY_CONVERSION_FEE",
             "quantity": -0.01,
             "timeCharged": "2025-04-16T18:32:37.148Z"
         }
     ],
    "fillType": "OTC",
    "status": "FILLED"
}

The fillPrice is 3.51USD, the value i bought filledValue is 8.51EUR so by calculating the quantity is 8.51/3.51 = 2,4245014245 but into the app is saying 2⁠.⁠7535

Making some research i found out that the currency is missing in my calculation.

Data from the order:

  • Ordered value : €8.51
  • FX fee: €0.01
  • Net amount used to buy: €8.50 (€8.51 - €0.01)
  • Exchange rate (EUR/USD) : 1.13703352
  • Fill price per share : $3.51

Step 1: Convert €8.50 to USD using the exchange rate
8.50EUR * 1.13703352 = 9.66478492USD

Step 2: Divide by fill price ($3.51 per share)
9.66478492 / 3.51 = 2.7535 shares (aprox)

TL;DR;
The currency exchange rate is missing from the history order api retrieve