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.