MindTrajour Logo
Guides

How to set up an IBKR Flex Query for your trading journal

An Activity Flex Query lets MindTrajour fetch your Interactive Brokers trades without exporting a file each time. You create the query once in Client Portal, copy its Query ID and a Flex Web Service token, and paste both into MindTrajour. After that, Sync now pulls the statement and shows a preview, and nothing is saved until you confirm it.

Create the query and connect it

  1. Open Flex Queries in Client Portal

    Log in to IBKR Client Portal and go to Performance & Reports → Flex Queries. The same works for brokers on the IB platform, such as CapTrader, LYNX, Estably or WH-SelfInvest.

  2. Create an Activity Flex Query

    Click the + next to Activity Flex Query and give the query a name you will recognise, for example MindTrajour.

  3. Add the Trades section

    Under Sections, click Trades. In the dialog, set Options to Execution, click Select All for the fields and save.

  4. Set the period

    Under Delivery Configuration, set Period to Last 365 Calendar Days. Leave the rest as it is: format XML, date format yyyyMMdd, time format HHmmss.

  5. Create the query and copy the Query ID

    Click Continue, check the summary and click Create. Back in the list, click the ⓘ next to the new query and copy its Query ID.

  6. Turn on the Flex Web Service

    On the same page, click the gear next to Flex Web Service Configuration, enable Flex Web Service Status, copy the Current Token and save.

  7. Connect in MindTrajour

    Select the trading account the trades belong to, open All Trades → Auto-sync (FlexQuery), paste the Flex token and the Query ID and click Connect.

  8. Sync now

    Click Sync now. MindTrajour requests the statement from IB and rebuilds your trades from the fills. Large statements can take a few minutes to prepare.

  9. Review the preview and import

    Check the rebuilt trades and their detected strategies, tick the ones you want and import them. Nothing is written to your journal before this step.

Why Execution and all fields

MindTrajour rebuilds trades from individual fills. It reads the trade rows of the statement and keeps only those at the Execution level of detail, one row per fill. In the Trades section of the query, the Options setting decides that level. A query set to a summary level has nothing for the importer to rebuild.

Select All matters because several fields feed the rebuild:

  • Side, quantity and price give each fill its signed premium.
  • The multiplier field gives mini and index options with a non-standard multiplier the right premium.
  • The commission becomes the order fee of the trade, always as a positive amount, whichever sign IB uses.
  • Order ids and execution times group the legs of one combo order into one trade.
  • The from and to dates of the statement show up in the preview as the period it covers.

The 365-day window and older history

Last 365 Calendar Days is a rolling window counted back from each sync, and it already applies on the day you connect. A sync can’t reach further back than that. If your history is longer, import a multi-year Activity Statement as a CSV once, under All Trades → Import from broker, and use FlexQuery for the updates after that. The preview shows the coverage dates IB reported and warns when a closing fill suggests that its opening lies outside the window.

Activity data is end-of-day. A fill from today lands in the IB statement overnight, so it shows up on tomorrow’s sync. Syncing is for catching up on your history, not for watching positions during the session.

Syncing again is safe

Statements overlap from one sync to the next, and that is expected. Before you see the preview, every sync is compared with what is already in your journal:

  • Trades you already imported are unchecked and listed under Previously added, so they don’t arrive twice.
  • A trade you imported while it was open and that has since been closed at IB is offered as an update that adds the real exit to the existing trade.
  • Rows you never want in your journal can be set to Ignore. They stay unchecked on every later sync of that trading account.
  • Nothing is saved until you confirm the preview.

Each FlexQuery connection belongs to the trading account that is selected when you connect. With several IB accounts, select each trading account in turn and connect its own Query ID and token.

What happens with your token

The token is kept on the server in a table the browser can’t read, and it is never sent back to the browser. After you save it, the connection only shows its last four characters. MindTrajour talks to the Flex Web Service in two steps, first requesting the statement and then fetching it, keeps to the IB limit of about one request per second, and retries the temporary errors IB documents, such as a statement that is still being generated.

When the sync fails

If IB rejects a request, the sync tells you what went wrong and what to do next. The usual causes:

  • The token has expired. Create a new one under the gear next to Flex Web Service Configuration and paste it into the connection settings.
  • IB doesn’t accept the token: it is wrong, was replaced by a newer one, or the Flex Web Service is switched off. Make sure the service is enabled and copy the current token.
  • The token only works from certain IP addresses. Remove the IP restriction from the token in Client Portal, then try again.
  • IB doesn’t recognise the Query ID. Copy it again from the ⓘ next to your query; if the query was deleted, create it again.
  • IB is still generating the statement or received too many requests. Wait a few minutes and try again.

Example

Worked example: four fills become one iron condor

A hypothetical opening order on the placeholder underlying XYZ: an iron condor with two contracts per leg, sent as one combo order. The statement holds four Execution rows. MindTrajour groups them by order id, signs each fill and adds them up.

Hypothetical numbers, not a recommendation.

The four Execution rows, multiplier 100
Sell 95 put × 2 at 1.20+$240.00
Buy 90 put × 2 at 0.50-$100.00
Sell 110 call × 2 at 1.10+$220.00
Buy 115 call × 2 at 0.40-$80.00
The rebuilt trade in the preview
Legs4
Contracts2
Entry premium, the sum of the four fills+$280.00
Entry order fee, the sum of the four commissions$5.20

See it in the app

Interactive Brokers syncFlexQuery connected with a token and Query ID, a sync, the review of the rebuilt trades and the import, plus a CSV import that asks for the openings a file is missing. Demo account, example data.

Keep every roll, fill and fee in one journal

Log your options trades by hand or sync them from Interactive Brokers, and read gross and net P&L for every position.

Start your journal