Does trading212 have an API?

This would be great. I’d like to play with it. I wish for a simple API which allows for buying/selling stocks.

Hi,
i´m writing a robo-trader based on trading212 and so i can share my swagger with you.

2 Likes

Nice just had a peer through.

Noticed you did the copy and paste on cookie too.

I did the same with my PHP screener. The cookie hasn’t yet expired, so seems to have a very very very long lifetime.

I couldnt be faffing about at working out the back in forth to generate it.

I haven’t tried opening a position, but I’d love to get to a point where it can detect very over sold automatically and place orders on my behalf.

I’m not familiar with Swagger so have no idea what to do.

the cookies expire in about 50 years. If you go through the lines, you can find an expiring date.
the only thing that makes a cookie invalid, is when you generate a new one. and that is happening if you refresh you´re login. so if you never login after you copied a cookie, it will work for years :wink:

I did so. but you can´t do it without running through a script (in my case) and that is nothing for a swagger docu.

it´s not very easy to use the cookie with a login script, but it is possible.

what is your´re plan, that you need an API?
possibly i can help you anouther way than swagger

It doesn’t expire with a new login. Well at least not for me. I login daily and the cookie I have in my script was pasted in about 4+ months ago.

It’s a bit of a security issue in my mind, as they should be being revoked or have a shorter expiry in case they got exposed.

ok then please give me you`re cookie :stuck_out_tongue:

but you could compare the old one from your script with a new one, generated today.
maybe you can find some differences and tell me them. a constant working cookie would be very nice :blush:

Easiest way is with Guzzle.

Screenshot 2020-11-20 at 14.40.04

use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
	private function postJSON($url, $payload)
	{

        $jar = CookieJar::fromArray(
            [
                'TRADING212_SESSION_LIVE' => $this->session
            ],
            'trading212.com'
        );

        $client = new Client(['cookies' => $jar]);

        $response = $client->post($url, ['json' => $payload,]);

        return json_decode($response->getBody());
	}

Yeah the session I got just logging in is fresh, and it doesn’t kill previous sessions getting new ones. So once that SESSION_LIVE is pasted in it’ll last forever.

I was just maybe gonna play with it, see what’s exposed and maybe get inspired to come up with a plan. No worries, though; got enough on my plate without learning another framework :smiley:

ok thank you. i will check this out.

+1 for official REST API

hey alextee, you can check out my swagger. possibly it is helpful for you.
you can find it in this message thread

An official REST API would be really useful.

I need read-only access for generating a stock tracker so I can have a consolidated view of my investments with additional information that Trading 212 doesn’t provide.

2 Likes

I subscribe. @kingrio how did you generate the swagger?

Would be so nice to get an (open to the public) API available in 2021 especially now that ProQuant has been closed. I believe PQ have proven that there is interest for algorithmic trading on T212 and this would open up more revenue streams for T212 so hopefully :pray: we will get in the new year :pleading_face:

3 Likes

What type of API are people expecting? stock prices? buy and sell stocks?

Am I the only one thinking that the Trading 212 API when it is available won’t be free? or maybe have different sub levels. I mean have you tried finding stock market data API, almost all of them offer a very basic tier of limits per day and even to get a decent level you need to pay £10 a month or even up to £1000 a month for a realtime one. Anything free would be subject to abuse possibly.

Well “GET” should be free imho. “POST” ,“PUT” might be behind pay wall.

yeah let’s hope there is some kind of free access, I think it will probably be like any other API with a ‘play’ level of access for free and anything else pay wall. I’ve just looked and interactive brokers have an API and there are multiple types of API access but it’s hard to find out what they actually cost, the market data has loads of different prices for different markets, if anyone wants to help me decipher it the link is below.

general API home:

market data cost:

realtime quotes and even detailed historical data is expensive and even very expensive api’s have rate limits (naturally)

I have posted following a while ago