How to set up an IBKR Flex Query and Flex Web Service token
6 min read · Updated 8 September 2026
A Flex Query is Interactive Brokers' machine-readable statement. Once you have a Flex Web Service token and a Query ID, any tool you authorise can download your statement automatically instead of you exporting a file by hand every day. Here is the whole setup, in order, and the two settings that most often go wrong.
What Flex Web Service actually is
IBKR gives you two ways to get your data out. The first is a manual export: you run an Activity Statement in Client Portal and download a CSV. The second is Flex Web Service, where IBKR exposes your saved query over an API endpoint that is authenticated with a token. You create the query once, and anything holding the token and Query ID can fetch the current version of that statement on demand.
The practical difference is automation. A file export is a snapshot you have to repeat; a Flex Query is a standing definition that can be refreshed on a schedule. If you want a journal or analytics tool to stay current without you touching it, Flex Web Service is the mechanism that makes it possible.
Step 1 — Enable Flex Web Service and generate a token
- 1
Log in to IBKR Client Portal
Use your normal Interactive Brokers credentials at the Client Portal web interface.
- 2
Go to Performance & Reports → Flex Queries
This is the same area where saved report templates live. If you have never used Flex before, the list will be empty.
- 3
Open Flex Web Service Configuration
Enable the service, then generate a Token. Copy it somewhere safe — IBKR shows it to you at creation time, and tokens expire, so you will need to regenerate it periodically.
Step 2 — Create an Activity Flex Query
The Activity Flex Query is the one that carries your history: trades, positions, and realised and unrealised P&L. Create it as a new query template with these settings.
- 1
Set the Delivery Format to XML
Flex Web Service delivers XML. A query saved with a different delivery format will not be retrievable over the API.
- 2
Set the Period to "Last 30 Calendar Days"
This is the single most important setting, and the one most people get wrong. See the section below on why fixed periods lose trades.
- 3
Include the required report sections
Account Info, Net Asset Value, Change in NAV, Open Positions, Trades, P/L Summary, and Cash Transactions. Omit any of these and parts of your analytics will be blank or wrong.
- 4
Save and copy the Query ID
IBKR assigns each saved query a numeric ID. That ID plus your token is everything a tool needs to fetch the report.
Why "Last Business Week" quietly loses trades
IBKR offers several fixed period options, and the tempting ones are traps. "Last Business Week" means the previous completed week — so on a Wednesday, everything you traded on Monday, Tuesday, and Wednesday falls outside the window. If a tool syncs only that query, those trades never arrive, and the gap is silent: the report is valid, it simply does not contain them.
"Last 30 Calendar Days" is a rolling window, so the current week is always inside it. It also gives a comfortable overlap between syncs, which matters because a well-built importer deduplicates: re-fetching a trade you already have should be a no-op, not a double count.
- Last 30 Calendar Days — recommended. Rolling window, always includes the current week.
- Last Business Week — avoid. Excludes the week in progress.
- Month to Date / Year to Date — usable, but the window shrinks to almost nothing on the first of the period.
What the Activity query will not give you
An Activity Flex Query only covers up to the previous business day. IBKR finalises a trading day's activity after the close, so today's fills are not in the activity statement yet, no matter how often you refresh it. This is expected behaviour, not a broken sync.
If you want the trades you placed this morning to appear, you need a second query — a Trade Confirmation Flex Query, which reports fills as they execute. Setting up both is the configuration that gives you a complete picture.
Connecting the query to PaprBoard
In PaprBoard, open Upload Data and choose the Flex Web Query tab. Paste your Token and Activity Query ID, and optionally a Trade Confirmation Query ID. From then on PaprBoard fetches new statements in the background, merges them into your existing history, and discards duplicates automatically.
PaprBoard also checks the period your query uses and warns you if it is a fixed window that could exclude recent trades — so the mistake described above gets caught rather than silently costing you data.
Related guides
How to get today's IBKR trades in realtime with a Trade Confirmation query
Why today's fills are missing from your IBKR activity statement, and how a second Trade Confirmation Flex Query imports them in realtime without double-counting.
How to export an IBKR Activity Statement as CSV
How to run and download an Activity Statement from the IBKR Client Portal in CSV format, which report sections to include, and what each section is used for.