2.1

🔶 Set Up Interactive Brokers

Flex Query and automatic synchronization

1. Overview

▶️Video tutorial: from zero to ready (19 min)The complete setup step by step on video — including the two traps most people fall into (the period and the validity of the token).Interactive Brokers (IBKR) offers the most comprehensive integration.

✅ Process:
1. Create Flex Query
2. Download and import Flex Query as XML for each year
3. Get updates via Flex Sync
⚠️ Important:
Flex Sync only retrieves updates from recent days. XML import builds the complete history. Without complete history, the system cannot properly evaluate trades (e.g., option strategies, campaigns, forex gains).

2. What is a Flex Query?

A Flex Query is a customizable report from Interactive Brokers. You define once which data you want to export, then you can retrieve this report anytime - manually or automatically.

Benefits:
• All trades, dividends, positions in one report
• Automatic synchronization possible
• Data from the last 365 days available
• No manual data entry required

Step-by-Step Guide

1

Step 1: Create Flex Query at IBKR

1. Log in to IBKR:
Go to interactivebrokers.com and log into your account.

2. Open Flex Queries:
Navigate to: Performance & Reports → Flex Queries

3. Pick the right query type:
The Flex Queries page lists two query types below each other. Only the first one is correct:
✅ Activity Flex Query
This is the right one. Click the ➕ in the top right of this panel"Create".
❌ Trade Confirmation Flex Query
Do not use this one! It only contains trade confirmations. sTraderZ.com cannot read any data from it — the import would come out completely empty.
As long as you have not created a query yet, the Activity Flex Query panel only shows a note saying you have no templates. The ➕ is still there — in the top right corner of that panel.

ℹ️ You do not need the "Configure with AI" button — just follow steps 2 and 3 below, they list every setting.
2

Step 2: Configure Flex Query

Query Name: anything you like, e.g. "SingularityTrader".

Then set the Delivery Configuration and General Configuration exactly like this:
0 of 11 settings done
3

Step 3: Select Report Sections

Enable all of the following sections in the Flex Query. The list is here to tick off — your progress is saved even if you reload the page.
0 of 20 sections enabled
⚠️ Fields vs. type options — the crucial difference

Fields (the numbered list inside each section): always use "Select All" — the more, the better. Missing fields are the most common cause of import errors.

Type options (the "Options:" line at the top of a section): here the opposite applies — pick only one level of detail, exactly the one stated above. Every additional level ("Summary", "Orders", "Symbol Summary", "Lots") describes the same event a second time in another row. sTraderZ.com does not evaluate the level of detail, it processes every row — so multiple levels can lead to double-counted trades, fees and positions. Exception: "Closed Lots" and "Wash Sales" in the Trades section are not merely redundant, they must be off.
4

Step 4: Save Query

Click "Continue" and then "Create".

After creation, you'll see your query in the list. Note the Query ID - you'll need it shortly.
5

Step 5: Generate Flex Query Token

For automatic retrieval you need an access key. IBKR calls it a token — in sTraderZ.com you will later enter it as the Flex Token.

1. Open the Flex Web Service:
On the Flex Queries page, scroll all the way down to the "Flex Web Service Configuration" block and click "Configure" (⚙️).

2. Enable the service:
On the "Configure Flex Web Service" page the Flex Web Service status must be enabled. If it is off, sTraderZ.com cannot retrieve the query — IBKR will reject the request.

3. Generate the token:
In the "Generate New Token" section:
0 of 3 settings done
⚠️ The token is displayed only once
Copy it immediately and store it securely. If you lose it you have to generate a new one — and doing so invalidates the old token. Any sync still using the old token will fail from that moment on.

The token is valid for 1 year. After it expires, generate a new one and store it in your account configuration.
6

Step 6: XML Export for All Years

Export the Flex Query as XML for each year of your trading history:

1. Open Flex Query:
At IBKR: Performance & Reports → Flex Queries

2. Adjust Date Range:
Edit the query and set the date range to one calendar year (e.g., 01/01/2023 - 12/31/2023)

3. Run Query:
Click "Run" and download the XML file

4. Repeat for Each Year:
Repeat steps 2-3 for all years you've traded at IBKR (e.g., 2021, 2022, 2023, 2024).
7

Step 7: XML Import of History

Import all downloaded XML files into Singularity Trader:

1. Open Import Section:
Go to Accounts → Your IBKR Account → Configuration → "Upload XML"

2. Oldest Year First:
Start with the oldest XML file (e.g., 2021) and work your way forward chronologically

3. Import All Years:
Import all XML files sequentially up to the current year

⚠️ Important: This step is essential! Without complete history, option strategies, trade campaigns, and forex gains cannot be calculated correctly.
8

Step 8: Set up in Singularity Trader

1. Open Account Configuration:
Go to Accounts → Your IBKR Account → Configuration

2. Enter Flex Query Data:
Flex Query ID: The 7-digit query ID from IBKR (shown on the query overview, e.g. 1570627)
Flex Token: The token you generated in step 5

3. Save and Test:
Click "Save" and then "Sync Now" to test.

Automatic Synchronization

After successful setup, your trades are automatically synchronized daily. You don't need to do anything else!

What happens during sync:
• New trades are imported
• Positions are updated
• Dividends are recorded
• Option strategies are recognized
• Forex gains are calculated (FIFO)

