How to set up IBKR Flex Web Service to auto-sync your portfolio
The IBKR Flex Web Service is the official way to pull your Interactive Brokers data into third-party apps. It is more reliable than screen scraping and does not require you to hand over your login credentials to anyone. Once it is set up, your positions sync automatically.
This guide walks you through the setup from scratch.
What the Flex Web Service includes
A Flex Query is a snapshot of your IBKR account data at the time you request it. Depending on how you configure it, a query can include:
- Open positions (the holdings you care most about)
- Account information (cash balances, net asset value)
- Trade history (useful for performance calculations)
- Corporate actions (dividends, splits)
For syncing a portfolio tracker like DeskFi, the two essential sections are Open Positions and Account Info.
Step 1: Generate a Flex Web Service Token
1. Log in to IBKR Client Portal (not Trader Workstation).
2. Go to Settings, then Account Settings.
3. Scroll down to find Flex Web Service and click the toggle to enable it.
4. A token will be generated. Copy it somewhere safe. You will need it later.
This token authenticates requests from external apps to your account. Treat it like a password.
Step 2: Create a Flex Query
1. Still in Client Portal, go to Reports, then Flex Queries.
2. Click Create to start a new query.
3. Give it a name, something like "DeskFi Sync".
4. Under Sections, add Open Positions and Account Info.
5. For Open Positions, make sure to include: Symbol, Description, Position, Market Value, Average Cost, Unrealized PnL, Asset Class, Currency.
6. Set the format to XML.
7. Save the query. IBKR will assign it a Query ID. Copy that too.
Step 3: Connect to DeskFi
1. In DeskFi, go to Settings, then Brokers.
2. Select Interactive Brokers and click Connect.
3. Paste your Flex Token and your Query ID.
4. Click Sync. DeskFi will run the query and pull your positions.
The first sync usually takes 10 to 30 seconds. After that, you can refresh on demand or set a schedule.
Troubleshooting common issues
"Query not found" error. Make sure you copied the Query ID and not the query name. The ID is a numeric string in your Flex Queries list.
Empty results. Check that you added the correct sections (Open Positions, Account Info) when building the query. A query with no sections returns nothing.
Authentication error. Your Flex Token may have been regenerated. Go back to IBKR Client Portal and check whether a new token was issued, then update it in DeskFi.
Stale data. IBKR's Flex data refreshes once per day, overnight. If you synced earlier today and the data looks old, that is expected. Real-time position updates are available through Trader Workstation, not the Flex Web Service.
What you get once it is connected
Once synced, DeskFi shows your IBKR positions alongside your other accounts (if you have them), calculates your overall allocation by sector and region, and lets you ask the AI questions about your holdings. It is considerably more useful than trying to make sense of the Trader Workstation portfolio view.
Ready to connect your IBKR account?
Ready to take control of your portfolio?
Connect your Trading 212 account and get AI-powered insights in minutes.
Create your free accountDeskFi is not authorised or regulated by the Financial Conduct Authority. All content is AI-generated for informational and educational purposes only and does not constitute financial advice or a personal recommendation. Capital at risk. The value of investments can go down as well as up. See our Risk Disclosure and Terms for details.