Get flex reports
Portfelj works by processing your brokerage account activity, also known as flex reports, created using Flex Query. Let's begin by setting one up.
Create flex query
Login to Interactive Brokers portal and follow instructions below to create a Flex Query.
- Go to Performance & Reports -> Flex Queries

- Click "+" next to Activity Flex Query to add new

- Type in the Query Name, can be anything
- Click on Account Information under the Sections menu. Select IB Entity and Account ID, then click Save at the bottom.

- Click on Trades under the Sections menu. Select Executions in Closed Lots under Options. Click on Select all to select all rows.

- Click on Corporate Actions under the Sections menu. Click on Select all to select all rows.

- Click on Cash Transactions under the Sections menu. Select Dividends, Payment in Lieu of Dividends, Withholding Tax, Broker Fees in Broker Interest Received under Options

- Click on Financial Instrument Information under the Sections menu. Click on Select all to select all rows.

- Click on Transfers under the Sections menu. Select Transfer under Options. Click on Select all to select all rows.

- Leave everything else unchanged, including date settings, which will be set later when running the flex query.
- Click Continue at the bottom of the page, then Create, then Ok once again before returning back to Flex Queries.

- Your newly created flex query can be found under Activity Flex Query in the Performance & Reports -> Flex Queries.
Export flex report
Assuming you're in the Performance & Reports -> Flex Queries section of IB portal, follow the next steps to export reports:
- Click the arrow next to your flex report.
- Change the Period to Custom Date Range.
- In the appeared From Date and To Date, select the first and the last day of the year for which you're generating the report.
- Hit Run to get the report.
Repeat the steps above for each trade year.
Download flex reports from Interactive Brokers
Instead of exporting reports by hand, Portfelj can download them directly from Interactive Brokers using the Flex Web Service. You need the flex query created above and a Flex Web Service token.
Configure Flex Web Service token
- In the Interactive Brokers portal, go to Performance & Reports -> Flex Queries.
- Find the Flex Web Service Configuration section and click the gear icon next to it.
- Turn on Flex Web Service Status.
- Click Generate New Token. Choose the longest available expiration, so you don't have to renew it often. Leave IP Address Restriction empty, unless your internet connection has a fixed IP address.
- Click Save and copy the Current Token.
- Back in Flex Queries, click the info icon next to the flex query you created above and copy its Query ID.
WARNING
The flex query must include all accounts that were active in the years you want to download. Interactive Brokers assigns new account IDs when accounts move between IB entities, so a query that only includes your current account can't provide reports for earlier years. In that case the download fails with No statement available.
WARNING
Treat the token like a password: anyone who has it, together with the query ID, can download your activity reports. Portfelj stores both in the system keychain.
WARNING
Flex Web Service tokens expire at most one year after they are generated. Currently they have to be renewed manually: generate a new token in Flex Web Service Configuration and save it in Portfelj again.
Download with the CLI
- Save the token and the query ID:sh
portfelj flex web-service set-token <TOKEN> portfelj flex web-service set-query-id <QUERY_ID> - Download the report for a given year, for example:sh
portfelj flex web-service download 2026
Run the command from your workspace directory (e.g. ibkr); the report is saved to its flex subfolder.
Downloading the current year saves a year-to-date report with the .incomplete.xml extension; once the full year report is downloaded, the year-to-date report is moved to the trash. Only the past 5 years can be downloaded.
TIP
If you have multiple accounts, you should be able to select all of them and export combined reports. The corresponding menu is available next to the Flex Queries heading on Performance & Reports -> Flex Queries page.
WARNING
Slovenian account holders have been transferred between different branches of Interactive Brokers over the years and received new account ID each time. Therefore it's important to export trade data for each account active in the selected year.
TIP
Some trade data can be backdated in the current year's report. Along with full year reports, make sure to generate a year-to-date report to ensure the correct calculations.
For example, if you look to generate a full year report for 2024, make sure to generate the year to date report for 2025 too. You can replace the incomplete 2025 report with the full year report in the following year.
WARNING
It's recommended to keep backups of reports since Interactive Brokers only provide reports for the past 5 years. Also so that you don't have to generate them each time.