Generating a CSV of complete trading history. (ISA)

Hi,

I am trying to incorporate my trading212 portfolio into a wider system and would like to have access to my trading history such that I can keep a record of the market price, prices that I paid, the exchange rate at the time that I made the purchase. The exchange rate being my main stumbling block.

I have written a basic script to read through my contract note emails (I only have the last month or so of these, If I had them all, this wouldnā€™t be a problem) and the Monthly Statement. The Monthly Statement has the Price and Market Price, but these are mostly in USD instead of GBP. Applying an exchange rate at this point would be inaccurate regardless. What I need really is a deposit/investment total in GBP for each instrument.

I have seen others post things like this link but the data there is just what is shown on the Monthly Statement. I am wondering if there is something like that but for purchase history or anything that would help at all?

I could potentially build a webscraper to pull out the history for each investment, but I would like to avoid this if possible.

Sorry if this is a bit waffly, Itā€™s super late over here right now.

I should say, Iā€™ve seen someone post on here a chrome extention that generates a csv of your holdings, but it cannot handle pieā€™s or and big enough order history.

ok, this looks promising -> https://github.com/praveendath92/Trading212-CSV-Exporter

1 Like

Scrape it. Look at the network calls through your browser when logged in. Look at the ā€˜orders?ā€™ API call and date parametersā€¦ throw them at your browser and pull out the json ā€¦ works well enough for meā€¦

1 Like

perfection :partying_face:

oh nice, you got it to work?

Im not sure, trying to figure out if i can get a sessionID using requests? There is always selenium of course, Iā€™m just trying to not use that so I learn something new.
I did think I had just blocked my IP or something, but i think my internet is just being tempermental.

EDIT: my internet is not being tempermental

Hereā€™s a bit of code I used before, you might be able to re-jig it somehow.

def get_session_id():

    session = requests.Session()
    url = 'your-website'

    r = session.get(url)
    session_id = r.cookies.get_dict()
    session_id = session_id.get('ASP.NET_SessionId_eReg') # might be different for T212

    return session,session_id

I think the trouble is you need to be logged in.

I am trying to post to
ā€œhttps://www.trading212.com/en/authenticateā€
or ā€œhttps://www.trading212.com/en/loginā€

But something is stopping me. I think there is a value that is generated when the page loads that is required in the login post. But I am not sure yet how to get it.

Itā€™s why I force an Internet Explorer objectā€¦that loads the sessionIdā€¦ then make the API call through the same browser with the same sessionIdā€¦ primitive, messy, not clever but works!

2 Likes

much better than ā€œbrilliant, amazing, art of engineering, but doesnā€™t workā€ :grin:

3 Likes

as long as its all on one line iā€™m happy.

1 Like

Wonder if you can load that csv in https://www.portfolio-performance.info/

do you know how the csv needs to be formatted (column names)?

Theyā€™ve done it! Currently, you can export from iOS and Android