Interactive Brokers integration

Connect your IBKR account to Stonksfolio using Flex Queries

Overview

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.

Read-only access

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

  1. Log in to the Interactive Brokers Client Portal and navigate to Performance & Reports → Flex Queries.
  2. Click the + button next to Activity Flex Query to create a new query.
  3. Enter a name for your query, e.g. Stonksfolio Sync.
  4. Click the Trades section, select Execution, and choose these fields:
    Symbol ISIN Trade ID Trade Date Buy/Sell Quantity TradePrice IB Commission Currency
  5. 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
  6. Click on Save and scroll down to the Delivery Configuration section.
  7. Set Period to Last 365 Calendar Days and Format to CSV.
  8. Click on Continue. Review the query and click on Create to save it.
  9. 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

  1. In IBKR Client Portal, go to Performance & Reports → Flex Queries.
  2. Locate the Flex Web Service Configuration section and click on the icon ("Configure").
  3. Check the Flex Web Service Status checkbox and click Save.
  4. Copy the Current Token.

Step 3: Connect your Stonksfolio portfolio

  1. Open your portfolio in Stonksfolio and click the (Settings) icon.
  2. Select Interactive Brokers from the list of available brokers.
  3. Enter the Query ID from Step 1 in the Flex Query ID field.
  4. Enter the Token from Step 2 into the Flex Web Service Token field.
  5. Click on Test Connection to check that everything works.
    If the test fails

    Check the Query ID and Token and try again. IBKR can take up to 30 minutes to activate a new token.

  6. 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:

Click Review to see the imported transactions:

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?
Usually the next business day. Interactive Brokers' Activity statements refresh once daily at market close, so a trade you fill on Monday lands in Stonksfolio on Tuesday morning.
Can Stonksfolio trade or move money on my behalf?
No. The Flex Web Service is read-only and can only fetch reports, so it can't place orders, move money or change your account. You can revoke the token at any time in Client Portal.
What happens when the token expires?
Syncs start failing with an 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.
If I also import CSVs manually, will I get duplicates?
No. The automatic sync and manual CSV imports recognise trades the same way, so you can use both.
Can I auto-sync multiple IBKR portfolios?
Yes. Create a Flex Query for each portfolio in Client Portal and connect each one separately. The optional currency filter lets you split a multi-currency IBKR account across separate Stonksfolio portfolios.
How do I turn it off?
Clear the token field on the portfolio edit page and save. Auto-sync stops immediately. To revoke from the IBKR side, generate a new token in Client Portal (the old one becomes invalid).

More about Interactive Brokers