# Python Portfolio Tracker

**URL:** <https://community.trading212.com/t/python-portfolio-tracker/46132>\
**Category:** 💡 Feature suggestions & ideas\
**Created:** [February 17, 2021, 11:01am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132 "2021-02-17T11:01:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 17, 2021, 11:01am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/1 "2021-02-17T11:01:31Z")

</div>

You can view my entire project in my github repository:  
[Trading212 Portfolio](https://github.com/alex999ar/Trading212Portfolio)

### 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

 ![example_output](https://europe1.discourse-cdn.com/flex013/uploads/trading212/original/2X/3/3959d39e80fe011909c087074214558170c0263d.png)

### 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)](https://community.trading212.com/t/new-feature-export-your-investing-history/35612) **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.

---

<div class="post-metadata">

**Author:** ![chantal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.trading212.com/chantal/32/12676_2.png) [@chantal](https://community.trading212.com/u/chantal)\
**Post date:** [February 18, 2021, 10:59am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/2 "2021-02-18T10:59:00Z")

</div>

Awesome. Going to take a look at it.

---

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 20, 2021, 9:29pm UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/3 "2021-02-20T21:29:02Z")

</div>

You might also want to check this: [Trading 212 Desktop App](https://community.trading212.com/t/trading-212-desktop-app/46386)

---

<div class="post-metadata">

**Author:** ![obrienciaran](https://dub1.discourse-cdn.com/flex013/user_avatar/community.trading212.com/obrienciaran/32/2705_2.png) [@obrienciaran](https://community.trading212.com/u/obrienciaran)\
**Post date:** [February 20, 2021, 11:23pm UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/4 "2021-02-20T23:23:19Z")

</div>

> [@alex999ar](#):
>
> **This project is designed for accounts with EURO currency**. It converts Usd, GBp, and Nok to euro

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?

---

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 21, 2021, 8:52am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/5 "2021-02-21T08:52:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![obrienciaran](https://dub1.discourse-cdn.com/flex013/user_avatar/community.trading212.com/obrienciaran/32/2705_2.png) [@obrienciaran](https://community.trading212.com/u/obrienciaran)\
**Post date:** [February 21, 2021, 10:32am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/6 "2021-02-21T10:32:16Z")

</div>

> [@alex999ar](#):
>
> 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” 😁

Thanks for the info, that makes sense.

---

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 21, 2021, 6:29pm UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/7 "2021-02-21T18:29:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HighwaytoHell](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@HighwaytoHell](https://community.trading212.com/u/HighwaytoHell)\
**Post date:** [February 21, 2021, 6:53pm UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/8 "2021-02-21T18:53:59Z")

</div>

Nice. Will check it out tomorrow. Thanks !

ps: Python \<3

---

<div class="post-metadata">

**Author:** ![ppt2](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@ppt2](https://community.trading212.com/u/ppt2)\
**Post date:** [February 27, 2021, 9:08am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/9 "2021-02-27T09:08:41Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![ppt2](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@ppt2](https://community.trading212.com/u/ppt2)\
**Post date:** [February 27, 2021, 9:14am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/10 "2021-02-27T09:14:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 27, 2021, 9:51am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/11 "2021-02-27T09:51:20Z")

</div>

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.**

---

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 27, 2021, 10:00am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/12 "2021-02-27T10:00:21Z")

</div>

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 😂

---

<div class="post-metadata">

**Author:** ![ppt2](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@ppt2](https://community.trading212.com/u/ppt2)\
**Post date:** [February 27, 2021, 5:35pm UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/13 "2021-02-27T17:35:08Z")

</div>

> [@alex999ar](#):
>
> In your case, you will have to have `USER\_CURRENCY = “USD” because that’s the currency your account uses.

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 ?

---

<div class="post-metadata">

**Author:** ![alex999ar](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alex999ar](https://community.trading212.com/u/alex999ar)\
**Post date:** [February 27, 2021, 7:52pm UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/14 "2021-02-27T19:52:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andybrice](https://dub1.discourse-cdn.com/flex013/user_avatar/community.trading212.com/andybrice/32/3388_2.png) [@andybrice](https://community.trading212.com/u/andybrice)\
**Post date:** [March 1, 2021, 11:58am UTC](https://community.trading212.com/t/python-portfolio-tracker/46132/15 "2021-03-01T11:58:25Z")

</div>

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.
