IBKR Web API vs TWS API: Which One Your Trading Bot Needs
In most self-built trading bots, the TWS API through IB Gateway is the better fit, because its market data streams run until you cancel them, it offers nearly the full feature set of Trader Workstation, and it allows 50 requests per second by default. The Web API lets you trade without TWS, but individual accounts still run the Client Portal Gateway with a browser login on the same machine and get 10 requests per second per session. Tables, a tested pacing check and a checklist follow, as of November 2026.
What is the difference between the TWS API and the Web API?
The TWS API is a TCP socket protocol. Your program connects as a client to Trader Workstation (TWS) or IB Gateway, which holds the authenticated session with Interactive Brokers (IBKR). IBKR offers it in Python, Java, C++, C# and VB.NET (the last two on Windows only) and describes it as having nearly full parity with the functionality, order types and market data of TWS.
The Web API is a REST interface: JSON over HTTPS plus a websocket for streaming. Some IBKR pages still call it the CP Web API, short for Client Portal. IBKR says its trading part is free of cost for all clients.
IB Gateway is a lighter alternative to TWS without the trading interface: identical for the TWS API, with about 40% lower resource use. The Client Portal Gateway is a Java client that reverse-proxies the Web API login. Choosing a gateway therefore means choosing an API. To have a developer make that call and build the connection, see Interactive Brokers bot development.
IBKR Web API vs TWS API at a glance
Based on IBKR's documentation as of November 3, 2026.
| Criterion | TWS API | Web API |
|---|---|---|
| What must run | TWS or IB Gateway, logged in | Client Portal Gateway (individual accounts) or OAuth (advisor, broker, fund and vendor accounts) |
| Login | Username and password in the TWS or IB Gateway window; again after the Saturday night reset, even with auto restart | Browser login on the Client Portal Gateway machine; sessions last up to 24 hours |
| Rate limit | Market data lines ÷ 2 per second, 50 by default | 10 requests per second per session; /iserver/orders and /iserver/trades once every 5 seconds |
| Parallel programs | Up to 32 API clients per instance, each with its own client ID | One brokerage session per username across all IBKR platforms |
| Streaming | Data flows until canceled | Websocket; market data requests (topic smd) end after 10 minutes and must be renewed |
| Orders | Nearly full parity with TWS | Order reply messages must be confirmed or suppressed before IBKR accepts the order |
| Account | Opened and funded IBKR Pro | IBKR Pro for API market data; the Client Portal Gateway blocks Lite and fractional order submissions from October 30, 2026 |
Which API should your bot use? A decision table
Editorial assessment based on the limits above, as of November 2026.
| If your bot needs … | Choose | Why |
|---|---|---|
| Streaming quotes for many symbols, frequent orders | TWS API through IB Gateway | 50 requests per second by default; streams run until canceled, and streamed updates do not count |
| Less common order types | TWS API | Nearly full parity with TWS |
| Several programs on one account (strategy, risk monitor, dashboard) | TWS API | Up to 32 API clients per instance, each with its own client ID; on the Web API, all programs share one brokerage session and its 10 requests per second |
| A REST stack and a few orders a day | Web API through the Client Portal Gateway | 10 requests per second is enough, if a daily browser login on that machine is acceptable |
| Unattended operation for an individual account | TWS API through IB Gateway, with a weekly login routine | No route removes the login, but IB Gateway asks weekly, the Client Portal Gateway at least daily |
| Programmatic login as an advisor, broker, fund or vendor | Web API with OAuth | IBKR lists these account types for OAuth |
| More than 50 requests per second | FIX | IBKR's suggestion when orders would otherwise queue; 10,000 USD equity and a 1,500 USD monthly minimum commission |
| Reports and nightly reconciliation | Flex Web Service, next to either API | Automates Flex Query reports |
| TradingView alerts as signals | A webhook receiver feeding either API | See TradingView alerts to Interactive Brokers |
TWS API with IB Gateway: requirements, pacing and the weekly login
IBKR requires an opened and funded IBKR Pro account, a current Stable or Latest release of TWS or IB Gateway and of the API, and at least Python 3.11.0, Java 21 or C++14. For Python code on ib_insync or ib_async, see migrating from ib_insync to ib_async.
Pacing is generous for streaming bots: market data lines divided by two per second, so 100 lines (the default) allow 50 requests and 200 lines allow 100. For a data stream, only the starting request counts. Depending on a setting in TWS or IB Gateway, excess requests are paced or rejected with error 100; in reject mode, three violations end the API session. Above 50 requests per second, IBKR suggests FIX.
The catch is the login. You enter username and password in the login window, and IBKR does not support a headless session without a graphical interface. Both applications are designed to restart daily. With auto restart they can run from Sunday to Sunday, but after the Saturday night server reset someone must enter the security credentials again. IBC, the community tool for automating that login, was archived on GitHub on September 1, 2026. Current options: running IB Gateway headless in Docker after IBC.
Web API and the Client Portal Gateway: login, sessions and order replies
For individual accounts, IBKR lists only the Client Portal Gateway: you start the Java program, log in through a browser on the same machine, and every API call must come from that machine. OAuth allows a fully programmatic login, but IBKR lists it for advisor, broker, proprietary trading group and fund accounts and, for OAuth 1.0a, third-party software developers.
Four rules shape the design:
- Session start: trading and market data run through
/iserverendpoints and need a brokerage session. After/iserver/auth/ssodh/init, IBKR recommends a 2-second pause, then a non-empty/iserver/accountsresponse. - Keep-alive: without requests, the session times out after about 5 minutes. Any
/iserverrequest or open websocket market data stream keeps it alive; otherwise IBKR recommends/tickleabout once a minute. Sessions last at most 24 hours and reset at midnight New York, Zug or Hong Kong time, depending on the nearest connection; daily server maintenance can end them earlier. - Limits: 10 requests per second per session. Violations return HTTP 429, offending IP addresses can land in a 10-minute penalty box, and repeat offenders can be blocked.
/iserver/ordersand/iserver/tradesallow one request every 5 seconds; polling for fills every second exceeds that fivefold. - Order replies: an order can return messages that need a confirmation, without which IBKR does not accept it. IBKR strongly recommends suppressing them per session via
/iserver/questions/suppress. Editorial assessment: suppress only message types you have read and decided to accept, because each one replaces a confirmation a human would otherwise give.
Can you use the Interactive Brokers API without TWS?
Yes, but not without IBKR software or an eligible account type:
- TWS API through IB Gateway: no trading interface, but a login window and a new login every week.
- Web API through the Client Portal Gateway: a local Java program, a browser login on that machine and sessions of at most 24 hours.
- Web API through OAuth: fully programmatic, for the account types listed above.
If IB Gateway runs on a server, remember that the TWS API port has no login of its own: IBKR describes TWS and IB Gateway as a server that client programs connect to after the user has authenticated, and a client program connects through a socket port and a client ID, without a password. Keep the port on localhost or behind an encrypted tunnel such as SSH, and never open it to the internet. With the Client Portal Gateway, the browser login must happen on the server itself; in most setups, that makes unattended operation harder than with IB Gateway (editorial assessment).
IBKR API rate limits: check your bot's request plan in Python
Add up what your bot sends per second at its busiest moment, such as the market open. This typical example checks it against the limits it lists; IBKR's pacing pages name more endpoints. Test conditions: run on November 3, 2026 with Python 3.9.6 and 3.12.15 on macOS, standard library only, no network access, no broker connection, no orders. The script does not import the TWS API, so IBKR's Python 3.11 minimum does not apply to it.
# Typical example; IBKR limits as of November 3, 2026
TWS_DEFAULT_LINES = 100 # TWS API pacing = market data lines / 2 per second
WEB_SESSION_LIMIT = 10 # Web API: requests per second per session
WEB_ENDPOINT_LIMIT = { # Web API: requests per second, selected endpoints
"/iserver/marketdata/snapshot": 10,
"/iserver/orders": 1 / 5,
"/iserver/trades": 1 / 5,
"/tickle": 1,
}
def tws_issues(sent_per_second, lines=TWS_DEFAULT_LINES):
# count what the bot sends; streamed updates do not count
limit = lines / 2
return [f"{sent_per_second:g}/s exceeds {limit:g}/s"] if sent_per_second > limit else []
def web_issues(plan):
# plan maps endpoint -> peak requests per second
issues = []
total = sum(plan.values())
if total > WEB_SESSION_LIMIT:
issues.append(f"{total:.1f}/s exceeds {WEB_SESSION_LIMIT}/s per session")
for endpoint, rate in plan.items():
limit = WEB_ENDPOINT_LIMIT.get(endpoint)
if limit is not None and rate > limit:
issues.append(f"{endpoint}: {rate:g}/s exceeds {limit:g}/s")
return issues
# Calculation example: 20 symbols at the open
naive = {"/iserver/marketdata/snapshot": 20, # one request per symbol, every second
"/iserver/orders": 1, # fills checked every second
"/tickle": 1 / 60}
batched = {"/iserver/marketdata/snapshot": 1, # all 20 conids in one request
"/iserver/orders": 1 / 5, # fills checked every 5 seconds
"/tickle": 1 / 60}
tws_peak = 20 + 2 # 20 streams opened once, plus 2 orders
for name, issues in (("Web API, one snapshot per symbol", web_issues(naive)),
("Web API, batched", web_issues(batched)),
("TWS API", tws_issues(tws_peak))):
print(f"{name}: {len(issues)} limit(s) exceeded")
for issue in issues:
print(" -", issue)
# Self-test of the limit logic
assert tws_issues(50) == [] and tws_issues(51) != [] and tws_issues(100, lines=200) == []
assert web_issues({"/iserver/orders": 0.2}) == [] and len(web_issues({"/iserver/orders": 0.5})) == 1Output:
Web API, one snapshot per symbol: 3 limit(s) exceeded - 21.0/s exceeds 10/s per session - /iserver/marketdata/snapshot: 20/s exceeds 10/s - /iserver/orders: 1/s exceeds 0.2/s Web API, batched: 0 limit(s) exceeded TWS API: 0 limit(s) exceeded
On the TWS API, the same bot uses 22 of 50 requests per second. On the Web API, the fix is fewer requests: the snapshot endpoint takes a comma-separated list of conids, so one request can cover all 20 symbols, and fills are checked at most every 5 seconds. The first snapshot request for a conid only starts its data stream and returns no prices yet. Streaming quotes over the websocket also works, but smd requests end after 10 minutes and must be renewed. If the strategy still needs more, choose the TWS API.
FIX, Flex Web Service and MCP: when neither API is the answer
- FIX targets institutions and OMS vendors. IBKR requires 10,000 USD account equity to apply and charges a monthly minimum commission of 1,500 USD for the first session, 1,000 USD for each further one. Through IB Gateway, FIX is limited to 250 messages per second.
- Flex Web Service automates Flex Query reports, IBKR's raw data files of account activity, which suits nightly reconciliation next to either API.
- AI integration via MCP connects ChatGPT, Claude, Grok, Perplexity and other MCP clients to authorized account data. In Review & Approve mode, you approve and submit each AI order; an optional Autonomous Trading mode in a separate AI Partition is limited to individual non-margin accounts. Details: Claude or ChatGPT with Interactive Brokers via MCP.
Editorial assessment: an MCP assistant does not replace a bot. Rule-based trading needs versioned code, tests and fixed risk limits, and human approval of every AI-generated order remains the safer default.
Risks and a checklist before you write code
- TWS API: code 1100 means TWS or IB Gateway lost its connection to IBKR, for example after an internet outage, the nightly server reset or a competing session. After 1101, market data requests must be sent again; after 1102, they are kept.
- Web API: a username holds only one brokerage session, so logging in to Client Portal, TWS or IBKR Mobile with the bot's username can end the bot's session.
- Both: API market data needs IBKR Pro, subscriptions and Market Data API access enabled in Client Portal, and 500 USD in the account on top of the subscription costs.
- Market risk: an automated system can repeat an error within seconds, and with leveraged products losses can reach a total loss. Position reconciliation, hard loss limits, fixed sizing rules (see the position size calculator) and a kill switch belong in every setup.
Checklist before coding:
- List instruments, order types, order frequency, data needs and where the system runs.
- Run your peak requests per second through the check above.
- Check the account: IBKR Pro, funded, market data subscriptions and API access.
- Decide who logs in when: weekly for IB Gateway, at least daily for the Client Portal Gateway. Give the bot its own username if you also trade manually; trading permissions and market data subscriptions belong to the username, so a second username needs its own subscriptions.
- Prototype in the paper account, with handling for disconnects, resets, error codes and HTTP 429.
- Plan monitoring and position reconciliation; the account holder decides when the bot goes live.
Frequently asked questions
Is the TWS API or the Web API better for a trading bot?
In most self-built bots with their own trading logic, the TWS API through IB Gateway is the stronger choice, because it offers nearly full TWS functionality, does not count streamed updates toward pacing and allows 50 requests per second by default. The Web API suits dashboards and bots with few requests: it is capped at 10 requests per second per session, and individual accounts log in through the Client Portal Gateway in a browser.
Can I use the Interactive Brokers API without TWS?
Yes. The TWS API also works with IB Gateway, a lighter application without the trading interface that still needs a login in its window and a new login after the weekly reset. The Web API needs no TWS, but individual accounts run the Client Portal Gateway and log in through a browser on the same machine. A fully programmatic OAuth login is listed for advisor, broker, fund and third-party developer accounts.
What is the difference between IB Gateway and the Client Portal Gateway?
IB Gateway is a lighter alternative to Trader Workstation without its trading interface. It serves the TWS API over a socket port and, according to IBKR, uses about 40% fewer resources than TWS. The Client Portal Gateway is a Java client that proxies the login for the Web API, a REST interface. Your choice of gateway therefore decides which API your bot uses.
What are the IBKR API rate limits?
The TWS API allows your market data lines divided by two requests per second, which is 50 with the default 100 lines; streamed updates do not count. The Web API allows 10 requests per second per session and returns HTTP 429 when you exceed it. Some endpoints are stricter: order and trade lists allow one request every 5 seconds. FIX through IB Gateway is limited to 250 messages per second.
Can I use the IBKR API with an IBKR Lite account?
In practice, no. IBKR requires an IBKR Pro account for the TWS API and for market data through its APIs. For the Web API, IBKR's changelog says the Client Portal Gateway blocks order submissions from Lite accounts, and fractional orders, in production from October 30, 2026. Check the current account rules before you build.
Is the Interactive Brokers API free?
IBKR says the trading part of its Web API is available to all clients free of cost. Market data is not: API market data needs subscriptions, and IBKR expects 500 USD in the account on top of their cost. FIX is a different case, with a monthly minimum commission of 1,500 USD for the first session; IBKR bills any shortfall. As of November 2026.
How long does an IBKR Web API session stay logged in?
According to IBKR, up to 24 hours, with a reset at midnight New York, Zug or Hong Kong time depending on your nearest connection. Without requests, the brokerage session times out after about 5 minutes, so IBKR recommends calling the tickle endpoint about once a minute. Daily server maintenance can end a session earlier.
Can IB Gateway run headless on a server?
Not officially. IBKR states that a headless session of TWS or IB Gateway without a graphical interface is not supported and that username and password are entered in the login window. IBC, the community tool for automating that login, was archived on GitHub on September 1, 2026, so any setup built on it needs its own maintenance plan.
Sources and status
- IBKR API Home (Web API, TWS API, Flex Web Service, FIX) — Interactive Brokers (retrieved November 3, 2026)
- TWS API: Requirements — Interactive Brokers (retrieved November 3, 2026)
- TWS API: Download TWS or IB Gateway (headless, daily restart, resources, socket server) — Interactive Brokers (retrieved November 3, 2026)
- TWS API: Connectivity Behavior (socket connection, up to 32 clients) — Interactive Brokers (retrieved November 3, 2026)
- TWS API: Pacing Limitations (incl. FIX in IB Gateway) — Interactive Brokers (retrieved November 3, 2026)
- TWS API: Error Codes (1100, 1101, 1102) — Interactive Brokers (retrieved November 3, 2026)
- Web API: Introduction (trading API free of cost) — Interactive Brokers (retrieved November 3, 2026)
- Web API: Authentication Introduction (Client Portal Gateway, OAuth account types) — Interactive Brokers (retrieved November 3, 2026)
- Web API: Limitations of the Client Portal Gateway — Interactive Brokers (retrieved November 3, 2026)
- Web API: Trading Sessions in the Web API (brokerage session, usernames, order replies) — Interactive Brokers (retrieved November 3, 2026)
- Web API: Authentication Frequently Asked Questions (session length, tickle) — Interactive Brokers (retrieved November 3, 2026)
- Web API: Pacing Limitations — Interactive Brokers (retrieved November 3, 2026)
- Web API: Top-of-Book Snapshots (comma-separated conids, pre-flight request) — Interactive Brokers (retrieved November 3, 2026)
- Web API: Changelog (entries of April 14 and October 29, 2026) — Interactive Brokers (retrieved November 3, 2026)
- FIX: Requirements & Costs — Interactive Brokers (retrieved November 3, 2026)
- Market Data Requirements — Interactive Brokers (retrieved November 3, 2026)
- AI Integrations and IBKR Autonomous Trading (FAQ) — Interactive Brokers (retrieved November 3, 2026)
- IBC repository (archived) — IbcAlpha on GitHub (retrieved November 3, 2026)
As of November 2026. Third-party rules, prices and APIs may have changed since; the providers' current documentation and the official texts are authoritative.
This article is also available in German: Interactive Brokers API-Vergleich: TWS, Web API, FIX und Flex.
Need an IBKR bot built on the right API, or an existing one reviewed? Get in touch — the free initial call covers your data needs, rate limits, the test plan in the paper account and day-to-day operation. More: Trading bot development for Interactive Brokers and MetaTrader 5.