Get started

Introduction

Broker integrations

Interactive Brokers

Interactive Brokers integration

Connect your IBKR account to Stonksfolio using Flex Queries

Overview

Interactive Brokers exposes account activity through Flex Queries - a read-only export mechanism that's the standard way third-party applications can read IBKR data.

Once set up, Stonksfolio periodically invokes the Flex Query to import your trades (and optionally dividends).

Read-only access

Flex Queries are pull-only and cannot place trades or modify your IBKR account. Revoke at any time from Client Portal.

Step 1 - Create 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 on 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 on 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. Navigate 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 - Configure the integration in 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 make sure things are wired up properly.
    If the test fails

    Make sure you entered the correct Query ID and Token and try again. IBKR will also sometimes take up to 30m to actually register the created token and activate it.

  6. Finally, if the test is successful, click on Save to save the settings.

How the sync works

Once the Flex Query is set up, Stonksfolio will periodically use it to check your IBKR account for any new transactions and they will automatically be added to your portfolio.

When new transactions are imported, you'll be notified once you open the portfolio page:

Clicking the Review button will show a detailed list with 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.
  • Imports are idempotent - transactions are never imported more than once. But if you already added the transactions manually, the importer might add duplicates. After the first import, double-check the Transactions tab and delete any duplicates.
  • If the credentials stop working (either because you deleted the Flex Query in IBKR Client Portal or the token has expired), Stonksfolio will stop the automatic sync. Once the credentials have been fixed, the sync will resume.

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 — it can only fetch reports. There is no path to placing orders, transferring funds, or modifying your account. Revoke the token any time from 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 same SHA1 deduplication runs on both API sync and manual CSV imports. You can mix and match safely.
Can I auto-sync multiple IBKR portfolios?
Yes. Create a separate Flex Query per portfolio in Client Portal and connect each independently. 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).