---
title: "Import an Interactive Brokers Flex Query"
description: "Which Flex Query sections Stonqs reads from Interactive Brokers, which three kinds of row it skips on purpose, and how to import the XML file."
url: "https://stonqs.app/guides/import-interactive-brokers-flex-query/"
lang: "en"
updated: "2026-10-25"
---

Getting your data in · Guide 4 of 10

# Import an Interactive Brokers Flex Query

[By Vladimir Varvorkin](https://stonqs.app/about/) Updated October 12, 2026 5 min read

Define a Flex Query with Trades, Cash Transactions and Corporate Actions, turn currency rates on, and download it as XML. Stonqs recognises the file, asks only which account it belongs to, and previews everything before writing. Options, futures, corporate actions and cancelled trades are not imported; the last step counts them.

## On this page

1. [Before you start](https://stonqs.app/guides/import-interactive-brokers-flex-query/#before-you-start)
2. [Define the query in the web office](https://stonqs.app/guides/import-interactive-brokers-flex-query/#define-the-query-in-the-web-office)
3. [Open the file in the Import screen](https://stonqs.app/guides/import-interactive-brokers-flex-query/#open-the-file-in-the-import-screen)
4. [Check what the app leaves out](https://stonqs.app/guides/import-interactive-brokers-flex-query/#check-what-the-app-leaves-out)
5. [Match the instruments](https://stonqs.app/guides/import-interactive-brokers-flex-query/#match-the-instruments)
6. [Write it](https://stonqs.app/guides/import-interactive-brokers-flex-query/#write-it)
7. [What the importer reads from each section](https://stonqs.app/guides/import-interactive-brokers-flex-query/#what-the-importer-reads-from-each-section)
8. [If something goes wrong](https://stonqs.app/guides/import-interactive-brokers-flex-query/#if-something-goes-wrong)

A currency exchange in a Flex Query is one trade. Stonqs writes it as two linked rows, one in each currency, so swapping euros for dollars counts as money moving inside the portfolio and not as a withdrawal plus a deposit. Two other things differ from a CSV: a dividend and the tax withheld from it stay two operations, and three kinds of row are left out on purpose.

A Flex Query is a report you define once in the broker’s web office and download as XML for any period. XML names what each value is, so there is no date format, decimal separator or column mapping to answer. Which attribute is read from which section is [in the tables below](https://stonqs.app/guides/import-interactive-brokers-flex-query/#what-the-importer-reads-from-each-section), for when a row looks off.

## Before you start

You need a portfolio with a brokerage account and a cash account linked to it (see [Install Stonqs and set up your first portfolio](https://stonqs.app/guides/install-stonqs-first-portfolio/)), and an Interactive Brokers login. The four wizard steps are the ones in [the CSV import guide](https://stonqs.app/guides/import-broker-csv/), minus the questions a Flex Query answers itself. Keep in mind that your broker’s own statements are the record; what Stonqs shows is computed from the file you give it.

## Define the query in the web office

1. Create a new Flex Query in Interactive Brokers’ web office. Menu names change, so use Interactive Brokers’ own Flex Query documentation for the current path; this guide cannot vouch for it.
2. Select Trades, Cash Transactions and Corporate Actions. [The app’s user guide](https://github.com/vvvlladimir/stonqs/blob/v0.5.0/docs/user-guide/import.md#interactive-brokers) also lists Account Information, but the reader creates no rows from it and takes the account from the statement’s header, so leaving it out changes nothing. Selecting it does no harm either.
3. Turn currency rates on and choose XML as the output format.
4. Tick the fields the reader looks for (the tables at the end). A field left out gives the app less to work with.
5. Run the query for the period you want. Any period works; for a first import, take the whole account history.

The file you get starts with a `<FlexQueryResponse` tag. Stonqs recognises a Flex statement by that tag in the first 4096 bytes.

Note

Trades come at two levels of detail, executions (each fill) and orders. Asking for both is harmless: when the file has orders, only the orders are taken, so one purchase made of three fills becomes one row, not four.

## Open the file in the Import screen

1. On the Import screen, choose the file. The File step lays itself out, with no encoding or date format to set.
2. On the Parsing step, pick “A broker statement” and the brokerage account the statement belongs to. If the portfolio has only one account of that kind, there is nothing to choose. Below the choice, “Rows land on” and “Money moves on” restate where the trades and the cash will go.

You should see no column mapping to fix. The file already says what each value is.

## Check what the app leaves out

Three kinds of row are not imported. They are counted under “Skipped by decision” on the last step, so nothing vanishes silently.

| Skipped             | Why                                                                                                                                |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Corporate actions   | Prices already account for a split, and lots are adjusted separately; importing the broker’s quantity change would count it twice. |
| Options and futures | A contract stands for a number of underlying units (the row’s multiplier is not 1), and the portfolio has nowhere to record that.  |
| Cancelled trades    | A trade whose buySell value carries a bracket, which is how the reader spots one the broker cancelled.                             |

If your account trades options, this is where your own total and the broker’s will part ways, so open the skipped rows before you write. You can take a wording off the skip list on the Parsing step, which imports those rows as whatever you map them to. Do it only for a wording you understand.

## Match the instruments

On the Instruments step, the app links each code in the file to a real instrument so prices can arrive. It tries the ISIN first, then the code and name, then the exchanges the instrument trades on, taking the first listing that has prices. A code left unresolved is imported under the broker’s spelling and stays without prices; the step tells you how many are in that state.

The ISIN is read from the row itself, or, if the row has none, looked up in the file’s security info section by its contract number (`conid`). If your query leaves both out, the match falls back to the code and the name, which is less exact.

## Write it

On the Commit step, the summary counts rows as “Ready to write”, “Duplicates”, “Skipped by decision” and “With notices”. Nothing has been written until you press the button on this step. If the instrument is not in the database yet, the “create” box decides whether it is added. Check it, then write.

Prices and exchange rates are fetched afterwards, starting from the earliest operation in the file. Importing the same file again adds nothing, so a later export that overlaps this one is safe. Next, [fill the gaps after an import](https://stonqs.app/guides/fill-gaps-after-import/).

## What the importer reads from each section

This is the reference for when a row looks wrong. The names are the XML attributes in the file, from [the reader’s source](https://github.com/vvvlladimir/stonqs/blob/v0.5.0/core/src/import/ibflex/mod.rs).

| Section                              | Attributes read                                                                                                            | Notes                                                                                                                                         |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| Trades                               | tradeDate, buySell, symbol, isin, description, quantity, tradePrice, proceeds, ibCommission, taxes, currency, fxRateToBase | Date falls back to dateTime, then reportDate. The cash amount is proceeds, else tradeMoney with its sign flipped.                             |
| Trades, for the skips and levels     | levelOfDetail, multiplier, assetCategory, conid                                                                            | Pick order over execution, flag contracts, route currency trades, find the ISIN when the row has none.                                        |
| Currency trades (assetCategory CASH) | symbol, quantity, currency, ibCommission, ibCommissionCurrency, tradeID, ibExecID                                          | Become the two linked rows. The commission goes on the leg in its own currency. A trade whose pair cannot be read is left out with a warning. |
| Cash Transactions                    | type, dateTime, amount, currency, fxRateToBase, description, symbol, isin, conid                                           | Date falls back to settleDate, then reportDate.                                                                                               |
| Corporate Actions                    | dateTime, quantity, proceeds, description, symbol, isin                                                                    | Read only so they can be shown as skipped.                                                                                                    |
| Security info                        | conid, isin                                                                                                                | Lookup table for rows that carry a conid but no ISIN.                                                                                         |
| Every row                            | accountId, acctAlias                                                                                                       | The alias is used if present, then the id, then the statement’s own accountId.                                                                |

The cash `type` values the app knows are these, spelled as Interactive Brokers spells them:

| type in the file                                      | Becomes                                            |
| ----------------------------------------------------- | -------------------------------------------------- |
| Dividends, Payment In Lieu Of Dividends               | dividend                                           |
| Withholding Tax                                       | tax                                                |
| Broker Interest Received, Bond Interest Received      | interest                                           |
| Broker Interest Paid, Bond Interest Paid              | interest charge                                    |
| Deposits/Withdrawals (also spelled with “&” or “and”) | deposit, or withdrawal when the amount is negative |
| Other Fees, Advisor Fees, Commission Adjustments      | fee                                                |

A dividend and the tax withheld from it stay two operations, so the gross payment is not netted away. A `type` not in this table is an unknown wording; map it or skip it on the Parsing step.

## If something goes wrong

**The import stops with “the Flex statement holds no trades, cash transactions or corporate actions”.** The query selected none of those sections, or the period held nothing. Check the sections and the dates, and download again.

**The file is read as an ordinary CSV, or not at all.** Only XML is recognised as a Flex statement. A Flex Query downloaded as CSV goes through the CSV path, where the app has two separate layouts, “Interactive Brokers · trades” and “Interactive Brokers · dividends”. Download XML instead.

**Holdings arrive without prices.** The code in the file could not be matched to a listing with prices. Go back to the Instruments step, correct the listing or press “Search again”.

**Fewer rows than the file has.** Compare the count with “Skipped by decision” first: options, corporate actions and cancellations are the usual gap. Rows you already imported before show as “Duplicates”.

Market data in the app comes from free third-party sources, without warranty. Your broker’s statement is what counts.

## Sources

- [Stonqs user guide: Import](https://github.com/vvvlladimir/stonqs/blob/v0.5.0/docs/user-guide/import.md)  · The Interactive Brokers section lists the sections the query needs and the three skipped kinds.
- [Stonqs: the Flex Query reader](https://github.com/vvvlladimir/stonqs/blob/v0.5.0/core/src/import/ibflex/mod.rs)  · Every attribute, fallback and wording named below is read from this file.
- [Stonqs: importing broker data](https://github.com/vvvlladimir/stonqs/blob/v0.5.0/docs/ai-reference/importing-data.md)

[  Previous Import a broker's CSV export](https://stonqs.app/guides/import-broker-csv/) [ Next Fill the gaps after an import](https://stonqs.app/guides/fill-gaps-after-import/)

## Read next

- [What broker CSV exports actually contain ](https://stonqs.app/blog/what-broker-csv-exports-contain/)
- [All guides ](https://stonqs.app/guides/)

---

[ Stonqs](https://stonqs.app/)

A portfolio tracker that runs on your own computer. Free, open source, no account.

## Product

[Download](https://stonqs.app/download/) [Privacy](https://stonqs.app/privacy/)

## Learn

[Guides](https://stonqs.app/guides/) [Blog](https://stonqs.app/blog/) [FAQ](https://stonqs.app/faq/)

## Project

[About](https://stonqs.app/about/) [Source code](https://github.com/vvvlladimir/stonqs) [Changelog](https://github.com/vvvlladimir/stonqs/blob/main/CHANGELOG.md) [Discussions](https://github.com/vvvlladimir/stonqs/discussions) [Report a bug](https://github.com/vvvlladimir/stonqs/issues)

Stonqs is a tool for recording and analysing your own investments. It is not financial, tax or legal advice, and neither are the answers of its assistant. Market data comes from free third-party sources with no guarantee of accuracy. This site sets no cookies and loads nothing from other servers; the only thing it keeps in your browser is the language you pick.

[Legal notice](https://stonqs.app/legal-notice/) [Privacy policy](https://stonqs.app/privacy-policy/)
