
Interactive Brokers Flex Query + Python: How to Automate Your Trading Reports (2026 Guide)
Originally published on supa.is I run an automated USDJPY momentum strategy on Interactive Brokers . Every week, I used to spend 30+ minutes logging into the portal, downloading reports, copying numbers into spreadsheets, and calculating my P&L breakdown. Then I discovered Flex Queries — IB's most underrated feature — and wrote a Python script that pulls everything automatically. Now my reports generate themselves every Monday morning before I wake up. Here's how to set it up from scratch. What Is a Flex Query? A Flex Query is IB's customizable reporting API. Instead of clicking through Account Management to download generic statements, you define exactly what data you want — trades, cash flows, positions, performance — and IB returns it as structured XML or CSV. The key difference from the standard Activity Statement: Feature Activity Statement Flex Query Customizable fields ❌ Fixed format ✅ Pick exactly what you need API access ❌ Manual download only ✅ Programmatic via token Output f
Continue reading on Dev.to Python
Opens in a new tab


