Set up an IBKR Activity Flex Query for the API sync
The exact Flex Query settings VEXA needs to pull your Interactive Brokers trades, plus where to find the token and query ID you paste in.
What this does
An Activity Flex Query is a saved report inside Interactive Brokers. You build it once, IBKR gives you a token and a query ID, and VEXA uses those two values to pull your executions whenever you press Sync. After this, IBKR trades arrive without you exporting anything.
Interactive Brokers has two kinds of Flex Query and VEXA uses both, for two different jobs.
| Query type | What it is for |
|---|---|
| Activity Flex Query | the API sync described on this page |
| Trade Confirmation Flex Query | the file you download and upload by hand |
The two use different date and time settings and are not interchangeable. If you want the download-and-upload route instead, use Export an IBKR Trade Confirmation Flex Query.
Before you start
- Build the query in a desktop browser. IBKR’s Flex Query editor is a wide, multi-step form and it is painful on a phone. Once you have the token and the query ID you can paste them into VEXA on any device.
- Broker connections need the Edge tier or above. On the Free tier the broker screens show a locked placeholder.
- Use your Master Account, the one whose number starts with
U. Flex tokens are issued per master account. - Set aside about ten minutes the first time.
Create the Flex token in IBKR
- Sign in to IBKR Client Portal at
interactivebrokers.com/portal. - Open Performance & Reports, then Flex Queries.
- Confirm the Master Account is the one selected at the top of the page.
- Click the gear icon next to Flex Web Service Configuration.
- Tick Flex Web Service Status.
- Set Expire After to one year. A shorter expiry means your sync stops working months later with no obvious cause.
- Click Generate a new Flex Token, then Save.
- Copy the Flex Token ID somewhere safe. You need it at the end.
Create the Activity Flex Query in IBKR
- Back on the Flex Queries page, find the Activity Flex Query heading.
- Click the + next to it. This is the correct query type. The Trade Confirmation section further down the page is a different report.
- Name the query.
VEXAis fine. - Under Sections, open Trades.
- Inside Trades, select Executions.
- Click Select All to include every execution field, then scroll to the bottom of that panel and save it.
- If you hold several accounts, select the ones you want included. Leave Models on Optional.
Step 5 is the one people miss. Without Executions, IBKR sends trade-level summary rows with no fill detail, and VEXA cannot reconstruct entries and exits from them.
The query settings VEXA needs
Set every one of these on the query’s settings step. These are the values that break the sync when they are wrong.
| Setting | Value |
|---|---|
| Format | CSV |
| Include header and Trailer records | No |
| Include column headers | Yes |
| Display single column header row | No |
| Include section code and line descriptor | No |
| Period | Last 365 Days |
| Date Format | yyyy-MM-dd |
| Time Format | HH:mm:ss |
| Date/Time Separator | a single space |
Then click Continue, Create, and OK. Reopen the finished query with the info or pencil icon and copy the Query ID.
Steps
You now have two values from IBKR: the Flex Token and the Query ID. Enter them in VEXA.
- Open Profile from the sidebar card at the bottom that shows your name with View Profile under it.
- Open Connected Brokers.
- Press Connect Your First Broker, or Add Another Broker if you already have one.
- Choose Interactive Brokers on the Add Broker Connection page.
- Stay on the Automated Sync tab.
- Paste the Flex Token.
- Paste the Query ID.
- Press Save Connection.
- Tap the circular avatar at the top right of Home.
- Tap Connected Services.
- Tap Add Broker, then Select Broker.
- Choose Interactive Brokers.
- Switch the segmented control to API Sync.
- Paste the Flex Token.
- Paste the Query ID.
- Tap Save Connection.
- Tap the profile chip at the bottom of the sidebar, then View Profile.
- Tap Connected Services.
- Tap Add Broker, then Select Broker.
- Choose Interactive Brokers.
- Switch the segmented control to API Sync.
- Paste the Flex Token.
- Paste the Query ID.
- Tap Save Connection.
- Tap the circular avatar at the top right of Home.
- Tap Connected Brokers.
- Tap Add Another Broker, then choose Interactive Brokers.
- Switch to the API Sync tab.
- Paste the Flex Token.
- Paste the Query ID.
- Tap Save Connection.
- Tap the profile chip at the bottom of the sidebar.
- Tap Connected Brokers.
- Tap Select Broker, then choose Interactive Brokers.
- Stay on the API Sync tab.
- Paste the Flex Token.
- Paste the Query ID.
- Tap Save Connection.
What you should see
The account appears under your broker list with a green Active badge and a last-sync time. The first sync pulls up to 365 days of executions, so it can take a minute on a busy account.
After that, nothing runs on a schedule. Saving the token does not put IBKR on an hourly job, so new trades arrive when you press Sync on the account row and not before. The last-sync time tells you when the last pull ran.
Re-running the sync never doubles anything. VEXA drops fills it has already imported, so the same 365-day window arriving again is harmless.
If it doesn’t work
- The connection saves but no trades arrive. The usual cause is a query built without Trades > Executions > Select All. Reopen the query in IBKR and check that panel.
- Nothing imports and the query looks correct. Check the Date Format and separator against the table above. A query carrying the manual-upload values returns data VEXA cannot read.
- The account later shows Needs Reauth. The token expired, or it was regenerated in IBKR. See Reconnect a broker that needs reauth.
- Share counts look impossible. IBKR keeps re-sending fills inside its rolling 365-day window. VEXA filters ones it has already consumed, so this should not happen. If it does, see Your P&L does not match your broker.
- Your SPLG history shows as SPYM. That is deliberate. SPLG and SPYM are treated as one symbol so a ticker change does not split a position in half.
Related
Related
Still stuck? Email support@vexatrade.ai.