equitiesday-tradingintermediate

Set up the Flex query once, then stop thinking about it

An IBKR Flex query is a saved report you build once in Client Portal. A journal fetches it with a token and a query ID. The setup takes a few minutes. The trouble starts later, when the token lapses or a field is missing and trades stop arriving without a word.

What is an IBKR Flex query, and why does a journal need one?

An IBKR Flex query is a custom report of your account activity that IBKR builds on request. A journal requests it over the Flex Web Service with a long token and a short query ID.

IBKR doesn't offer a login-style connect button for retail journals. The Flex Web Service is the official route, and it works well once it's configured right.

The catch is that it fails in quiet ways. An expired token, a missing section or a short date window won't show an error on your screen. Your journal just stops getting new fills. Weeks later the stats look fine and they're built on half your trades. Each of those failure points has a simple fix, and they're all in the setup below.

Which sections and fields should the Flex query include?

Build an Activity Flex Query with two sections switched on: Trades and Cash Transactions. Set the output format to XML.

In the Trades section, pick the execution level of detail. Leave out orders and closed lots. Those repeat the same fills in another shape, and a journal can end up counting a trade twice.

For the fields, the easy path is to tick select all. A missing required field is the most common reason a Flex pull fails. If you prefer a lean report, keep at least symbol, buy or sell, quantity, trade price, proceeds and trade date. Add commission, taxes and asset category so fees land in your P&L.

Cash Transactions carries your deposits. A journal uses them to separate money you added from money you made. Leave the account ID in the report too, so the import knows which account it's reading.

How to set up the Flex query and token, step by step

Do this in IBKR Client Portal, under the Performance and Reports menu. It takes about as long as making coffee. Then paste two values into your journal and you're done.

  • Open Flex Queries and create a new Activity Flex Query.
  • Give it a name you'll recognise later.
  • Switch on the Trades section at execution level.
  • Tick select all in the Trades field list.
  • Switch on the Cash Transactions section.
  • Set the format to XML.
  • Set the period to the last 365 calendar days.
  • Save, then copy the query ID number.
  • Open Flex Web Service Configuration and enable the service.
  • Generate a token set to expire after one year.
  • Leave the IP address field blank.
  • Paste the token and query ID into your journal and sync once.

Token expiry: the six-hour default that breaks syncs

When you generate a Flex token, IBKR defaults its lifetime to six hours. Leave that default and your first sync works. The next morning nothing comes through.

Pick the longest option, one year, from the expiry list. Then put a reminder in your own calendar a week before that date.

Two more traps. Generating a new token cancels the old one at once, so paste the new token into your journal straight away. And the IP address field should stay empty. A journal calls IBKR from its own servers, so locking the token to your home address blocks every sync.

If a sync suddenly fails with an authentication message, an expired or replaced token is the first thing to check.

Date-range limits and what they mean for your history

A single Flex request can cover at most 365 days. Choose the last 365 calendar days as the period and each sync returns a rolling year of trades.

That window is all a Flex pull can see. A journal reading the report can't reach trades from before it on its own. If you connect today, your first sync shows the past year. A narrower period, like month to date, shows only that month.

Sometimes IBKR replies that the statement is still being generated. That reply is temporary. Wait a few minutes and sync again rather than rebuilding the query.

If a failed sync names a field or a section, go back to the query and tick it. IBKR's own wording usually tells you exactly what's missing.

When to use the Activity statement CSV instead

If you can't get Flex working, the Activity statement CSV is the fallback. In Client Portal, open Reports, then Activity. Pick a date range, run it, and download it as CSV.

That file has several sections stacked in one sheet. A journal reads the Trades section for fills, Cash Transactions for deposits and Account Information for the account number.

Know the trade-offs. A CSV is a snapshot, so new trades only appear when you export and upload again. In TraderLog the CSV route reads price, quantity, proceeds and date. The Flex route also carries commissions and taxes, so it gives the truer P&L.

Use the CSV to get started tonight. Then set up Flex when you have ten quiet minutes, so the import runs by itself.

Frequently asked questions

It's a saved, custom report of your IBKR account activity. A journal fetches it over the Flex Web Service with a token and a query ID.

It most likely expired, since the default lifetime is six hours, or a newer token replaced it. Generate one set to one year and paste it into your journal.

Yes. Export the Activity statement as a CSV from Client Portal and upload it. It won't update by itself, so you'll need to repeat the export for new trades.

Connect IBKR to TraderLog in minutes

Paste your Flex token and query ID and TraderLog imports your IBKR trades automatically, with CSV import as a backup. Every trading day lands on a calendar with its P&L. The stats page shows your win rate, expectancy and max drawdown. Try it free on the Hobby plan, no card needed.

Every trading morning at 8:40 ET our model draws the SPY, QQQ and IWM zones it expects to matter, on a TradingView chart, before the open. Where price reaches one, it has turned 74 percent of the time. Free, no account. See today's map