Interactive Brokers integration
Connect your IBKR account to Stonksfolio using Flex QueriesOverview
Interactive Brokers shares account activity through Flex Queries, a read-only export that other apps use to read IBKR data.
Once it's set up, Stonksfolio runs your Flex Query regularly to import your trades, and your dividends if you include them.
Flex Queries only read data. They can't place trades or change your IBKR account, and you can revoke access at any time in Client Portal.
Step 1: Create a Flex Query
- Log in to the Interactive Brokers Client Portal and navigate to Performance & Reports → Flex Queries.
- Click the + button next to Activity Flex Query to create a new query.
- Enter a name for your query, e.g. Stonksfolio Sync.
-
Click the Trades section, select Execution, and choose these fields:
Symbol ISIN Trade ID Trade Date Buy/Sell Quantity TradePrice IB Commission Currency
-
optional Syncing dividends: click the Cash Transactions section. Mark the Dividends and
Withholding Tax options and then select the following fields:
Symbol ISIN Date/Time Amount Type Transaction ID Currency
- Click on Save and scroll down to the Delivery Configuration section.
-
Set Period to Last 365 Calendar Days and Format to CSV.
- Click on Continue. Review the query and click on Create to save it.
- Go back to Performance & Reports → Flex Queries. Find your new query and click on the icon. Copy the Query ID.
Step 2: Generate a Flex Web Service token
- In IBKR Client Portal, go to Performance & Reports → Flex Queries.
- Locate the Flex Web Service Configuration section and click on the icon ("Configure").
- Check the Flex Web Service Status checkbox and click Save.
- Copy the Current Token.
Step 3: Connect your Stonksfolio portfolio
-
Open your portfolio in Stonksfolio and click the (Settings) icon.
- Select Interactive Brokers from the list of available brokers.
- Enter the Query ID from Step 1 in the Flex Query ID field.
- Enter the Token from Step 2 into the Flex Web Service Token field.
-
Click on Test Connection to check that everything works.
If the test failsCheck the Query ID and Token and try again. IBKR can take up to 30 minutes to activate a new token.
- If the test succeeds, click Save to save the settings.
How the sync works
Stonksfolio uses the Flex Query to check your IBKR account for new transactions regularly and adds them to your portfolio.
When new transactions arrive, the portfolio page tells you the next time you open it:
Important details
- IBKR's Activity statement refreshes once a day at market close. New trades typically appear in Stonksfolio the next business day.
- The sync never imports the same transaction twice. Transactions you added by hand aren't recognised, though, so check the Transactions tab after the first import and delete any duplicates.
- If the credentials stop working, because you deleted the Flex Query in Client Portal or the token expired, Stonksfolio pauses the sync. It resumes once you fix them.
FAQ
How long until a new trade shows up in Stonksfolio?
Can Stonksfolio trade or move money on my behalf?
What happens when the token expires?
auth failed error and a banner appears on the portfolio. Generate a new token in Performance & Reports → Flex Queries, paste it into Stonksfolio, and save. Auto-sync resumes from the next run.