← All articles

Connecting to Interactive Brokers: TWS API, Web API and Flex Web Service

IBKRAPI

Interactive Brokers does not have "an API". It has three, they solve different problems, and picking the wrong one is paid for in weeks of maintenance. Here is the difference, plainly.

The three surfaces

What it isWhat must be runningWhat it is for
TWS APITCP socket, asynchronousTWS or IB Gateway openReal-time data and order entry
Web APIREST over HTTPSAn authenticated sessionQueries and trading without a socket
Flex Web ServiceScheduled reportsNothingPositions and executions after the fact

Which one do I need?

  • I want live prices and to send orders from my code: TWS API. It is the one built to handle hundreds or thousands of simultaneous market data lines, and the one automated strategies run on.
  • I want to query my account from a server or a web app without keeping a desktop on: Web API.
  • I only want to read what already happened — end-of-day positions, today's executions, data for the tax report: Flex Web Service.

The usual trap: building all your analytics on the TWS API because it is the best known, then discovering it requires a TWS running on a machine nobody watches. If your question is answered by yesterday's data, a Flex report does not fall over overnight.

What is coming: one Web API with OAuth 2.0

IBKR is merging the Client Portal Web API, digital account management and the Flex Web Service into a single IBKR Web API, with shared authorization and authentication through OAuth 2.0. Existing endpoints and authentication schemes are not deprecated and keep receiving features, so nothing you build today breaks tomorrow.

The practical reading: if you are starting now, build assuming authentication ends up as OAuth 2.0 and isolate that behind your own layer. Migrating an HTTP client is an afternoon; migrating credentials scattered across twenty files is not.

Why Fulcrum Quant uses two and not one

Portfolio Sync uses the Flex Web Service, a read-only report feed: it pulls your positions and executions on a schedule. IB Live connects directly to a TWS or IB Gateway running on your own machine, which is what gives real-time positions and market data. They are two different jobs, which is why they are two different connections.

Fulcrum Quant

Position sizing, IBKR portfolio sync, risk analytics and tax reporting in one place.

Join the waitlist