Python Portfolio Tracker

You can view my entire project in my github repository:
Trading212 Portfolio

Description

The goal of this project is to get your Trading212 portfolio, calculate your returns and show everything in a graph without having to log in to the trading 212 website. This is achieved by getting the order information from a provided csv and/or the gmail of the user and searching in yahoo finance for the current price of the stock using the ISIN.

Image example of script output

Information

This project is designed for accounts with EURO currency. It converts Usd, GBp, and Nok to euro. You can add more conversions by adding a conversion variable in the yahooInfo function. (dont forget to use it after the “convert everything to euros if necessary” comment)

Place your (order data).csv which you can download from Trading212 (instructions here) and selecting ONLY the orders as included data. You need to name this file as orders and replace my own file.

You can also use your gmail (if it receives the emails from Trading212) in order to automatically update the orders data. Beware my script only gets the data from the “Contract Note Statement from Trading 212” so if you are informed about an order via the “Monthly statement” the code won’t know anything about it.

6 Likes

Awesome. Going to take a look at it.

1 Like

You might also want to check this: Trading 212 Desktop App

1 Like

Do you mean if my account is in USD, the code will run but the outputs will be in EUR?

I read your Github and you mention ‘we’ a lot. Did a few people make this?

1 Like

If you don’t want to get the newest changes in your account using gmail then the Money Invested chart will be in your currency (even though it will show Euros) and the Current Stock Value chart will be in euros. The profit/loss bars will also be wrong since they will subtract from Current Stock Value the Money Invested (in your case it will be Euro - Usd). However, the fix in this case is reatively easy and I will post the answer probably today in the readme of my github.

If you are going to use the email fuctionality the script will probably break. This is because when it gets strings from the email to get the numbers it needs, I have used the word Euro that the string contains to split it where I want. It is a little more difficult to fix this because I don’t have an email from trading 212 in another currency to test it.

This project has been developed exclusively by me. English is my second language and it sounded kind of arrogant to use the word “I” so many times.

I’m joking, don’t worry. I hate that data scientists and software engineers say “we” :grin:

Thanks for the info, that makes sense.

1 Like

It’s okay man. I also updated the readme in case you want to use it for Usd. You did well to point it out in case anybody else wants to change the currency

Nice. Will check it out tomorrow. Thanks !

ps: Python <3

1 Like

Well done for sharing this! Open banking in action!!

If you could add Revolut Trading support, so that I could see a consolidated view of both my Revolut Trading and T212 portfolios, this would be a killer app!

Also a feature to generate the file I need to file my taxes on trade gain/loss !

1 Like

When you write that this converts everything to EUR.

I am in Europe and do want to see my portfolio returns in EUR, but my T212 base currency is USD.

Let’s say I buy a stock on NASDAQ at 100$ and exchange rate is 1.20$. 2 weeks later, the stock price is still 100$ but exchange rate is 1.18$

I would have gained 1.4€ just on the exchange rate fluctuation. Would your program return this result?

There has been some time and I can’t edit the orginal post, but I have updated the program to use whatever currency you use in trading 212. You can always read the readme to see the most up to date instructions.

To change the currency to your own trading212 currency go to myPortfolio.py and change the variables USER_CURRENCY and USER_SYMBOL accordingly. For example for GBP you need to have USER_CURRENCY = "GBP" and USER_SYMBOL = "£"

Unfortunately, I haven’t added the ability to change everything from trading212 currency to another currency because that’s something very specific and doesn’t concern a lot of people.
In your case, you will have to have `USER_CURRENCY = “USD” because that’s the currency your account uses.

Taxes is something very difficult to make in a program like this because they depend on your income. What is more, even if 2 people made the exact same money they will pay different taxes if they live in a different country. That’s why it’s almost impossible for me to implement and to tell you the truth I am too bored to even consider it :joy:

Thanks for this update. In my scenario where I make a small € gain just on currency fluctuation when the USD stock price does not move, will your software flag it as a € gain ?

Yes, it will. It gets the newest currency exchange rates from yahoo finance even if the market is closed

Nice work. I’ve been building something similar to this myself. I’ll give it a try.

Hopefully in the future we can get an official API which just lets us download our portfolio as JSON. You can get that data already, but you have to intercept the WebSockets stream via the browser.

1 Like