IBKR Flex Query Setup: Token, Query ID and Errors
Turn on the Flex Web Service in Client Portal for a token, save an Activity Flex Query for its Query ID, then call SendRequest and GetStatement, per IBKR's docs.
Checked Not affiliated with Interactive Brokers.
| Step | Where | You get |
|---|---|---|
| Turn it on | WherePerformance & Reports > Flex Queries, the gear on Flex Web Service Configuration, the toggle | You getA token |
| Build the query | Where+ beside Activity Flex Query, sections, Continue, Create | You getA saved query |
| Copy its ID | WhereThe info icon beside it | You getThe Query ID |
| Fetch it | WhereThe two calls below | You getUp to 365 days per call |
Which sections to pick3 rows
| You want | Section | Fields |
|---|---|---|
| Positions | SectionOpen Positions | FieldsSymbol, Quantity, Mark Price, Position Value, Cost Basis Price, FIFO Unrealized PNL, Currency, FX Rate to Base |
| Account value | SectionChange in NAV | FieldsStarting Value, Deposits/Withdrawals, Dividends, Commissions, Forex Translation, Ending Value, TWR |
| Cash | SectionCash Report | FieldsStarting Cash, Deposits, Withdrawals, Ending Cash, Ending Settled Cash, by currency |
The two calls
bash
BASE=https://ndcdyn.interactivebrokers.com/AccountManagement/FlexWebService
curl -s -A "curl/8" "$BASE/SendRequest?t=$FLEX_TOKEN&q=$QUERY_ID&v=3"
# <Status>Success</Status> <ReferenceCode>1234567890</ReferenceCode>
sleep 10
curl -s -A "curl/8" "$BASE/GetStatement?t=$FLEX_TOKEN&q=1234567890&v=3" -o statement.xmlq is the Query ID, then the ReferenceCode. Send a User-Agent and v=3. Failures answer HTTP 200 too: a fake token sent on 5 November 2026 got 1015, Token is invalid.
Token life, dates and limits5 items
- Generate A New Token sets its life, 6 hours to 1 year, and optionally one IP address. The old token stops working.
fd=yyyymmdd&td=yyyymmddsets the range; send both.p=Nasks for the last N days instead. Either reaches 365 days per request.- Saved queries cover the four previous calendar years and this one.
- One request a second and 10 a minute per token, or error
1018.
Every error code21 rows
| Code | IBKR's message | Check first |
|---|---|---|
| 1001 | IBKR's messageStatement could not be generated at this time. Please try again shortly. | Check firstRetry later; IBKR gives no reason |
| 1003 | IBKR's messageStatement is not available. | Check firstThe query's period and accounts |
| 1004 | IBKR's messageStatement is incomplete at this time. Please try again shortly. | Check firstRetry later |
| 1005 | IBKR's messageSettlement data is not ready at this time. Please try again shortly. | Check firstRetry later |
| 1006 | IBKR's messageFIFO P/L data is not ready at this time. Please try again shortly. | Check firstRetry later |
| 1007 | IBKR's messageMTM P/L data is not ready at this time. Please try again shortly. | Check firstRetry later |
| 1008 | IBKR's messageMTM and FIFO P/L data is not ready at this time. Please try again shortly. | Check firstRetry later |
| 1009 | IBKR's messageThe server is under heavy load. Statement could not be generated at this time. Please try again shortly. | Check firstRetry later |
| 1010 | IBKR's messageLegacy Flex Queries are no longer supported. Please convert over to Activity Flex. | Check firstRebuild it as an Activity Flex Query |
| 1011 | IBKR's messageService account is inactive. | Check firstThe Flex Web Service toggle is on |
| 1012 | IBKR's messageToken has expired. | Check firstGenerate a new token |
| 1013 | IBKR's messageIP restriction. | Check firstThe token's IP address matches the caller |
| 1014 | IBKR's messageQuery is invalid. | Check firstThe Query ID, under the same account selection |
| 1015 | IBKR's messageToken is invalid. | Check firstThe Current Token, not an older one |
| 1016 | IBKR's messageAccount in invalid. | Check firstThe accounts in the query |
| 1017 | IBKR's messageReference code is invalid. | Check firstThe ReferenceCode goes in q of GetStatement |
| 1018 | IBKR's messageToo many requests have been made from this token. Please try again shortly. Limited to one request per second, 10 requests per minute (per token). | Check firstSlow down |
| 1019 | IBKR's messageStatement generation in progress. Please try again shortly. | Check firstWait, then call GetStatement again |
| 1020 | IBKR's messageInvalid request or unable to validate request. | Check firstThe URL, v=3 and the User-Agent; IBKR gives no reason |
| 1021 | IBKR's messageStatement could not be retrieved at this time. Please try again shortly. | Check firstRetry later |
| 1025 | IBKR's messageToo many failed attempts. | Check firstStop, then check the token and Query ID |
Advisor and linked accounts3 items
- Only the master account sees Flex Web Service Configuration; subaccounts do not.
- One token can fetch every linked account the query includes.
- A query shows only under the account selection it was created with.
Where Gloom fits
Gloom's Interactive Brokers plugin takes the same token and Query ID, from an XML query, under Flex (read-only) in Brokers (BR).

Gloom covers
- Positions with cost, mark, unrealized P&L and FX rate.
- Net liquidation and cash.
- Both calls, the wait and plain errors.
Gloom does not cover
- The browser version: Flex needs the app or the terminal.
- Trades, or anything newer than the statement.
Sources5 sources
- IBKR's Client Portal guides, read 5 November 2026: Flex Queries (updated 27 October 2026), Create an Activity Flex Query (23 September 2026) and Enable Flex Web Service (29 August 2025): the menus, sections, formats, periods and the years a query reaches. Field names from the reporting reference for Open Positions, Change in NAV and Cash Report, updated 20 March 2025.
- Configure Flex Web Service, IBKR's Broker Portal guide, updated 17 June 2026: a 6-hour default expiry, no IP restriction when left blank, the old token invalidated, the User-Agent header,
fd,tdandpup to 365 days, version 2 withoutv. - IBKR's Flex Web Service docs, read 5 November 2026: access token (6 hours to 1 year, linked accounts), Generate a Report (pacing, ignore
<url>), Retrieve the Report, SendRequest and error codes. - Two calls with an invalid token, 5 November 2026: HTTP 200,
text/xml,<Status>Fail</Status>,1015,Token is invalid. - Gloom's Interactive Brokers plugin source, v1.1.0: the rows it reads, the polling and the 15-minute cache.
Not verified3 claims
- What causes error
1020when the URL is right. A reply on 11 July 2026 blamed selecting every field in Open Positions (r/interactivebrokers). - Error
1001from a second IP address with no IP restriction, reported on 9 May 2026 (r/interactivebrokers). No cause was confirmed. - That Gloom needs Open Positions at the Summary level of detail. It reads every row as a position; not tested on an account.
- What causes error