# IBKR API without TWS: headless IB Gateway options

Independent and unofficial. Not affiliated with or endorsed by any broker or platform named here. Educational only: nothing here is advice, and nothing here recommends a broker or a trade.

This is the markdown version of https://openbrokerapi.com/guides/ibkr-headless-gateway, written from the same records as that page.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

You cannot skip IBKR's gateway software as a retail user, but you can skip the full TWS window. IB Gateway, IBC and Docker images cover the socket API; the Client Portal Gateway covers the Web API. Daily restarts and 2FA are the constraints you design around.

- Checked: 2026-09-18
- For: People running IBKR bots on a server
- About: [Interactive Brokers](https://openbrokerapi.com/brokers/ibkr)

## Steps

### 1. IB Gateway instead of TWS

IBKR says IB Gateway is a lighter application using about 40% fewer resources than TWS. The TWS API needs one of the two running, and IBKR says a session without a login window is not supported: the user types the username and password by hand. IBKR's older setup guide gives TWS default ports of 7496 live and 7497 paper. This site also holds 4001 live and 4002 paper for IB Gateway, which were not found on the IBKR pages read on 12 October 2026.

Status: verified. Source: [interactivebrokers.com](https://www.interactivebrokers.com/docs/tws-api/doc/architecture/the-trader-workstation/the-ib-gateway), checked 2026-09-18.

### 2. Plan for the daily restart

IBKR says both TWS and IB Gateway were designed to be restarted daily, and from version 974 both have an autorestart setting so the daily restart needs no manual step. With it on, IBKR says either can run from Sunday to Sunday, and credentials are needed again after the Saturday night server reset.

Status: verified. Source: [interactivebrokers.com](https://www.interactivebrokers.com/docs/tws-api/doc/architecture/the-trader-workstation/the-ib-gateway), checked 2026-09-18.

### 3. Plan for the weekly login

IBKR says the weekly authentication cycle starts every Monday. A Soft token=0 login failure means you need to log in by hand again.

Status: verified. Source: [interactivebrokers.com](https://www.interactivebrokers.com/docs/tws-api/doc/tws-settings/daily-weekly-reauthentication), checked 2026-09-18.

### 4. IBC automates the login

IBC fills in credentials, handles TWS dialogs, restarts daily without re-authentication and can retry IBKR Mobile 2FA if you miss the alert. It runs on Windows, macOS and Linux under GPL 3. The repository was archived on 1 Sep 2026, so it is now read-only.

Status: verified. Source: [github.com](https://github.com/IbcAlpha/IBC), checked 2026-09-18.

### 5. Docker: ib-gateway-docker

The community gnzsnz/ib-gateway-docker image bundles IB Gateway, IBC, Xvfb, VNC and socat. It reads TWS_USERID and TWS_PASSWORD or TWS_PASSWORD_FILE (Docker secrets), with TRADING_MODE paper or live, READ_ONLY_API, TWOFA_TIMEOUT_ACTION and AUTO_RESTART_TIME. Its example compose file uses ghcr.io/gnzsnz/ib-gateway:stable, READ_ONLY_API yes or no, and binds the API ports to 127.0.0.1 only.

Status: verified. Source: [github.com](https://github.com/gnzsnz/ib-gateway-docker), checked 2026-09-18.

### 6. Client Portal Web API gateway

For the Web API, retail users run the Java Client Portal Gateway and must log in through a browser on the same machine; IBKR says API calls must also come from that machine, and that it does not support automating the login. 2FA is required for all IBKR users. This site held Java 8 update 192 or later as the minimum: the pages read on 12 October 2026 ask only for a working Java, so that version is not repeated as current.

Status: verified. Source: [interactivebrokers.com](https://www.interactivebrokers.com/docs/web-api/authentication/cpgw/limitations-of-the-client-portal-gateway), checked 2026-09-18.

### 7. Web API sessions drop at midnight

IBKR says Web API clients see disconnects at midnight in their connecting region. Call /tickle about every 60 seconds to keep a session alive, and remember one brokerage session per username across TWS, Client Portal and mobile.

Status: verified. Source: [interactivebrokers.com](https://www.interactivebrokers.com/docs/web-api/v1/regular-server-maintenance), checked 2026-09-18.

### 8. IBeam for headless Web API logins

The community IBeam tool injects credentials into the Client Portal Gateway and keeps it running without a display, as the voyz/ibeam Docker image. Its README warns that storing credentials is a security risk and suggests paper credentials.

Status: verified. Source: [github.com](https://github.com/Voyz/ibeam), checked 2026-09-18.

### 9. Keep it on paper and read only first

Every tool above needs your IBKR password somewhere on disk. Start with paper credentials, keep the API port on localhost, and leave Read-Only API on until you have watched the setup survive a restart.

Status: verified. Source: [github.com](https://github.com/gnzsnz/ib-gateway-docker), checked 2026-09-18.

## Sources

- Status: verified. Source: [IBKR TWS API documentation, the IB Gateway](https://www.interactivebrokers.com/docs/tws-api/doc/architecture/the-trader-workstation/the-ib-gateway), checked 2026-10-12.
- Status: verified. Source: [IBKR Web API documentation, limitations of the Client Portal Gateway](https://www.interactivebrokers.com/docs/web-api/authentication/cpgw/limitations-of-the-client-portal-gateway), checked 2026-10-12.
- Status: verified. Source: [GitHub: IbcAlpha/IBC](https://github.com/IbcAlpha/IBC), checked 2026-09-18.
- Status: verified. Source: [GitHub: gnzsnz/ib-gateway-docker (community)](https://github.com/gnzsnz/ib-gateway-docker), checked 2026-09-18.
- Status: verified. Source: [GitHub: Voyz/ibeam (community)](https://github.com/Voyz/ibeam), checked 2026-09-18.
- Status: verified. Source: [IBKR TWS API documentation, daily and weekly reauthentication](https://www.interactivebrokers.com/docs/tws-api/doc/tws-settings/daily-weekly-reauthentication), checked 2026-10-12.
- Status: verified. Source: [IBKR Web API v1.0 documentation, regular server maintenance](https://www.interactivebrokers.com/docs/web-api/v1/regular-server-maintenance), checked 2026-10-12.
- Status: verified. Source: [IBKR Web API v1.0 documentation, supported two factor authentication](https://www.interactivebrokers.com/docs/web-api/v1/requirements-limitations/supported-two-factor-authentication-2-fa), checked 2026-10-12.
- Status: verified. Source: [IBKR Web API v1.0 documentation, ping the server](https://www.interactivebrokers.com/docs/web-api/v1/endpoints/session/ping-the-server), checked 2026-10-12.
- Status: verified. Source: [IBKR Web API documentation, managing multiple sessions](https://www.interactivebrokers.com/docs/web-api/authentication/multiple-sessions), checked 2026-10-12.
- Status: verified. Source: [TWS API guide: initial setup (legacy docs)](https://interactivebrokers.github.io/tws-api/initial_setup.html), checked 2026-10-12.

## More on the Interactive Brokers API

- [Interactive Brokers API quickstart](https://openbrokerapi.com/brokers/ibkr/quickstart): From credentials to a first call on a demo account, step by step.
- [Interactive Brokers API error codes](https://openbrokerapi.com/errors/ibkr): 511 decoded, each with what it means, and the fix where the source gives one.
- [Interactive Brokers API endpoints](https://openbrokerapi.com/brokers/ibkr/endpoints): 23 documented, each with its method, path, parameters and source.
- [Interactive Brokers API page](https://openbrokerapi.com/brokers/ibkr): The full record: access, authentication, limits and the source for each.
- [Get your Interactive Brokers trade history into a spreadsheet](https://openbrokerapi.com/guides/ibkr-trade-history): Guide
- [The three Interactive Brokers REST front doors compared](https://openbrokerapi.com/guides/ibkr-rest-front-doors): Guide
- [Interactive Brokers MCP servers, compared](https://openbrokerapi.com/guides/interactive-brokers-mcp-servers): Guide

## Licence and how to cite

The records behind this page are all rights reserved. This file is the page itself, at its own address, in another format. It is not part of the CC BY 4.0 downloads listed at https://openbrokerapi.com/data. Quote from it with a link to the page.

Cite as: IBKR API without TWS: headless IB Gateway options. Broker API Hub, https://openbrokerapi.com/guides/ibkr-headless-gateway, newest check 2026-09-18.

Where you rely on a single figure, cite the source and the checked date printed beside it as well. Where this page and a broker's own documentation differ, the documentation wins.