You can always manually sync anytime if you want the latest data immediately.

12. Auto-Retry on Temporary Errors

IBKR Flex fetches can fail temporarily for various reasons (e.g. a brief server error at IBKR, a network timeout, or a query that is currently being processed). Singularity Trader has an automatic retry queue for this:

• If a sync fails, it is retried up to 3 times automatically (with exponential backoff).
• Only when all attempts have failed does a CRITICAL entry appear in the system log along with a notification.
• Temporary problems usually resolve themselves without you having to intervene.

You can see the current sync status in the Accounts area — green = last sync successful, yellow = retry in progress, red = failed after 3 attempts.

13. Alternative: Manual XML Import

If you prefer not to use automatic synchronization, you can export the Flex Query manually:

1. At IBKR: Flex Queries → click "Run" next to your query
2. Download: Save the XML file
3. Upload: In Singularity Trader → Accounts → Configuration → "Upload XML"

This method is also required for older data (> 365 days), since Flex Sync only goes back 1 year.

14. Imported Data at IBKR

Fully supported:
• Stock trades (buy/sell)
• Options trades incl. Greeks
• Futures and Forex
• Dividends (gross, net, withholding tax)
• Interest (credit/debit)
• Option exercises and assignments
• Stock splits and mergers
• Statement of Funds for currency FIFO

Automatically detected:
• Option strategies (spreads, iron condors, etc.)
• Covered calls / cash-secured puts
• Trade campaigns
• Currency gains under § 23 EStG

15. 📥 Data from TradingLogbook? Bring Your Tags.

📥 Coming from TradingLogbook?

You can transfer your maintained strategies as tags onto your already-imported trades — symbol + opening date is all it takes. Done in 3 minutes.

To the 3-step migration

⚠️ Troubleshooting

"Token expired":
Generate a new token at IBKR and enter it in the configuration.

"Query not found":
Verify that the Query ID is correct and that the query is active.

"No data":
Make sure all required sections are enabled in the query.

"Error during import":
Check the import log for details. Common cause: missing fields in the query.

⚠️ Reload Missing Historical Trades (⚠️ Badge on Positions)

The problem:
A ⚠️ symbol appears next to the account name for a position in the dashboard or positions list. The tooltip reads "Missing trade data — No transactions were imported for this position. As a result, the strategy cannot be detected automatically."

The cause:
The position itself is known via the IBKR portfolio snapshot, but the opening trades lie before the earliest trading day imported so far. This is typical for LEAPS (long-dated options) that were opened months or years before the first Flex Sync.

✅ The solution:
Trigger a one-time ad-hoc export with a historical date range on your existing Flex Query, download it as XML, and upload it via the XML import. There is no need to create a new Flex Query!
Step by step:
1. Trigger the historical export at IBKR
• Find your existing Flex Query → click Run
• Change the period to Custom Date Range
• From: as far back as needed (e.g. 01/01/2024)
• To: one day before the earliest already-imported trade
• Format: XML → confirm Run

2. Download the XML file and save it locally

3. Upload in Singularity Trader
• Accounts → IBKR account → "Configure IBKR" → XML Import

4. What happens during import
• Only new trades are imported (no duplicates)
• Strategies, campaigns and trade cycles are recalculated

5. Check the result
• Reload the dashboard — the ⚠️ badge should be gone

If the ⚠️ persists: The opening trades go back even further → trigger another run with an earlier start date.

18. ✅ Cross-check: what the finished query looks like

After saving, IBKR shows you a summary page ("Review your Activity Flex Query"). Compare it against this reference — that is what your query has to look like when everything is right.
SectionType options ("Options:" line)
Interest Accruals
Cash TransactionsAll sub-types (Dividends, Payment In Lieu Of Dividends, Withholding Tax, Deposits & Withdrawals, Broker/Bond Interest, Other Fees, Other Income …) + Detail
CFD Charges
Cash Report
Incoming/Outgoing Trade TransfersTrade Transfers
Forex P/L DetailsTransaction
Grant Activity
Financial Instrument Information
Statement of FundsBase Currency Summary, Currency Breakout, Include Starting and Ending Balances
Corporate ActionsDetail
Account Information
Net Asset Value (NAV) in Base
Open PositionsSummary (no "Lots")
Open Dividend Accruals
Option Exercises, Assignments and Expirations(the one most people forget!)
Prior Period Positions
TradesExecution onlyno "Closed Lots", no "Wash Sales", no "Orders"/"Asset Class"/"Symbol Summary"
Transaction FeesExecution only (not additionally "Summary")
TransfersTransfer (no "Lots")
Change in Dividend AccrualsDetail (not additionally "Summary")

Delivery Configuration and General Configuration:

SettingValue
AccountsYour account ID (e.g. U1234567)
FormatXML
PeriodLast 30 Calendar Days
Profit and LossDefault
Include Offsetting Trade/Cancel Pairs?No
Include Currency Rates?No
Include Audit Trail Fields?No
Display Account Alias in Place of Account ID?No
Breakout by Day?No
Date FormatyyyyMMdd
Time FormatHHmmss
Date/Time Separator; (semi-colon)
💡 Note down the Query ID
The same overview shows the Query ID at the top (a 7-digit number, e.g. 1570627). You will need it together with the token in step 8.