How to import from XTB?

Nice to know you managed to set it up. I understand it might be tricky in the beginning.

There is one flaw I’ve noticed recently. If you have just 1 account for trading with multiple currencies, then it probably does not work well.
My script expects XTB USD account for USD stocks and XTB EUR account for EUR stocks. Not mixed. I’ve probably mentioned that earlier. It can be fixed but I was lazy :slight_smile:

If anyone experience any problem, let me know.

Changed date format to YYYY-MM-DD as PP works better with that

XTB_convert_run.zip (2.5 KB)

Neu: CSV-Importer für XTB (Cash Operations), einschließlich CFD-Ergebnissen und Spin-off-Zahlungen.

have you noticed?
..and is there even an option to export Cash Operations in csv from XTB anymore?:smiley:

I wanted to try that new import and did not notice that it is for CSV. XTB does not have CSV export. So I will stick with my solution it seems :slight_smile:

I checked git and you have to save CSV from XLS first, then you can import it.

  1. Firstly, thank you for your work, hubga. I don’t want the rest of my comment to come across as coinceited or anything, so to make it clear - i’m very grateful for you putting in the time and effort to make this work for all of us!

  2. As a tip, would you perhaps consider updating your answer at the top to keep it actual? Since you’re updating it throughout (which is great), i think it would be great if future readers did not have to first go through discussions regarding export and transformation ways which are not possible anymore anyway.

  3. Most importantly - sadly, it still doesn’t work properly.
    a) firstly, even though the securities do get imported after manually switching the decimal dot for a comma, the resulting number of shares held is not correct. Unsurprisingly, then, the total market value is also wrong.

I noticed the same issue when i was trying to import a manually created CSV (without using your script) earlier, so it’s… strange.

b) secondly, and this is again an issue that also happens when using a CSV created without this script, is that an extra yellow-folder holding with the name of the portfolio is created, for some reason, with a non-zero value. I can find nothing about this on the forums either.

Unfortunately, users don’t have permission to edit old comments (at least not me). So I can’t change it.

As for your issue, I need more details

  • open .xlsx export from XTB, go to Cash operation page
    write here what you can see in “Amount” and “Comment” column (eg. -100,00 and OPEN BUY 10 @ 10.00). It looks like this in my case. You can change the values if you want to anonymize it

  • open .csv converted file, find the line with that trade. You should see the same values there. Something like this

    • “ID”;“Type”;“DateTime”;“Ticker symbol”;“Note”;“Value”;“Transaction Currency”;“Date”;“Time”;“Shares”;“Gross Amount”;“Currency Gross Amount”;“Cash Account”;“Securities Account”
      “123”;“Buy”;“01.01.2026 00:00:00”;“ABC. US”;“OPEN BUY 1 @ 10.00”;“100,00”;“USD”;“2026-01-01”;“00:00:00”;“10”;“10,00”;“USD”;“XTB USD”;“XTB USD”
  • when you import the csv into PP, it should look like this. Again, you should see same amount and quantity

    image

In which step you see wrong values?

I’ve just found that they changed format a little bit. Here is an update. It should fix the quantity issue.

XTB_convert_run.zip (2.5 KB)

Okay, this helps somewhat!

One needs to (presumably) only keep the Cash operations sheet in the excel, then run the .bat, then change the decimal comas to dots, then just drag the CSV file inth the PP, then change the delimitors to “;”, and then it can be uploaded.

I checked that the amount of shares now match! The tickers match also. However, two problems remain:

  1. the market values are still quite notably different for seemingly all the holdings. I’m uploading a file that has one random holding’s data in it, maybe you will uncover the issue?

Actually, I may have found it? An issue might stem from how the decimal separator is handled in Office. Because of this, some of the numbers get converted weird (like 3.VIII etc, and then making it a very high number when switching formats back). I haven’t found a way to prevent this from happening - be it by changing it ahead of running the .bat, or after, using excel’s “substitute” function"… For context, I’m using decimal coma on my PC.

Obviously, this might not be the issue at all - it’s just something i noticed.

send to PP.xlsx (9.5 kB)

  1. when inputting my whole portfolio, there’s still the holding with the symbol of an orange folder, which has some value that doesn’t match anything i have in my broker’s app (though this value did get lower notably while using your newest zip).

I haven’t found any issue. It works fine with your example.
The conversion script does not use Office. It uses some PowerShell library. No, you don’t need to remove the pages in excel. The script will find it automatically.

Can you convert your example and send the converted .csv? I will check if it is same on my computer.

The script parses note “OPEN BUY 4/4.0442 @ 74.190” into 4 (pieces) per 74.190 = 296,76.
When you look into csv, you can see “4”;“74,19” and “296,76”.
Now you just import the csv, choose comma “,” as decimal separator and then it must be imported correctly. When you check the import in PP transactions, what do you see there?

Note that you need XTB USD (or any currency) deposit and XTB USD security account in Portfolio Performance. You can’t mix currencies. Maybe that is the issue that names in PP don’t match with the import.

Edit the script and change variables in the beginning as you need. You can have just “USD” or “XTB USD 123456”
$IncludeXTBToDepositAccount = $true this is “XTB” prefix
$IncludeXTBToSecurityAccount = $true
$IncludeAccountNumberToDepositAccount = $true this is account number suffix - probably turn it off
$IncludeAccountNumberToSecurityAccount = $true

It should look like this when you open the CSV in PP (just in EUR, I think)

and like this in the second page

image

Hi, I just want to confirm, that your newest script still works great for me (I hve Windows with czech enviroment).

sorry for the slow replies, had a crazy week.

