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