FillScope

IBKR guide

How to set up an IBKR Flex Query (token, query ID, trade fields)

A Flex Query is a reusable report you define in IBKR Client Portal. With the Flex Web Service, you give any tool, FillScope included, a token and a query ID, and it pulls the report automatically. Setup takes about 10 minutes.

Before you start

Step 1 - Open Flex Queries

  1. Sign in to Client Portal.
  2. Open Performance & Reports in the top menu, then Flex Queries. In the older layout, the path is Reports, then Flex Queries.
  3. Find the two blocks: Activity Flex Query and Trade Confirmation Flex Query. Use Activity for a journal.
  4. Click the + next to Activity Flex Query to create a new query.

Step 2 - Name the query and pick sections

  1. Enter a Query Name, for example fillscope-journal.
  2. Open the Trades section. This section is required.
  3. Under Options, select Executions. Do not select Orders or Closed Lots. Each execution arrives with its own tradeID. FillScope merges partial fills of the same order into one trade for you.
  4. Tick the fields below, or use Select All.

Trades fields (minimum)

Open Positions section (optional)

Add this section if you want an open positions tab. Select these fields:

Add no other sections. A wider report is larger and shares more data than the journal needs. Keep the scope as narrow as possible.

Step 3 - Set the delivery configuration

  1. Set Format to XML. FillScope reads XML, not CSV.
  2. Set Period to Last 365 Calendar Days for the first import. This is the widest range. Later, Last 30 Calendar Days is enough. FillScope deduplicates by tradeID, so overlapping periods do not create copies.
  3. Keep the defaults: date format yyyyMMdd, time format HHmmss, date/time separator ; (semicolon). The format dd/MM/yyyy is also accepted.
  4. Set Include Canceled Trades, Include Currency Rates, Include Audit Trail Fields, Display Account Alias and Breakout by Day to No.
  5. Click Save. The numeric Query ID now shows next to the query in the list. Write it down.

Step 4 - Create the Flex Web Service token

  1. On the same Flex Queries page, open Flex Web Service Configuration (gear icon or Configure).
  2. Set Status to Enabled.
  3. Generate a token. Expiry ranges from 6 hours to 1 year. Choose 1 year for a journal. When it expires, renew it in the same place.
  4. IP restriction is optional. FillScope does not use a fixed server IP, so leave it empty, or ask us first.
  5. Copy the token right away. IBKR shows it once.

The token works like a password. Do not share it or post a screenshot of it.

Step 5 - Test the query yourself

Check the setup without any third-party tool. Open these two URLs in a browser. Replace the placeholders first.

https://ndcdyn.interactivebrokers.com/AccountManagement/FlexWebService/SendRequest?t=TOKEN&q=QUERY_ID&v=3
https://gdcdyn.interactivebrokers.com/AccountManagement/FlexWebService/GetStatement?t=TOKEN&q=REFERENCE_CODE&v=3
  1. Open the first URL with your token and Query ID. A good reply contains <Status>Success</Status> and a <ReferenceCode>.
  2. Paste that reference code into the second URL as REFERENCE_CODE. The reply is your XML report.
  3. If a reply contains <ErrorCode> and <ErrorMessage>, check the table below.

Step 6 - Connect to FillScope

  1. Open Settings, then IBKR connection.
  2. Paste the Flex token and the Query ID.
  3. Click Save, then Refresh.
  4. Wait 1 to 3 minutes. The first import time depends on report size.

Read how FillScope uses the report and how the token is stored.

Start free with FillScope

Common errors

Typical messages include the ones below. Exact wording can differ.

MessageCauseFix
Statement generation in progress. Please try again shortly.IBKR has not finished building the report. This is common in the morning.Wait a few minutes and request again. FillScope retries automatically, up to 8 times at 5-minute intervals.
Token has expired / Invalid tokenThe token passed its expiry date, or it was pasted incorrectly.Generate a new token in Flex Web Service Configuration and paste it again.
Invalid query ID / Query is not an Activity Flex QueryYou used a Trade Confirmation query, or the ID is wrong.Copy the Query ID of your Activity Flex Query from the list.
Flex Web Service is not enabledThe service status is Disabled.Set Status to Enabled in Flex Web Service Configuration.
Report loads but contains no tradesThe period does not cover your trades, or Trades is set to Orders or Closed Lots.Select Executions in the Trades section and widen the period.
Dates are emptyThe date format is not yyyyMMdd (for example MM/dd/yyyy).Set the date format to yyyyMMdd and save.

FAQ

Is a Flex Query the same as the IBKR API or TWS?

No. A Flex Query is a report service. IBKR builds a statement from your account data and you download it as XML. It is not a live execution stream like TWS or IB Gateway, so data arrives after IBKR generates the report.

Does the Flex Web Service work with paper trading accounts?

Often not. Paper accounts may not expose the Flex Web Service. Use your live login to create the query and token.

How often can I pull a Flex report?

IBKR applies rate limits. A few requests per minute are enough for testing. Do not poll in a tight loop. FillScope schedules its own refreshes so you do not need to.

Can one token serve several queries?

Yes. The token belongs to your account. The query ID belongs to one report. Keep one token and create a separate query for each report you need.

Is sharing a Flex token safe?

Treat it like a password. Use the narrowest report, set an expiry and add an IP restriction if the tool has a fixed address. To revoke access, generate a new token, which invalidates the old one.

Why is the Flex period limited to 365 days?

The Activity Flex Query period has an upper limit of 365 days. For older history, run several queries with consecutive custom date ranges.

Ready to import?

You have a token and a Query ID. Connect them and review your trades.

Start free with FillScope