pytr-org / pytr

Use TradeRepublic in terminal and mass download all documents
https://pypi.org/project/pytr/
MIT License
387 stars 70 forks source link

Support for Visa Card transactions #53

Closed MartinScharrer closed 3 months ago

MartinScharrer commented 7 months ago

Trade Republic now has a Debit Visa Card available which spendings are taken out from the Cash account directly. However, pytr (as of V0.1.9) does not include this entries in the generated account_transactions.csv file yet. In addition to the actual spending additional round-up values might be added if the account holder configured it. Therefore, when importing this file into tools like Portfolio Performance the reported Cash amount is off.

Please adapt the script to also produce these entries.

otmezger commented 7 months ago

I also would love to see this. In addition to just the visa transactions, it would be great to get a complete export of the "cash" account, it's basically a normal bank account and exporting it can enable me to import it in my personal finance software (actual budget)

MartinScharrer commented 7 months ago

I now had a look myself and unfortunatly TR seems to not include the VISA card transactions (payments done with card, safeback and round-up ETF buys) in the timeline responses. This is the reason why they are not included by pytr.

I got some success by implementing a timelineTransactions subscription which then appends more timeline_events, but this only gives me some more entries in the events_with_documents.json file like "Round up" and Card Transactions, but not all and some of their PDFs fail to download with API errors. Further investigation is required.

otmezger commented 6 months ago

They must have an API. Both TR web app and mobile app show the card transactions, so they must be serving it somehow. I’m not very familiar with websocket, and was unable to find my way around the code.

MartinScharrer commented 6 months ago

I analyzed the API now. They seem to have added additional subscriptions (timelineTransactions, timelineDetailV2) which need to be used instead of the old ones (timeline, timelineDetail) which are however still supported but do not include the newer entry types like the card transactions.

I forked the project now (https://github.com/MartinScharrer/pytr) and added handling of the new websocket subscriptions and their handling. Still needs some work in order to get the documents downloaded as the structure changed.

MartinScharrer commented 6 months ago

I made the necessary changes (https://github.com/MartinScharrer/pytr/tree/timeline_V2). It works now for me. I will do some further tests and then make a pull request.

otmezger commented 6 months ago

Let me know if you need another hand testing. thanks!

marzzzello commented 6 months ago

@otmezger If you can test the PR that would be great. If everything works I can make a new release

tenjaa commented 6 months ago

I gave it a try and observed a few things by comparing both documents with the following commands:

$dir1 = Get-ChildItem -Recurse -path C:\dir1
$dir2 = Get-ChildItem -Recurse -path C:\dir2
Compare-Object -ReferenceObject $dir1 -DifferenceObject $dir2

it works

I got the new saveback documents. I did not try the round up feature yet so I cannot say anything regarding that.

additional general meeting documents

There are two very recent new documents. They should be there and are just missing in the current version it seems.

different order

I have two deletion confirmations of the same security, same day, same minute. With the current version, the one with the the starting id ac4... gets renamed. With the new version the one with the id 21c... gets renamed. But both documents are present. For me that would be fine.

error

I get the following error message with the new version

Received error message: '106 E {"errors":[{"errorCode":"NOT_FOUND","errorField":null,"errorMessage":"Could not find resource","meta":{"source":"PLATFORM"}}]}'

Interestingly it does not seem to matter. Looking at the logs, there are no files missing from the security that it was just checking when that error occured.

MartinScharrer commented 6 months ago

I got some error with some new documents which do not have the date in the subtitle entry. Some code needs to be coded more robust to handle this.