Just to rule out human error, i’ve tried to go through it again (same as last time), still the same issue.

Firstly, please note that i have everything set to EUR, since basically all of the holdings are in EUR also. (Yes, i’m aware this may impact the total market value of the whole portfolio - that’s fine, that’s not the issue).

I tried editing the script with the change you proposed; it did not help either. Result is attached below.

send to PP_out.csv (722 bajtů)

Note that the delimiter must be set to “;”, not “,” as you proposed, otherwise PP can’t read it.

Also, i have found that one must change the decimal “,” into “.” in the CSV export in the Shares, otherwise even though the first screen you posted is identical to mine, the second one will show “442” in the second screen you posted on the second row, and upon confirming, the portfolio will show 914 shares.

@Vlastimil_Mensik , thank you for your comment - so you’re confirming everything matches what you see in your XTB app exactly?

Could you perhaps give me the extremely specific steps you took to upload it into PP? I’m fully willing to admit all this is the fault of my limited intellect, if that’s the case.

Great. The output is correct - just the currency not.

You need to keep the original filename like EUR_12345_2026-01-01_2026-12-31.xlsx
The script needs it for the currency. It won’t work with “send to PP” filename. Maybe this is the last issue in the steps.

You set the settings like this
$IncludeXTBToDepositAccount = $true
$IncludeXTBToSecurityAccount = $true
$IncludeAccountNumberToDepositAccount = $false
$IncludeAccountNumberToSecurityAccount = $false

You created XTB EUR as deposit and security account.

Then you import it and it should look exactly like this. When you double click the grey “shares” text, you can change the decimal. Script uses “,” (comma) by default. I plan to make it as an option into the next update.

so it looks like this in the next step

image

I don’t know where PP got 914 shares. Then have a look into all transaction

thank you for your continued support.

did the changes you proposed; the double click must be done for all the values, not just the shares, though, so i think it’s still simpler to do it in excel at once. Good to know about, though.

Overall, the holdings load (again, with the mysterious orange folder with a small value…), and the share amount seems okay. The market value is still a little off (about 1.18% for the entire portfolio), but this seems to be an issue of PP, not of your script.

It appears the “Quote” is wrong, despite it coming from the correct exchange… the Quote value from PP is nowhere to be found - not on the exchange’s page, not in its charts, nowhere. Strange.

Either way, that’s a PP thing. Thank you for your help, i really appreciate it! At least i now have my portfolio in PP, even if its value is wrong.

Edit: found sort of a work-around, maybe it will help some when dealing with the fact the Quote is wrong in PP. It helped me to right-click on the holding, edit, historical quote, and select Yahoo finance (adjusted close). This brought it in line with what my stock exchange shows. Upon saving, you will have to go Online (at the top) → Update quotes.

This changes the quote and the historical ones. It’s still not the live quote (maybe it would be on other stock exchanges), but it comes from the current day, and the historical quotes are in line with the stock exchange (it’s the Close value) - so hey, at least we know what the data shows!

Why not import the XTB .xlsx file directly?

Thanks everyone for the scripts and the sample files in this thread, they helped a lot.

Since xStation 2.67, XTB only exports Excel (.xlsx), PDF and HTML, no CSV anymore. The XTB importer in Portfolio Performance reads CSV, so today you have to open the export in Excel, keep the “Cash Operations” sheet and save it as CSV first. That step is where many of the problems in this thread come from: separator, decimal comma, encoding, wrong sheet.

I don’t quite understand why the importer doesn’t read the .xlsx file directly. I looked at the file from this thread:

  • The “Cash Operations” sheet has exactly the same columns the CSV importer already expects.
  • Time and amount are stored as real numbers, not as text. Regional settings (date format, decimal comma, separator) would no longer matter.
  • An .xlsx file is a ZIP archive with XML inside. Java can read that without an additional library.

So a direct .xlsx importer looks like a fairly small step to me, and it would remove the manual conversion completely. Is there a reason not to do this, or would such a change be welcome?

Until then: improvements for the CSV import in PR #6394
XTB CSV: dividend tax and shares, translated messages by stoeggich · Pull Request #6394 · portfolio-performance/portfolio · GitHub (not merged yet):

  • Files saved by Excel with English regional settings (comma as separator) are accepted.
  • The withholding tax is booked as tax of the dividend.
  • The number of shares of a dividend is derived from the dividend per share.
  • Unsupported transaction types are shown in the import wizard instead of being dropped.
  • Malformed files are reported instead of aborting the import.
  • An empty XTB ID is no longer added to the note.

By the way, partial executions like “OPEN BUY 4/4.0442 @ 74.190” are imported correctly: the first number is the quantity of that row.

Sample files wanted
To build and test a direct .xlsx import, real exports would help a lot: the original .xlsx from XTB, not edited in Excel, with only the account number removed. Especially useful are files with dividends, withholding tax, sales, transfers between XTB accounts and purchases on the London Stock Exchange (several fees).

@Krevie Ok. I probably just don’t remember what I changed. But the setting remains saved, isn’t it? I don’t need to change anything. You set it once and then you just import.

Current stock price will never be exactly the same like XTB. It depends on provider. I use Yahoo Finance too. It is enough.

@hubga depends. Manual changes to the decimal separator is still necessary for all the columns where decimals appear, so if it’s not an insurmountable challenge, i think people with non-english excel settings would appreciate it. Perhaps through a small edit in the script, where the user would be able to change the separator, so the script remembers it for next time?

Here is the update. There is an option to change regional settings.

XTB_convert_run.zip (2.6 KB)