Trading 212 API Update 🛠️

You can now place Market Orders via the Trading 212 API for live accounts!

While still in beta, this marks the next phase of the rollout, with a major API upgrade on the way in the coming months. :rocket:

Explore the updated API docs here.

Let us know if you’ll give it a go - and feel free to share any questions or feedback below!

17 Likes

This is great news!

Can you please share the API roadmap as well for the upcoming months? :tada:

6 Likes

We have a number of enhancements planned over the coming months, but we’ll keep the details under wraps for now. We’ll be sharing updates as they roll out.

In the meantime, please let us know what you would like to see from the API.

8 Likes

The API needs the ability to access foreign exchange rates ie GBPUSD, which the App has access to.

Else the local currency value of a position cannot be calculated.

6 Likes

This is great news, and we’ve been waiting for it for a long time! :+1:

Please stay the course and keep going!! :flexed_biceps: :flexed_biceps: :flexed_biceps:

3 Likes

This is great news! Looking forwarding to building an investment bot!

2 Likes

Great news! It would be good if the tickers when pulling a list of orders were the ‘real’ tickers for a security (ie. AAF.L rather than AAFl_EQ). I’m having to maintain a dictionary to then get some market info on the ticker from the yahoo finance api. Unless if there is an easier way to do it? Many thanks.

6 Likes

Completely agree. Having to parse the non-standard ticker names is a nightmare. It almost takes up more code than my app’s core logic!

Looks like you can get the ticker name from /instruments/metadata, I never realised that!

3 Likes

Hi, I have been trying the API for the Demo. In your manual to obtain API keys, there is stated that I will get “API Key” and “API Secret” in the App, but I have been only given the “API Key”. Is there a new a authentication process than described? Or is API only accessible only for some users these days? I also tried the authorisation only simply using the API Key, but being given “401” error. What could I be doing wrong? If someone already successfully made it, would you be please able to share a short example of Python code e.g. to get all open positions that worked for you? Thanks!! :slightly_smiling_face:

@velkejdomi, when you create your API key, you’ll also receive a Secret Key. For security reasons, Secret Keys are only visible at the moment the API key is created.

1 Like

I’ve just wasted so long trying to work out how to generate a secret key… the iOS app doesn’t display a secret key. It wasn’t until I deleted it and went via the website it generated one. Might want to fix that.

Even more annoying when the ticker name is some historial name that no longer exists. There needs to be a method that provides the current symbol. e.g. ACIC→ACHR

1 Like

@KrisG Thank you for the update. While creating the API key, Order execute is still disabled on iPhone and states “Available in practice mode only.“ It works on the Android device.

Update: With the latest app update, it is available.

@KrisG The documentation is not consistent. It provides Python code to show authentication, but the portfolio example still uses username and password. It will be great if the team provide consistent and working examples.

import requests

url = "https://live.trading212.com/api/v0/equity/portfolio"

response = requests.get(url, auth=('<username>','<password>'))

data = response.json()
print(data)

UPDATE: Working version

import requests

credentials_string = f"{api_key}:{api_secret}"
encoded_credentials = base64.b64encode(credentials_string.encode('utf-8')).decode('utf-8')
header = f"Basic {encoded_credentials}"

url = "https://live.trading212.com/api/v0/equity/portfolio"
response = requests.get(url, headers={"Authorization":header)

data = response.json()
print(data)
2 Likes

Hi @KrisG !

This is honestly an excellent news! I’m so happy and been waiting for this day!

What I would really suggest however for your next update, could you please please allow extendedHours option for stop limit orders (and all other orders) as many traders would benefit from this to prevent unwanted order executions.

Cheers

1 Like

I don’t know what I am doing wrong but I keep getting 401 unauthorized.

I’ve created two API keys now, one with everything but restricted to my IP address, and another which just has a couple of scopes, Account data and metadata. Neither are working, so I can only assume it’s something I’m doing wrong?

I am doing the following on my Raspberry Pi in bash

CREDENTIALS=$(echo -n "358758[redacted]:9X[redacted]" | base64)

Both the API Key ID and Secret Key have been copied directly from the website key generator screen

curl -i -X GET "https://demo.trading212.com/api/v0/equity/account/info" -H "Authorization: Basic $CREDENTIALS"
HTTP/1.1 401 Unauthorized
Date: Mon, 06 Oct 2025 09:34:22 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 1
Connection: keep-alive

I’ve tried both demo and live, neither work.

OK, I think I have solved it by modifying the command to generate the $CREDENTIALS variable by added -w 0 to the base64 command

CREDENTIALS=$(echo -n "358758[redacted]:9X[redacted]" | base64 -w 0)
curl -i -X GET "https://live.trading212.com/api/v0/equity/account/info" -H "Authorization: Basic $CREDENTIALS"
HTTP/1.1 200 OK
Date: Mon, 06 Oct 2025 10:05:38 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
  -w, --wrap=COLS       wrap encoded lines after COLS character (default 76).
                          Use 0 to disable line wrapping

Or even better just return the local currency value in the /api/v0/equity/portfolio response as a new field.

Additionally an API endpoint to get a list of my Pies and their current value in local currency would be nice.

I have a strange issue with the API.

Let’s say I own 90 shares of METC_US_EQ. I try to sell 1 via the API and I get:

Selling 1 x METC_US_EQ
{‘code’: ‘SellingEquityNotOwned’, ‘clarification’: ‘SellingEquityNotOwned’}

So I use the API to buy one instead and it works:

Buying 1 x METC_US_EQ
{‘strategy’: ‘QUANTITY’, ‘id’: 39911966885, ‘type’: ‘MARKET’, ‘ticker’: ‘METC_US_EQ’, ‘quantity’: 1, ‘filledQuantity’: 0, ‘status’: ‘NEW’, ‘creationTime’: ‘2025-10-07T20:44:46.636+03:00’, ‘extendedHours’: False}

I try selling again, only this one, and it also works:

Selling 1 x METC_US_EQ
{‘strategy’: ‘QUANTITY’, ‘id’: 39911967056, ‘type’: ‘MARKET’, ‘ticker’: ‘METC_US_EQ’, ‘quantity’: -1, ‘filledQuantity’: 0, ‘status’: ‘NEW’, ‘creationTime’: ‘2025-10-07T20:45:41.664+03:00’, ‘extendedHours’: False}

Now I try selling another one but no luck:

Selling 1 x METC_US_EQ
{‘code’: ‘SellingEquityNotOwned’, ‘clarification’: ‘SellingEquityNotOwned’}

I do have 90 shares though!

Do I need to buy them via the API to be able to sell them via the API as well?

Many thanks,

David