Set up an IBKR Flex Query for automatic trade imports
A Flex Query is a saved, read-only report in Interactive Brokers. With a Flex Web Service token, an app can download it on a schedule, so your trades update without manual CSV exports.
Updated October 7, 2026
What you will end up with: a Query ID (a number) and a Flex Web Service token (a long code). Together they let an app download that one report. They cannot place trades, move money or log in to your account.
Step by step
- Open the Flex Queries page. In Client Portal click Performance & Reports → Flex Queries (or Menu → Reporting → Flex Queries). If you manage several accounts, select the one to report on.
- Create an Activity Flex Query. Click the + next to Activity Flex Query and give it a name such as “IBKR Analyzer”.
- Select the Trades section. Click Trades; a pop-up lists its options and fields. Choose Executions, select all fields and click Save. Leave unrelated sections unselected; a smaller report is faster and shares less.
SectionTradesOptionExecutionsFieldsAll
- Set the Delivery Configuration. Format XML, one account. Any Period works, such as Last 30 Calendar Days; an app that syncs requests the exact dates it needs.
FormatXMLAccountsOne
- Set the General Configuration if these options are shown: date format
yyyyMMdd, a semicolon (;) between date and time, and a New York timezone so trade dates line up with US market days. Then click Continue and Create.Date formatyyyyMMddDate/time separator; - Note the Query ID. The saved query appears in the Activity Flex Query list with its numeric ID.
- Turn on Flex Web Service and generate a token. Open Flex Queries → Flex Web Service Configuration, tick Flex Web Service Status and Save. In Should Expire After, choose the longest period: the default is only 6 hours, after which automatic imports stop. Leave Valid For IP Address blank unless you restrict it to the app’s server address, then click Generate New Token. Generating another token later invalidates the previous one.
StatusActiveShould Expire AfterLongest available
- Paste both values into the app. In IBKR Analyzer, open IBKR sync, paste the token and Query ID, and connect. The first sync imports up to a year of available history in batches, newest first.
IBKR’s own instructions: Create an Activity Flex Query and Configure Flex Web Service.
Is a Flex token safe to share with an app?
A Flex token can only download the reports you configured. It cannot trade, transfer funds or read your password. Good practice still applies:
- Only select the sections the app needs (Trades).
- Store the token like a password; apps should keep it encrypted. IBKR Analyzer stores it encrypted and never asks for your IBKR password.
- Revoke or regenerate it in Client Portal whenever you stop using an app.
Troubleshooting
“Use an Activity Flex Query instead of a legacy query”
The Query ID belongs to an older query type. Create a new Activity Flex Query and use its ID.
The report has no trades
Check that the Trades section is selected with Executions, and that the account traded in the requested dates. Weekends and holidays legitimately have no executions.
The token stopped working
Tokens expire, after 6 hours by default. Generate a new one with a longer Should Expire After period in Flex Web Service Configuration and update it in the app; your imported history stays.
Numbers are in my base currency instead of the trade currency
Use the default trade-currency report rather than one converted to your base currency, so each currency’s P/L can be checked against IBKR.