TL;DR: An IB Gateway Docker container fails in silence, because IBKR’s login needs a person and a container hides the screen that said so. This open-source project keeps the person and ends the silence: one command builds the image on your own machine from IBKR’s own download in about 7 to 9 minutes, the container never automates the second factor and never re-sends a password that IBKR rejected, and an optional sidecar tells a phone when a person is needed; of the eight open-source IBKR gateway containers we read on 18 November 2026, it is the only one in which we found a built-in notifier that sends a message to a person. It is a public preview under permanent development: the build is tested, paper logins passed with the project’s earlier images, and no image built this way has logged in yet.
Status: public preview. The build is tested on Windows and on Linux CI. Logins were tested on an IBKR paper account with the project’s earlier images (IB Gateway 10.50.1g and 10.52.1d); not yet with an image you build, and not on a live account. This is engineering software, not investment advice and not a managed trading service.
| At a glance | |
|---|---|
| Repository | RocketEdge/brokersre-ib-gateway, MIT, derived from gnzsnz/ib-gateway-docker (MIT) |
| What you run | scripts/build-image.sh, or scripts/build-image.ps1 on Windows |
| First build | About 7 to 9 minutes on a 20-core machine; about 6 GB of free disk |
| Runs on | One 2 vCPU / 4 GiB VM: USD 24 to 41 a month |
| Also in this post | A 113-line Python strategy that runs next to the gateway, and why its logs go to Azure Log Analytics |
| Status | Public preview, under permanent development |

Picture your trading algo at 03:00. It waits for one tap on a phone. The phone lies face down on a bedside table, because nothing told it.
If you are the trader and not the engineer, two words are enough. A container is a sealed box of software: here it holds IB Gateway, the IBKR program that your algo trades through, and runs it on a server with no screen. Docker is the tool that runs the box. The first three sections need nothing more; the 25 steps are for whoever looks after your machine.
Most advice on this problem tries to remove the person. This post argues the opposite. The goal of an unattended gateway is not to remove the person; it is to know the minute a person is needed, and to say so.
The project behind it ships a recipe, not an image. Every other active project that we read publishes a ready-made image; this one gives you one script. The image contains IB Gateway, which is software of Interactive Brokers (IBKR), and RocketEdge decided not to distribute it. In the README’s words: “When you build, your machine downloads IB Gateway from IBKR itself, under your own agreement with IBKR, and the image stays with you.”
This post is the full walkthrough: 25 steps, every command, every output, and the date each one ran. It includes a small Python trading strategy that runs next to the gateway, and the reason to send the gateway’s logs to Azure Log Analytics.
Why does an IB Gateway Docker container fail when nobody is watching?
It fails because IBKR built the Gateway for a person at a screen, and a container removes the screen.
Three terms first. IB Gateway is IBKR’s lighter alternative to Trader Workstation: a Java program that a trading strategy connects to. The TWS API is the socket protocol that the strategy speaks, for example ib_async connecting to 127.0.0.1:4002. IBC is the open-source controller that types the username and password into the Gateway’s login window, so that no person has to.
The field reports are public, and they look alike:
- A
socaterror that returns on the first morning of every trading week, cured each time by a manual restart of the container (gnzsnz issue 119). - The API port accepts TCP connections but never answers, with sockets stuck in
CLOSE_WAIT“until the container is restarted” (gnzsnz issue 336). - “Weekly 2FA restart silently skipped … permanent brokerage disconnect with no recovery”. The algorithm ran for days while every order was rejected (LEAN IB issue 246).
None of this is a Docker defect. It is documented behaviour:
- Daily restart. “Both TWS and IBGW were designed to be restarted daily” (IBKR).
- Weekly login by a person. “This procedure will require manual authentication once a week” and “This security process occurs each Sunday at 1:00 am ET” (IBKR). That login includes the second factor (2FA): a second proof after the password, for example an approval in the IBKR Mobile app.
- One session per username. “It is not possible to login to multiple trading applications simultaneously with the same username” (IBKR).
- Daily server resets. The North America window is 00:15 to 01:45 ET (IBKR system status).
Two more facts sit upstream of every container. IBKR serves the Linux installer at an address without a version, one build per channel, and replaces it without notice. On 16 November 2026 the stable channel moved from 10.50.1g to 10.50.1h, and a build pinned to the old installer’s checksum failed the next morning. And IBC, which most Gateway containers rely on, was retired on 1 September 2026 after 23 years, counting its predecessor; its repository is archived (IbcAlpha/IBC).
What people say the cause is, and what it is
| Stated cause | Verdict | Why |
|---|---|---|
| “IB Gateway is flaky” | Fails | It does what IBKR documents: daily restart, weekly manual login, one session per username |
| “We need a bigger VPS” | Fails | A logged-in paper Gateway used 459 to 494 MB of memory (its working set) in our short sessions (earlier image, 10.50.1g). A larger machine does not answer a login prompt |
| “We need more automation” | Fails | Automating the second factor removes its value. A restart loop that re-sends a rejected password locks the account |
| “The container hides the screen” | Holds | The screen was the only interface that told a person they were needed. The container removed it and put nothing in its place |
| “Upstream moves under us” | Holds | IBKR replaces builds without notice; IBC is retired |
The fourth row is the real cause. The screen had a job. The container removed the screen and left the job undone.
Time-to-human: the number nobody measures
Time-to-human is the time between the moment the gateway needs a person and the moment that person knows. Example (illustrative): your gateway restarts on Sunday at 23:45 ET and IBKR asks for the second factor. The prompt expires after about three minutes and is asked again, all night. Your engineer learns of it at 09:25 the next morning, from a strategy that cannot connect: a time-to-human of 9 hours 40 minutes.
In an earlier post we argued that IB Gateway reliability is time-to-truth, not uptime. Time-to-human is its sibling.
Uptime asks whether the socket is open. Time-to-truth asks how long you were wrong. Time-to-human asks how long the machine waited for you in silence.
The whole argument fits in three lines:
- Premise. IBKR requires a person once a week, and after every restart outside the daily one.
- Premise. A container hides the only interface that told that person.
- Conclusion. The engineering problem is not to remove the person. It is to cut time-to-human to seconds, and never to make the wait worse.
What did a 1924 loom get right that most gateway containers get wrong?
It stopped itself and called a person. In 1924 Sakichi Toyoda completed the Type G automatic loom, which stopped by itself when a thread broke (Toyota Industries). Before it, looms needed an operator’s constant attention, because nobody knew when a thread would break (Toyota, Integrated Report 2024). Toyota named the principle jidoka, “automation with a human touch”: when the machine stops, a board called the andon lights up, and “people need only respond when there is an abnormality” (Toyota).
The loom did not get rid of the weaver. It got rid of the watching.
The opposite case is Knight Capital on 1 August 2012. From about 8:01 a.m. ET an internal system sent 97 automated e-mails that named the fault, all before the 9:30 open. The SEC’s order says Knight “did not design these types of messages to be system alerts, and Knight personnel generally did not review them” (SEC order). In the first 45 minutes of trading the router sent more than 4 million orders to fill 212 customer orders, and the firm lost more than USD 460 million (SEC).
The machine knew. The people did not. For those 97 messages, time-to-human never ended: the SEC found that they were not acted upon before the open and were not used to diagnose the problem after it.
Where these analogies break down. A broken thread is a binary fact; a gateway has states that are harder to read, such as an API port that accepts connections and never answers. Knight was a broker-dealer’s order router after a failed code deployment, a different class of system from a small fund’s gateway. The shared point is narrow: a signal that does not reach a person as an alert is not a signal.
Why now: the forces behind the problem
- Secular: small teams run their own code. This post is written for a fund, prop group or family office of 1 to 20 people that runs its own strategies with
ib_async, IBKR’s official client libraries, or a framework such as LEAN or NautilusTrader, with no operations desk behind it. - Secular: the consumer of status is a machine. A strategy or an AI agent cannot look at a remote-desktop (VNC) screen. As we argued in Agentic Trading in 2026, adaptation loops need truthful inputs; the gateway’s state is the first of them.
- Secular: broker security only tightens. “Two Factor Authentication (2FA) is required for all users at Interactive Brokers” (IBKR). A design that depends on avoiding it works against the broker’s direction.
- Secular: the one-maintainer era of this stack ended. IBC’s retirement moved a 23-year dependency from “maintained” to “your problem”.
- Cyclical: IBKR’s release rhythm. The
stablebuilds of 9 and 16 November 2026 are one week apart. Each new build breaks every checksum that was pinned to the one before.
What does this container do differently?
It applies jidoka to a gateway, in three verbs: Stop, Signal, Show. Four mental models carry the design. Each is named where it applies.
Stop: refuse to make things worse
Inversion asks what would guarantee failure. For a gateway the list is short: answer the second factor with a script, re-send a rejected password in a loop, restart on every unhealthy reading. The container does none of them.
- The second factor is never automated. This is Chesterton’s fence: do not remove a fence until you know why it stands. IBC’s author gave the reason: “if 2FA is automated, it has no value” (IBC discussion 352).
- A rejected password is not sent again. After IBKR rejects the credentials, later starts with the same secret files do not log in until a file is rewritten. We call this the rejected-login latch. It is second-order thinking: the first-order fix for a failed login is a retry; the second-order effect of retries is a locked account.
- A prompt limit, if you want one.
TWOFA_MAX_PROMPTSstops re-prompting after N unanswered prompts and waits in the phaseneeds-human. - A preflight named
doctor. It checks 13 settings before anything reaches IBKR. Example: a daily restart time inside IBKR’s reset window fails the check, with the fix in the message.
The limits are written down. The latch needs the persistent log volume of the reference compose file (the Docker Compose file that describes how the container runs), and a file rewritten with the same wrong password gets one more attempt. The prompt limit recognises a prompt from the text in IBC’s source code; no real prompt has been seen yet.
Signal: tell a machine, then tell a person
A Docker HEALTHCHECK is a command that Docker runs inside the container, here every 15 seconds, to label it healthy or unhealthy. This one is healthy only when the Gateway process is alive and the API port accepts a connection. A pending second factor is honestly unhealthy, and nothing restarts the container because of it.
The finer state is one word in a file, /var/log/ibgateway/state/phase:
| Phase | What it means | What to do |
|---|---|---|
starting, login | Starting up, logging in | Wait |
2fa-pending | IBKR waits for a second factor | Approve it in IBKR Mobile |
logged-in | Login completed, API available | Nothing |
restarting | The daily restart | Wait; clients retry |
existing-session | The username is logged in elsewhere | Close the other session |
needs-human | Nothing will change until a person acts | Fix the cause, then restart the container |
Three more signals complete the picture:
- Structured events. Every event is one JSON object on one line, on stdout and on a shared log volume. Example:
{"event":"container_start", ... "seq":1}; theseqcounter has no gaps, so a reader knows that it lost nothing. - A relay that follows the login. The relay is a small forwarder (
socat) between your strategy and the Gateway’s API port. It listens only while the Gateway is logged in, so “connection refused” always means “not logged in yet: retry”. It never means a connection that is accepted and then dropped. - An optional sidecar for people. A sidecar is a second, small container that watches the first. This one reads the log volume read-only, probes the API with a read-only time request, serves
/livez,/readyz,/statusand/metricson port 9810, and sends a message through Teams, Slack, Telegram, ntfy, PagerDuty, e-mail or a webhook when a person is needed. It alerts and never acts: no orders, no automated second factor, no restart of the gateway.
Two details matter. A dead-man ping covers the case where the host itself dies: the sidecar fetches a URL every 60 seconds, and an outside service raises the alarm when the fetches stop. And every alert links a one-page runbook, the step-by-step instruction for that alert; there are 16.
Map versus territory governs the whole design: healthy is a map, the session at IBKR is the territory. So the sidecar never reports a value it did not measure as a failure or as a success. It reports not_measured.
Show: prove what is inside, and what is not proven
- You build it from IBKR’s own download. The script accepts the installer only when it matches the repository’s pinned SHA-256 or IBKR’s own announced build. A SHA-256 is a fingerprint of a file: change one byte and the 64-character value changes.
- The image says what it holds. The IB Gateway version, IBKR’s build stamp (for example
(.1h) 20261116 16:02:08) and the installer’s SHA-256 are written into the image’s labels. - Least privilege by default. The container runs as uid 1000, an ordinary user, with no
sudo(the command that grants administrator rights), a read-only root file system and all Linux capabilities dropped. Credentials enter only as files, are rendered to memory-backed storage with mode 0600, and are removed from the environment before any child process starts. In our Mythos post we argued that cheap vulnerability discovery makes least privilege the baseline; this is that argument in a Dockerfile. - The unproven is listed.
docs/limitations.mdholds 40 numbered limitations.docs/evidence.mdmaps the usual operational due-diligence questions to the artefact and the command that answer each.
One honest qualifier belongs here. IBKR’s bundled libraries carry known CVEs, publicly listed vulnerabilities, that no image can patch. The project’s statement on each is published as an OpenVEX file, a machine-readable format that a scanner such as Trivy reads.
How is it better than every other IB Gateway container we read?
For a fund of 1 to 20 people that runs its own strategy code on the TWS API and keeps the second factor in a person’s hand, this is the strongest open-source starting point we know of. That is a scoped claim, and the evidence follows row by row. We read eight projects on 18 November 2026: this one, gnzsnz/ib-gateway-docker, UnusualAlpha/ib-gateway-docker, extrange/ibkr-docker, manhinhang/ib-gateway-docker, IBGA, ibg-controller and IBeam.
Seven things you get here and nowhere else together
- A message to a person. We searched the other seven repositories for Slack, Teams, Telegram, PagerDuty, ntfy, webhook and SMTP, and found none. The closest is ibg-controller, which writes
ALERT_*lines to its log for a monitor that you wire up yourself. - A health check in the image. The incumbent, gnzsnz, has no
HEALTHCHECKin its Dockerfile. Neither have extrange, IBGA and UnusualAlpha. - The second factor stays human, and the human gets told. IBGA, ibg-controller and IBeam automate TOTP on purpose. gnzsnz and extrange leave the prompt to a person and ship no notifier to say that it is waiting.
- A rejected password stays rejected across restarts. The latch survives a container restart. gnzsnz and extrange have no such stop.
- A preflight before any login.
doctorruns 13 checks and names each fix. We found no equivalent command in the other seven. - No
sudo, no root. gnzsnz and IBGA give the container user passwordlesssudoin their Dockerfiles. extrange runs as root. - An image you can account for. Every input is checked on your machine, and the labels record the result. You do not have to trust a published gateway image, because there is none.
Running unattended: the capabilities that decide whether you find out
| Capability | This project | gnzsnz | ibg-controller | extrange | IBeam |
|---|---|---|---|---|---|
Docker HEALTHCHECK in the image | Yes: process alive and API port accepting | No | Yes: asks its controller’s /health | No | No; its own /livez and /readyz server |
| Built-in notifier for people | Yes, optional sidecar: 7 channels, dead-man ping, 16 runbooks | None found | ALERT_* log lines for your own monitor | None found | None found; it can re-send IBKR’s own 2FA notification |
| Second factor | Never automated; optional prompt limit | Never automated | Automates TOTP when given the secret; IB Key waits for you | Never automated | Can be automated with TOTP |
| After IBKR rejects the password | Stops; stays stopped across restarts until a secret file changes | No latch | Halts in place | No latch | Stops after a set number of failed attempts |
| Preflight before any login | Yes: doctor, 13 checks | None found | Validates some settings at start | None found | None found |
| Privileges | uid 1000, no sudo, read-only root, all capabilities dropped | uid 1000 with passwordless sudo | uid 1000, on gnzsnz’s base image | Root | Non-root user |
Supply chain and scope
| This project | gnzsnz | ibg-controller | extrange | IBeam | |
|---|---|---|---|---|---|
| API it serves | TWS socket API | TWS socket API | TWS socket API | TWS socket API | Client Portal Web API |
| Licence | MIT | MIT | MIT | None published | Apache-2.0 |
| How you get the image | You build it: one script, about 7 to 9 minutes the first time | Prebuilt, GHCR and Docker Hub | Prebuilt, GHCR, on top of gnzsnz’s image | Prebuilt, GHCR | Prebuilt, Docker Hub |
| Build inputs checked | Base image and IBC by SHA-256; the Gateway by the pinned SHA-256, or by IBKR’s own build stamp when IBKR has moved on | Gateway yes, IBC no | Base image pinned by digest | Gateway yes, noVNC unpinned | Not verified |
| Signature and SBOM | None on your build; its labels carry the Gateway version, IBKR’s build stamp and the installer’s SHA-256 | No / no | cosign-signed, with an SBOM | No signature; SBOM from BuildKit | No signature found; SBOM not verified |
| Login controller | IBC 3.24.2: retired upstream, re-released by RocketEdge without code changes | IBC | Its own controller, in place of IBC | IBC | Its own (different API) |
| Platforms | amd64; arm64 builds, no arm64 login yet | amd64 and arm64 | amd64 and arm64 | amd64 only | amd64 and arm64 |
| TWS desktop image | No | Yes | Not verified | Yes | No |
| Real-login check | By hand, on paper, with the project’s earlier images; not yet with a self-built image | None | Its README says a release waits for one | A CI job exists; skipped or cancelled in all 15 runs checked | Not verified |
Sources: each project’s default branch on 18 November 2026: gnzsnz/ib-gateway-docker, ibg-controller, extrange/ibkr-docker and Voyz/IBeam. The extrange CI runs were checked for 31 October to 12 November 2026.
Two projects are outside the table. manhinhang/ib-gateway-docker is a small image without VNC, with an HTTP health check that you switch on. IBGA automates TOTP with its own scripts.
Four terms in these tables: TOTP is a time-based one-time password, the six-digit code that an authenticator app shows. cosign signs a container image so that a reader can check who built it. An SBOM is a software bill of materials, the list of every component inside an image. GHCR is GitHub’s container registry.
Where the alternatives are the better choice
A comparison that only wins is an advertisement. Here is where this project loses.
- You want an image in seconds. Pull gnzsnz. It is the community’s incumbent (1,311 stars and 112,267 Docker Hub pulls on 18 November 2026), and this project is derived from it. Building costs minutes and disk.
- You need the TWS desktop in a container. gnzsnz and extrange ship one. This project removed it.
- You want a signed image and an SBOM out of the box, or a login controller under active development. ibg-controller ships both. This project runs a re-release of the retired IBC; that is a single point of failure, and the repository says so in its architecture decision record (ADR) 0015.
- Your strategy speaks the Client Portal Web API. That is IBeam’s API, and IBeam is the right tool for it.
- You want a platform, not a gateway. QuantConnect bundles data, backtesting and hosting; its Researcher pack lists at USD 84 a month.
- You qualify for IBKR’s first-party OAuth. OAuth lets a program authenticate itself with keys, and IBKR lists it for institutional account types such as advisor, proprietary trading group and hedge fund accounts (IBKR). Then the Web API needs no gateway software at all, at the price of moving from the TWS socket API to REST.
How do you build the IB Gateway Docker image yourself?
You clone the repository and run one script. Steps 1 to 9 need no IBKR login and no credential, so you can do them today. Outputs marked 17 November 2026 ran from a clean clone at commit 7841934 on Windows 11 with Docker Desktop (Engine 29.9.3, Compose v5.7.0, buildx v0.38.1), in Git Bash and PowerShell 7.6. Lines cut from an output are marked ...; nothing was added.
Step 1: Check what you need
- Docker with buildx: Docker Desktop, or Docker Engine 23 or later with the buildx plugin. buildx is Docker’s current build engine front end.
git, about 6 GB of free disk, and a connection todownload2.interactivebrokers.com, Docker Hub and GitHub.- Nothing else. Finding, downloading and checking IBKR’s installer run in a small helper container that the script builds first.
Tested hosts: Windows 11 with Docker Desktop (Git Bash, PowerShell 7 and Windows PowerShell 5.1), and GitHub’s Ubuntu runner in the project’s CI. Not tested yet: macOS, an arm64 Linux host, WSL.
Step 2: Clone the repository
git clone https://github.com/RocketEdge/brokersre-ib-gateway.git
cd brokersre-ib-gateway
Step 3: Ask what a build would do, without building
Linux, macOS, WSL or Git Bash:
scripts/build-image.sh --print-plan
PowerShell 7, or Windows PowerShell 5.1 (the second form):
pwsh -NoProfile -File scripts/build-image.ps1 -PrintPlan
Output, 17 November 2026 (6 seconds; an empty installer cache):
version: 10.50.1h
channel: stable
arch: x64
pinned_version: 10.50.1g
pinned: no
qualified_by_project: no
ibkr_build_stamp: (.1h) 20261116 16:02:08
installer_sha256: unknown
source: ibkr
installer_source: ibkr
cache_hit: no
ibkr_reachable: yes
platform: linux/amd64
image: brokersre-ib-gateway:stable
Read it as: on 17 November IBKR served 10.50.1h, and the repository pinned 10.50.1g. Nothing was downloaded or built.
Step 4: Build
Linux, macOS, WSL or Git Bash:
scripts/build-image.sh
PowerShell 7, or Windows PowerShell 5.1 (the second form):
pwsh -NoProfile -File scripts/build-image.ps1
powershell -NoProfile -ExecutionPolicy Bypass -File scripts\build-image.ps1
Output of the first build, 17 November 2026 (Git Bash, nothing cached, exit 0):
resolve-installer: downloading https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh
build-image: building brokersre-ib-gateway:stable: IB Gateway 10.50.1h (stable) for linux/amd64
...
== IBC smoke (offline, --network none, hardened: read-only root, no capabilities) ==
PASS IBC command server listening on 7462 within 180s
PASS IBC/Gateway Java process running
...
PASS healthcheck honestly unhealthy before login
PASS SIGTERM stops the container (IBC STOP path)
PASS shutdown_complete event emitted
ALL CONTAINER TESTS PASSED
resolve-installer: cached 10.50.1h (x64) in /cache/installers/10.50.1h/x64/eb578b23b636e19c8417fc969264853a22792bcffa8fc79990cf15ff032fe7aa
WARNING: IB Gateway 10.50.1h (stable) is not qualified by this project.
versions.json pins 10.50.1g; this image holds 10.50.1h, build stamp (.1h) 20261116 16:02:08.
The installer was checked against IBKR's own build stamp and the offline tests ran, but no
login has been made with this Gateway build. To qualify it, make one login to a paper
account of your own (README, "Qualifying an image with a real paper login"):
scripts/qualify-paper.sh --image brokersre-ib-gateway:stable --secrets-dir <dir>
version: 10.50.1h
channel: stable
qualified_by_project: no
installer_sha256: eb578b23b636e19c8417fc969264853a22792bcffa8fc79990cf15ff032fe7aa
ibkr_build_stamp: (.1h) 20261116 16:02:08
image: brokersre-ib-gateway:stable
image_id: sha256:60c05b9da5b21f79ddd92705708eeabdef50235395968ba09521bd8e6f524cc3
How long it takes. Plan about 7 to 9 minutes the first time and 1 to 3 minutes for a rebuild, on a 20-core machine in Singapore. A small VM is slower; we did not measure one.
| Build | Measured, 17 November 2026 | Conditions |
|---|---|---|
| First build, nothing cached | 6 min 58 s | An empty buildx builder and an empty installer cache; 2 min 27 s of it built the helper image and downloaded IBKR’s 360,312,436-byte installer |
| Rebuild, both caches warm | 2 min 35 s | The same builder |
| Rebuild from PowerShell 7 | 2 min 1 s | Docker Desktop’s default builder |
| The project’s CI, GitHub’s Ubuntu runner | 1 min 36 s | Download and IBC test included |
Step 5: Read the seven last lines
| Line | Meaning |
|---|---|
version | The IB Gateway build in the image, as IBKR names it |
channel | IBKR’s channel: stable or latest. “latest” is IBKR’s channel name, not Docker’s moving tag |
qualified_by_project | yes: the version and the installer’s SHA-256 equal the repository’s pin, which passed the project’s offline CI. no: IBKR serves another build than the pin |
installer_sha256 | The fingerprint of the installer the image was built from |
ibkr_build_stamp | IBKR’s build stamp; the installed Gateway carries exactly this stamp, or the build fails |
image | The first tag of the image |
image_id | Docker’s id of the image you built |
qualified_by_project: no is not an error. IBKR had moved to 10.50.1h while the repository pinned 10.50.1g. The script built it because IBKR’s version.json named the same build before and after the download, and the installer and the installed Gateway carried IBKR’s stamp.
That proves the bytes are the build IBKR announced. It does not prove that this Gateway logs in.
You have three ways on, in the README’s order:
- Qualify the image with one login to a paper account of your own:
scripts/qualify-paper.sh --image brokersre-ib-gateway:10.50.1h --secrets-dir <dir>. - Wait for the repository to pin the new build, then build again.
- Refuse such builds with
--strict, which exits with status 4.
qualified_by_project: yes does not mean that a login happened either. Make one paper login with the very image before you go live, whatever the line says.
Later on 17 November 2026, at 20:57 UTC, the repository moved its pin to 10.50.1h. A clean clone now pins the build that IBKR serves, so by the rule in the table your build prints qualified_by_project: yes. We did not run the build again after that change; the outputs above stay as they ran.
Step 6: Verify what you built
Three independent records must agree: the image’s labels, the installer in the cache, and the stamp inside the installed Gateway.
docker image inspect brokersre-ib-gateway:stable --format '{{json .Config.Labels}}'
{"com.rocketedge.brokersre.ibc.release":"3.24.2-rocketedge.1","com.rocketedge.brokersre.ibc.version":"3.24.2","com.rocketedge.brokersre.ibkr.build_stamp":"(.1h) 20261116 16:02:08","com.rocketedge.brokersre.ibkr.channel":"stable","com.rocketedge.brokersre.ibkr.version":"10.50.1h","com.rocketedge.brokersre.installer.sha256":"eb578b23b636e19c8417fc969264853a22792bcffa8fc79990cf15ff032fe7aa","com.rocketedge.brokersre.installer.source":"ibkr","com.rocketedge.brokersre.qualified":"no",...}
sha256sum ~/.cache/brokersre-ib-gateway/installers/10.50.1h/x64/*/ibgateway-10.50.1h-standalone-linux-x64.sh
curl -fsS https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/version.json
docker run --rm --entrypoint cat brokersre-ib-gateway:stable //home/ibgateway/Jts/ibgateway/10.50.1h/.install4j/i4jparams.conf | grep -o 'applicationVersion="[^"]*"'
Output, 17 November 2026:
eb578b23b636e19c8417fc969264853a22792bcffa8fc79990cf15ff032fe7aa *~/.cache/brokersre-ib-gateway/installers/10.50.1h/x64/eb578b23b636e19c8417fc969264853a22792bcffa8fc79990cf15ff032fe7aa/ibgateway-10.50.1h-standalone-linux-x64.sh
ibgatewaystable_callback({"buildVersion":"10.50.1h","buildDateTime":"20261116 16:02:08"});
applicationVersion="(.1h) 20261116 16:02:08"
The label, the cached installer and the installed Gateway carry the same SHA-256 and the same stamp as IBKR’s announcement. (The log writes the home directory as ~; Git Bash on Windows prints the full path.)
A Docker image is a claim. A recipe that you run and check yourself is evidence.
To see later whether IBKR serves a newer Gateway than your image holds:
scripts/build-image.sh --print-plan | grep '^version:'
docker image inspect brokersre-ib-gateway:stable --format '{{index .Config.Labels "com.rocketedge.brokersre.ibkr.version"}}'
version: 10.50.1h
10.50.1h
The first line is what IBKR serves now, the second what your image holds. When they differ, a rebuild brings the new Gateway.
How do you start it without sending anything to IBKR?
You start it in test mode. IBC_LAUNCH=no starts everything except IBC and the Gateway, so nothing reaches IBKR. Do this before the first real login: it proves that the image starts on your machine with its volumes, ports and preflight.
Step 7: Store the two secrets as files
Use an IBKR username that nothing else uses; IBKR allows one session per username. Linux, macOS, WSL or Git Bash:
(
trap 'stty echo; exit 130' INT
mkdir -p compose/secrets
printf 'IBKR username: '; IFS= read -r u; printf '%s' "$u" > compose/secrets/ib-username
printf 'IBKR password: '; stty -echo; IFS= read -r p; stty echo; echo
printf '%s' "$p" > compose/secrets/ib-password
)
The parentheses are deliberate. The shell reads the whole block before it asks anything, so pasting works, and Ctrl-C at a prompt turns echo back on and writes no password file.
Windows (PowerShell 5.1 or 7):
New-Item -ItemType Directory -Force compose\secrets | Out-Null
$utf8 = New-Object System.Text.UTF8Encoding($false)
[IO.File]::WriteAllText("$PWD\compose\secrets\ib-username", (Read-Host 'IBKR username'), $utf8)
$secure = Read-Host 'IBKR password' -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try { [IO.File]::WriteAllText("$PWD\compose\secrets\ib-password", [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr), $utf8) }
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) }
On Windows do not use > or echo for this. Windows PowerShell 5.1 writes UTF-16 that way, and the gateway refuses such a file instead of sending IBKR a wrong password. The password never appears on screen in either block.
Step 8: Run the preflight
docker compose -f compose/docker-compose.example.yml run --rm ib-gateway doctor
Output, 17 November 2026 (exit 0 in 2 seconds):
...
STATUS CHECK DETAIL
PASS trading_mode TRADING_MODE=paper
PASS credentials username from TWS_USERID_FILE, password from TWS_PASSWORD_FILE
PASS secret_values no password is passed in a plain environment variable
PASS login_latch no rejected login is recorded for these credentials
PASS auto_restart_time AUTO_RESTART_TIME=11:45 PM
PASS restart_window AUTO_RESTART_TIME 11:45 PM (America/New_York) is outside IBKR's North America reset windows (00:15-01:45 daily, Saturday 00:00-02:00 ET)
PASS time_zone TIME_ZONE=America/New_York
PASS ignored_variables no ignored or unknown variable in the environment
PASS writable_dirs LOG_DIR, RUN_DIR, TWS_SETTINGS_PATH and the Java home are writable by uid 1000
PASS heap_vs_memory heap 768 MB (default) is 37% of the 2048 MB memory limit
PASS read_only_api READ_ONLY_API=yes: API clients cannot place orders
SKIP relay_exposure the container cannot see how the host publishes the relay port
fix: publish relay port 4004 on 127.0.0.1 or a private address only, never on 0.0.0.0 of a host the internet can reach
PASS disk_space LOG_DIR and TWS_SETTINGS_PATH: ...
doctor: pass (12 passed, 0 warned, 0 failed, 1 skipped)
One caution: doctor does not contact IBKR. The credentials check says that the files exist and are readable as UTF-8. It does not say that IBKR accepts them; this run passed with the dummy value x in both files.
Note the defaults in that output. The example starts in paper mode with the read-only API: API clients cannot place orders until you decide otherwise.
Step 9: Start it once without a login
IBC_LAUNCH=no docker compose -f compose/docker-compose.example.yml up -d
docker compose -f compose/docker-compose.example.yml exec ib-gateway cat //var/log/ibgateway/state/phase
docker compose -f compose/docker-compose.example.yml ps --format 'table {{.Service}}\t{{.Status}}\t{{.Ports}}'
docker compose -f compose/docker-compose.example.yml logs ib-gateway | grep container_start
Output, 17 November 2026:
test-mode
SERVICE STATUS PORTS
ib-gateway Up 7 seconds (healthy) 127.0.0.1:4001->4003/tcp, 127.0.0.1:4002->4004/tcp
ib-gateway-1 | {"ts":"2026-11-17T09:10:03.995Z","src":"entrypoint","level":"info","event":"container_start","msg":"brokersre-ib-gateway 10.50.1h (stable) IBC 3.24.2 starting as uid 1000","data":{"gateway_version":"10.50.1h","channel":"stable","ibc_version":"3.24.2","ibc_release":"3.24.2-rocketedge.1","trading_mode":"paper","instance":"default"},"boot_id":"956d0d7613774ce6","seq":1}
The two slashes in //var are deliberate. Git Bash on Windows rewrites an argument that starts with a single / into a Windows path; Linux, macOS and PowerShell read //var as /var.
What test mode proves, and what it does not. It proves that the image starts on your machine and that the secret files can be read. It does not touch IBKR, and its healthy means only that the relay listens. Nothing answers behind it, as this check shows (exit 1, no ready):
examples/wait-for-gateway.sh --host 127.0.0.1 --port 4002 --timeout 20 && echo ready
wait-for-gateway: waiting for 127.0.0.1:4002 to answer the TWS API handshake (timeout 20 s)
wait-for-gateway: not ready: 127.0.0.1:4002 closed the connection without answering the API handshake
wait-for-gateway: timeout after 20 s: 127.0.0.1:4002 closed the connection without answering the API handshake
Stop it before the real start:
docker compose -f compose/docker-compose.example.yml down
Read this before step 10. The compose file defaults to IBC_LAUNCH=yes. The same up -d without IBC_LAUNCH=no starts a real login to IBKR with whatever is in the credential files.
How do you log in on a paper account and connect a strategy?
You start the same compose file without IBC_LAUNCH=no, on a paper account first. A paper account is IBKR’s simulated account: real login, no real money.
From here on, the outputs come from our paper test of 16 November 2026, with the project’s earlier image of IB Gateway 10.50.1g, which the project built itself before it published the recipe. No image built with the recipe has logged in yet. Treat these outputs as what a login looked like then, not as the output of your build.
Step 10: Start it and follow the log
docker compose -f compose/docker-compose.example.yml up -d
docker compose -f compose/docker-compose.example.yml logs -f
In the paper test of 16 November 2026 (earlier image), the JSON events arrived in this order: container_start, doctor_ok, config_rendered, jts_ini_written, xvfb_started, vnc_disabled, socat_started, ibc_starting, ibc_version, login_dialog, login_completed, relay_opened. The relay opened 12 seconds after up -d. The paper account asked for no second factor.
If IBKR asks for a second factor, the event twofa_initiated appears and the phase becomes 2fa-pending. Approve the prompt in IBKR Mobile. The image never answers it for you.
Step 11: Check that it is logged in
docker compose -f compose/docker-compose.example.yml exec ib-gateway cat //var/log/ibgateway/state/phase
docker compose -f compose/docker-compose.example.yml ps --format 'table {{.Service}}\t{{.Status}}\t{{.Ports}}'
Output, 16 November 2026, earlier image:
logged-in
SERVICE STATUS PORTS
ib-gateway Up 12 seconds (healthy) 127.0.0.1:4001->4003/tcp, 127.0.0.1:4002->4004/tcp
The API is then reachable on 127.0.0.1:4002 (paper) or 127.0.0.1:4001 (live). While the phase is login or 2fa-pending, the container reports unhealthy on purpose.
Step 12: Wait until the API really answers
examples/wait-for-gateway.sh --host 127.0.0.1 --port 4002 --timeout 300 && echo ready
Output, 16 November 2026, earlier image:
wait-for-gateway: waiting for 127.0.0.1:4002 to answer the TWS API handshake (timeout 300 s)
wait-for-gateway: ready: 127.0.0.1:4002 answered the API handshake (server version 178) after 0 s
ready
Healthy is a moment, not a promise. Use this script as the entrypoint wrapper of your strategy, so that the strategy starts only when the API answers. Step 21 does exactly that.
Step 13: Connect the Python example client
cd examples/python
uv sync
uv run python resilient_client.py --host 127.0.0.1 --port 4002 --client-id 101 --interval 30
Output, 16 November 2026, earlier image:
2026-11-16 21:02:44,792Z INFO resilient_client: connected to 127.0.0.1:4002, client id 101
2026-11-16 21:02:44,794Z INFO resilient_client: IBKR server time 2026-11-16T21:02:44+00:00
2026-11-16 21:03:14,803Z INFO resilient_client: IBKR server time 2026-11-16T21:03:14+00:00
2026-11-16 21:03:44,814Z INFO resilient_client: IBKR server time 2026-11-16T21:03:44+00:00
...
It connected within a second and read the server time every 30 seconds for 29 minutes without a gap. The client is read-only: it holds no order, cancel or what-if call.
The part worth copying into your own strategy is its state machine for IBKR’s connectivity codes. Code 1100 means the Gateway lost its link to IBKR: stop sending and keep the connection. Code 1102 means the link is back with data intact: continue. Code 1101 means the link is back and data was lost: continue and subscribe again. An excerpt from examples/python/resilient_client.py:
CONNECTIVITY_LOST: Final = 1100
CONNECTIVITY_RESTORED_DATA_LOST: Final = 1101
CONNECTIVITY_RESTORED_DATA_KEPT: Final = 1102
# ... inside class GatewayState; the docstring is cut
def on_error(self, code: int, message: str) -> Action:
if self._readiness is Readiness.DISCONNECTED:
return Action.NONE
if code == CONNECTIVITY_LOST:
self._readiness = Readiness.CONNECTIVITY_LOST
return Action.PAUSE
if code == CONNECTIVITY_RESTORED_DATA_KEPT:
self._readiness = Readiness.READY
return Action.RESUME
if code == CONNECTIVITY_RESTORED_DATA_LOST:
self._readiness = Readiness.READY
return Action.RESUBSCRIBE
if code in FARM_BROKEN_CODES:
self._broken_farms.add(_farm_name(message, FARM_BROKEN_CODES[code]))
elif code in FARM_OK_CODES:
self._broken_farms.discard(_farm_name(message, FARM_OK_CODES[code]))
return Action.NONE
The status of this code is exact: the handling of 1100, 1101 and 1102 and of the daily restart is tested against stand-ins only. It has not been seen live yet.
Step 14: Run the gateway and a strategy in one compose file
docker compose -f examples/compose-with-client.yml up -d
docker compose -f examples/compose-with-client.yml logs --no-log-prefix strategy
Output, 16 November 2026, earlier image:
wait-for-gateway: waiting for ib-gateway:4004 to answer the TWS API handshake (timeout 600 s)
wait-for-gateway: ready: ib-gateway:4004 answered the API handshake (server version 178) after 0 s
strategy placeholder: the gateway is ready, replace this service with your strategy
The strategy starts after the gateway is healthy and then waits for the API. Nothing is published on the host. Steps 19 to 22 replace the placeholder with a small strategy that decides and, when you allow it, sends an order.
A C# client for .NET 10 is in examples/csharp; it needs IBKR’s own C# library, which you build from IBKR’s TWS API download.
How do you get the alert on your phone?
You add the optional sidecar and give it one notification channel. All commands in this section run in the compose/ folder. The sidecar image is public and contains no IBKR software; it is the only RocketEdge image that you pull. These runs used version 0.2.2.
The repository’s sidecar file is set up for Teams. Teams is outside the scope of this article, so this walkthrough uses ntfy, a simple push service with a phone app that subscribes to a topic.
Step 15: Point the alerts at ntfy
Save this override file as compose/ntfy.yml. It is not in the repository; this post introduces it.
services:
sidecar:
environment:
NOTIFY_TEAMS_URL_FILE: !reset null
NOTIFY_NTFY_URL_FILE: /run/secrets/notify-ntfy-url
secrets: !override
- notify-ntfy-url
secrets:
notify-ntfy-url:
file: ./secrets/notify-ntfy-url
printf '%s' 'https://ntfy.sh/<a long, random topic name>' > secrets/notify-ntfy-url
Anyone who knows a public ntfy topic can read it. Pick a name that nobody can guess, or use an access token (NOTIFY_NTFY_TOKEN_FILE) on a reserved topic. The messages carry no username, password or account number, but they do say what state the gateway is in.
What exactly was verified: this file passed docker compose ... config and check-config with an https URL. The messages below were delivered to a self-hosted ntfy server on the same compose network. The public ntfy.sh service was not used.
Step 16: Check the configuration and send a test message
These two commands never start the gateway. Keep --no-deps: without it, compose starts a gateway first, and that gateway logs in.
docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml run --rm --no-deps sidecar check-config
docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml run --rm --no-deps sidecar notify test
Output, 17 November 2026:
configuration ok
instance: default (paper)
network mode: own network namespace
probe: enabled, ib-gateway:4004, client id 999, every 60 s
reset windows: none (IBKR_REGION=none; API alerts are never held back)
endpoints: 0.0.0.0:9810
notifier: ntfy; escalation: ntfy
state directory: /var/lib/sidecar (writable)
dead-man ping: not configured (nobody is told when this sidecar or its host dies)
gateway log volume: /var/log/ibgateway (present)
...
ntfy: ok
The message that arrived (title, then body):
[INFO] default: Test notification
No action needed. This message confirms that this channel works.
Instance: default
Class: test
Severity: info
Phase: test-mode
API status: not_measured
Time (UTC): 2026-11-17T09:11:06.159Z
Time (local): 2026-11-17 04:11:06 EST (America/New_York)
Runbook: https://github.com/RocketEdge/brokersre-ib-gateway/tree/main/docs/runbooks
Read the dead-man ping: not configured line again. The sidecar tells you what it cannot tell you.
Step 17: Start the sidecar and ask it
This run kept the gateway in test mode. Without IBC_LAUNCH=no, this up -d starts a real login to IBKR.
IBC_LAUNCH=no docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml up -d
curl -s -w '\n[HTTP %{http_code}]\n' http://127.0.0.1:9810/readyz
curl -s http://127.0.0.1:9810/metrics | grep -E '^ibgw_(phase|api_ready|api_rtt_seconds|clock_offset_seconds|memory_working_set_bytes|sidecar_info)'
Output, 17 November 2026, gateway in test mode:
not_measured: gateway phase is test-mode; the API is probed only while it is logged-in
[HTTP 503]
ibgw_sidecar_info{version="0.2.2"} 1
ibgw_phase{phase="test-mode"} 1
ibgw_memory_working_set_bytes 18788352
This is the honest result for a gateway that is not logged in. The metric ibgw_api_ready is absent, not 0: an unmeasured value is never reported as a failure or as a success.
With a logged-in gateway (16 November 2026, earlier image), the same commands without -w, plus /status, returned:
ready
{"schema":"brokersre.sidecar.status.v1","generated_at":"2026-11-16T21:02:32.641Z","instance":"default","trading_mode":"paper","network_mode":"own_network","phase":"logged-in","phase_since":"2026-11-16T21:02:27.618Z","status":"ready","reason":"time round trip ok, connectivity up, no farm broken","status_since":"2026-11-16T21:02:29.452Z","connectivity":"ok","farms":[{"kind":"historical_data","name":"apachmds","condition":"ok"},{"kind":"market_data","name":"hfarm","condition":"ok"},{"kind":"sec_def","name":"secdefhk","condition":"ok"}],"last_probe":{"at":"2026-11-16T21:02:29.452Z","ok":true,"rtt_s":0.0013,"error":null,"consecutive_failures":0},...}
ibgw_sidecar_info{version="0.2.2"} 1
ibgw_phase{phase="logged-in"} 1
ibgw_api_ready 1
ibgw_api_rtt_seconds 0.0012847250000049826
...
In that run the phase was logged-in 16 seconds after up -d, and /readyz answered 200 one second later.
Step 18: Trigger an alert and its resolution
Stop the gateway on purpose and start it again. With a gateway that was created for a real login, the start logs in to IBKR again.
IBC_LAUNCH=no docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml stop ib-gateway
IBC_LAUNCH=no docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml start ib-gateway
The two messages that arrived, 17 November 2026, at 09:12:58 and 09:13:04 UTC:
[INFO] default: The gateway was stopped on request
No action needed if the stop was intended. The gateway stays down until someone starts it; a start needs a new login and two-factor approval.
Instance: default
Class: gateway_stopped
Severity: info
Phase: stopped
...
Runbook: https://github.com/RocketEdge/brokersre-ib-gateway/tree/main/docs/runbooks/gateway_stopped
[INFO] default: Resolved: The gateway was stopped on request
No action needed. The condition has cleared.
...
The stop command was issued at 09:12:56 UTC, and the first message reached the ntfy server at 09:12:58. For this alert class, in this one run, time-to-human was two seconds plus the push to the phone, which we did not measure. The same stop and start with a logged-in gateway (16 November 2026, earlier image) sent the same two messages 4 seconds apart.
What this article covers. In our tests, ntfy on a self-hosted server, a generic webhook and the dead-man ping were delivered end to end, to receivers that we ran ourselves. Teams, Slack, Telegram, PagerDuty and e-mail are outside the scope of this article; the sidecar’s README records the state of each channel. The alerts for a pending second factor (twofa_pending) and a rejected login (login_failed) use the same path but have not been triggered: the paper account asks for no second factor, and we did not provoke a rejected login on a real account.
For the dead-man ping, the sidecar’s README gives the pattern: create a check at a service that expects a regular ping, write its URL to secrets/deadman-ping-url, and set DEADMAN_PING_URL_FILE: /run/secrets/deadman-ping-url. Without it, nobody is told when the host itself dies.
How do you run a Python trading strategy next to the gateway?
You put it in a third container that starts only when the API answers. The gateway logs in, the sidecar tells a person, and the strategy trades. Steps 19 to 22 add that third part, in dry run first.
The whole setup, with the optional log shipper that a later section explains:

Read the figure by its seven numbered flows. The orange path is the alert and the human action; the dashed path is optional.
The example is the “hello world” of algorithmic trading: a moving-average crossover. A simple moving average (SMA) is the mean of the last N daily closing prices; the 20-day SMA of SPY is the mean of its last 20 closes. When the 20-day average is above the 50-day average, the strategy holds one share of SPY. Otherwise it holds none.
A teaching example, not a recommendation. We did not backtest it, and we claim no return for it. Its job is to show the wiring between a strategy and the gateway. Past performance is not indicative of future results.
The file has 113 lines, and the signal is seven of them. The other 106 are risk management and plumbing: wait, reconnect, pause, check the position, send one order at a time. That ratio is the lesson of the example.
It uses a fifth mental model, defence in depth: several independent locks, so that one mistake does not reach the market. Three locks stand between this code and an order, and you open each one with a deliberate act.
| Lock | Where it is | Default | What opens it |
|---|---|---|---|
| Dry run | The strategy | On: it logs the order and sends nothing | --place-orders, step 22 |
| Read-only API | The gateway, READ_ONLY_API | yes: API clients cannot place orders | READ_ONLY_API=no, step 22 |
| Paper account | The gateway, TRADING_MODE | paper | The going-live checklist, step 24 |
What is checked. The strategy passed 25 offline tests with the real ib_async 2.1.0 library against a stand-in gateway. We built its image and ran it with the limits of step 21 against the same stand-in. It has not connected to IBKR, so treat it as a starting point that you test on your own paper account.
Step 19: Write the strategy
Create a folder strategy in the repository root. Save the four parts below, in order, as strategy/sma_strategy.py. The file is not in the repository; this post introduces it.
Part 1 of 4: the signal and the order rule.
"""Teaching example, not a recommendation: a moving-average crossover, long or flat."""
import argparse
import asyncio
import contextlib
import logging
import random
import ib_async
LOG = logging.getLogger("sma_strategy")
FETCH = ib_async.StartupFetch.POSITIONS | ib_async.StartupFetch.ORDERS_OPEN
LOST, BACK = 1100, (1101, 1102) # the Gateway lost its link to IBKR; the link is back
def target_shares(closes: list[float], fast: int, slow: int, size: int) -> int | None:
"""Return the shares to hold, or None when there are too few bars to decide."""
if len(closes) < slow:
return None
fast_avg = sum(closes[-fast:]) / fast
slow_avg = sum(closes[-slow:]) / slow
return size if fast_avg > slow_avg else 0
def order_for(target: int, held: float, size: int) -> tuple[str, int] | None:
"""Return (action, quantity) that moves `held` to `target`, or None for no order."""
if held not in range(size + 1) or held == target: # not ours to touch, or nothing to do
return None
return ("BUY", target - int(held)) if target > held else ("SELL", int(held) - target)
target_shares is the whole signal. order_for is the first safety rule: if the account holds a SPY position that this strategy cannot have opened (more than --size shares, a short position or a fraction), it sends nothing and leaves that position to a person.
Part 2 of 4: one decision.
async def step(ib: ib_async.IB, args: argparse.Namespace) -> None:
"""One decision: read daily bars, compare with the position, send at most one order."""
contract = ib_async.Stock(args.symbol, "SMART", "USD")
bars = await ib.reqHistoricalDataAsync(
contract, endDateTime="", durationStr="6 M", barSizeSetting="1 day",
whatToShow="TRADES", useRTH=True, timeout=30,
)
if not bars:
raise TimeoutError(f"no bars for {args.symbol}")
closes = [bar.close for bar in bars[:-1]] # the newest bar can be unfinished
target = target_shares(closes, args.fast, args.slow, args.size)
held = sum(
p.position for p in ib.positions()
if p.contract.symbol == args.symbol and p.contract.secType == "STK"
)
busy = bool(ib.openTrades()) # one order at a time
order = None if target is None or busy else order_for(target, held, args.size)
LOG.info("bars=%d target=%s held=%s busy=%s order=%s", len(closes), target, held, busy, order)
if order is None:
return
if not args.place_orders:
LOG.info("dry run: would send %s %d %s at market", *order, args.symbol)
return
trade = ib.placeOrder(contract, ib_async.MarketOrder(*order))
LOG.info("sent %s %d %s at market: %s", *order, args.symbol, trade.orderStatus.status)
Each decision asks IBKR for six months of daily bars and drops the newest bar, because that bar can be unfinished. It takes the position from IBKR’s records and not from a variable of its own, so a reconnect does not make it buy twice. It sends at most one market order, and an open order blocks the next one.
The bars need market data on your IBKR username: “Streaming real time data or receiving historical bars from the API requires streaming level 1 market data subscriptions” (IBKR). The same page says that market data is attached to each username, so a paper username needs its own subscription or the data shared from the live username. Without it the request fails; IBKR’s list has code 162 for a historical-data error and code 354 for market data that is not subscribed (IBKR error codes). The strategy then logs the code, makes no decision, and asks again after a growing delay of at most about 30 seconds.
Part 3 of 4: the loop that copes with a gateway.
async def run(args: argparse.Namespace) -> None:
"""Connect, decide every `interval` seconds, and cope with what a gateway does."""
ib, attempt, paused = ib_async.IB(), 0, False
def on_error(_req_id: int, code: int, _text: str, _contract: object) -> None:
nonlocal paused
if code == LOST or code in BACK:
paused = code == LOST
LOG.warning("IBKR code %d: %s", code, "pausing" if paused else "continuing")
elif code in (162, 321, 354): # no market data for the symbol, or an order refused
LOG.warning("IBKR code %d", code)
ib.errorEvent -= ib._onError # ib_async's own 1102 handler opens a subscription per outage
ib.errorEvent += on_error
while True:
try:
if not ib.isConnected():
await ib.connectAsync(args.host, args.port, clientId=args.client_id, timeout=10,
readonly=not args.place_orders, fetchFields=FETCH)
LOG.info("connected to %s:%d", args.host, args.port)
paused = False
if not paused:
await step(ib, args)
except OSError as error: # refused, unanswered or closed: the gateway is not ready
ib.disconnect()
delay = min(30.0, 2.0**attempt) + random.random()
LOG.info("not ready (%s); next attempt in %.0f s", type(error).__name__, delay)
attempt += 1
else:
attempt, delay = 0, args.interval
await asyncio.sleep(delay)
This part is the reason for the example. It maps what a gateway does to what a strategy must do:
| What happens | What the strategy sees | What it does |
|---|---|---|
| The gateway is not logged in: a login, a pending second factor, the daily restart | The connection is refused or closes | Disconnects and tries again after about 1, 2, 4 and up to 30 seconds |
| The Gateway loses its link to IBKR | Code 1100 | Pauses: no request, no order; the connection stays |
| The link is back | Code 1101 or 1102 | Continues at the next interval |
| No bars arrive | An empty answer, with or without a code | Makes no decision and tries again |
| An order is open | An open trade | Sends nothing new |
| A position that is not its own | More than --size, short or fractional | Sends nothing |
One line needs a comment. ib.errorEvent -= ib._onError switches off the library’s own handler for code 1102, which opens one more account-summary subscription at every outage. It uses a private name of ib_async 2.1.0, so check it again when you upgrade the library.
Part 4 of 4: the options.
def main() -> None:
"""Parse the options and run until stopped."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", default="127.0.0.1")
parser.add_argument("--port", type=int, default=4002)
parser.add_argument("--client-id", type=int, default=201)
parser.add_argument("--symbol", default="SPY")
parser.add_argument("--fast", type=int, default=20, help="days in the fast average")
parser.add_argument("--slow", type=int, default=50, help="days in the slow average")
parser.add_argument("--size", type=int, default=1, help="shares to hold when long")
parser.add_argument("--interval", type=float, default=300, help="seconds between decisions")
parser.add_argument("--place-orders", action="store_true", help="send orders")
args = parser.parse_args()
if not 0 < args.fast < args.slow or args.size < 1:
parser.error("need 0 < --fast < --slow and --size of 1 or more")
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
logging.getLogger("ib_async").setLevel(logging.CRITICAL) # its messages can name an account
with contextlib.suppress(KeyboardInterrupt):
asyncio.run(run(args))
if __name__ == "__main__":
main()
The defaults are the safe ones: host 127.0.0.1, the paper port 4002, one share, a decision every 300 seconds, no orders. The client id 201 is its own on purpose: the example client of step 13 uses 101, and the sidecar’s probe uses 999. The line that sets the ib_async logger to CRITICAL keeps the library’s own messages, which can name an account, out of your log.
Step 20: Put the strategy in a container
Save this as strategy/Dockerfile:
FROM python:3.14-slim
RUN pip install --no-cache-dir ib_async==2.1.0
WORKDIR /app
COPY sma_strategy.py .
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
USER 1000:1000
CMD ["python", "sma_strategy.py"]
Build it from the repository root:
docker build -t sma-strategy:0.1 strategy
The image follows the gateway’s rules: an ordinary user, a pinned library version, nothing written at run time. On 17 November 2026 we built it from this file with Podman 5.7.0 on Linux, which gave Python 3.14.10 and ib_async 2.1.0. We did not build it with Docker.
Step 21: Start it next to the gateway and the sidecar
Save this as compose/strategy.yml:
services:
strategy:
image: sma-strategy:0.1
pull_policy: never # the image you built in step 20; never fetched
restart: unless-stopped
depends_on:
ib-gateway:
condition: service_healthy
# Start the strategy only when the API answers; wait up to 10 minutes.
entrypoint: ["/usr/local/bin/wait-for-gateway.sh", "--host", "ib-gateway", "--port", "4004", "--timeout", "600", "--"]
command: ["python", "sma_strategy.py", "--host", "ib-gateway", "--port", "4004"]
init: true
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
mem_limit: 256m
pids_limit: 256
volumes:
- ../examples/wait-for-gateway.sh:/usr/local/bin/wait-for-gateway.sh:ro
Then start all three from the compose/ folder. Without IBC_LAUNCH=no, this up -d starts a real login to IBKR.
docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml -f strategy.yml up -d
docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml -f strategy.yml logs --no-log-prefix strategy
Compose starts the strategy only after the gateway is healthy, and the wait script then holds it until the API answers. The repository’s own example says what happens when a second factor is still waiting: up stops with “dependency failed to start”; approve the prompt, then run up -d again.
Output, 17 November 2026 (UTC), from the image of step 20, run with the limits of this file against a stand-in gateway on the same host:
wait-for-gateway: waiting for 127.0.0.1:37465 to answer the TWS API handshake (timeout 600 s)
wait-for-gateway: ready: 127.0.0.1:37465 answered the API handshake (server version 178) after 0 s
2026-11-17 21:46:45,011 INFO connected to 127.0.0.1:37465
2026-11-17 21:46:45,012 INFO bars=124 target=1 held=0 busy=False order=('BUY', 1)
2026-11-17 21:46:45,012 INFO dry run: would send BUY 1 SPY at market
2026-11-17 21:46:47,016 INFO bars=124 target=1 held=0 busy=False order=('BUY', 1)
2026-11-17 21:46:47,016 INFO dry run: would send BUY 1 SPY at market
...
Read the status of this output exactly. The prices are made up, the interval was 2 seconds, and nothing went to IBKR. Docker Compose v5.8.0 accepted the four files with config; the up -d itself was not run. In your run the address is ib-gateway:4004.
Step 22: Open two locks, on the paper account only
Add --place-orders to the command in compose/strategy.yml:
command: ["python", "sma_strategy.py", "--host", "ib-gateway", "--port", "4004", "--place-orders"]
Then switch the read-only API off and start again:
READ_ONLY_API=no docker compose -f docker-compose.example.yml -f docker-compose.sidecar.yml -f ntfy.yml -f strategy.yml up -d
Compose re-creates the gateway container because its setting changed, so the gateway logs in again. Have the phone ready. To keep the setting, write READ_ONLY_API=no into compose/.env; without it, the next up -d turns the read-only API on again and re-creates the gateway once more.
Output of the same stand-in run with --place-orders, 17 November 2026 (UTC):
...
2026-11-17 21:47:05,864 INFO connected to 127.0.0.1:40029
2026-11-17 21:47:05,866 INFO bars=124 target=1 held=0 busy=False order=('BUY', 1)
2026-11-17 21:47:05,866 INFO sent BUY 1 SPY at market: PendingSubmit
2026-11-17 21:47:07,871 INFO bars=124 target=1 held=1.0 busy=False order=None
...
2026-11-17 21:47:13,966 WARNING IBKR code 1100: pausing
2026-11-17 21:47:16,970 WARNING IBKR code 1102: continuing
2026-11-17 21:47:17,887 INFO bars=124 target=1 held=1.0 busy=False order=None
...
2026-11-17 21:47:21,894 INFO connected to 127.0.0.1:40029
2026-11-17 21:47:21,896 INFO bars=124 target=1 held=1.0 busy=False order=None
...
One order goes out. Two seconds later the position is 1 and the target is 1, so nothing more is sent. Code 1100 pauses the strategy for three seconds, and code 1102 lets it continue.
Then the stand-in drops the connection. The strategy connects again, reads the position again, and still sends nothing. The stand-in received one order in this run and none in the dry run.
What this example leaves out on purpose. It has no backtest, no transaction costs, no stop, no sizing rule beyond one share and no kill switch other than stopping the container. A production strategy needs all of them. The third lock, the paper account, stays shut until the checklist in step 24: on a live account, a market order for one share is a real order.
How do you take it to a live account?
You pin the image, qualify it on paper, and walk a checklist. The repository’s README holds the full list under “Going live”; this is the short form.
Step 23: Run an image name that cannot move
The channel tag brokersre-ib-gateway:stable moves with every build. Run the version tag that the build printed, or the digest (the SHA-256 address) of a copy in a registry that only you can read:
IBGW_IMAGE=brokersre-ib-gateway:10.50.1h docker compose -f compose/docker-compose.example.yml up -d
On 17 November 2026, docker compose ... config with this variable showed image: brokersre-ib-gateway:10.50.1h and pull_policy: never; the up -d itself was not run with a login. If you move the image to another machine, push it to a registry that only you can read: a public repository would publish IBKR’s software.
Step 24: Walk the going-live checklist
- A username of its own. A login with the same username in IBKR Mobile, Client Portal or TWS ends the gateway’s session.
- One paper login with that very image.
scripts/qualify-paper.sh --image <the image you built> --secrets-dir <dir>exited 0. TRADING_MODE=live, andREAD_ONLY_API=noonly if the strategy places orders. These are two of the three locks of the strategy section.- A daily restart time outside IBKR’s reset windows for your region.
- The relay on a private address. The API has no authentication: whoever reaches the relay can use the account as far as
READ_ONLY_APIallows. - A clean
doctor. - A persistent log volume. It holds the record that IBKR rejected a login.
- Someone who is told when a person is needed, and a dead-man ping.
- A host that stays up: no sleep, no unattended reboot in trading hours, a synchronised clock.
- One stop and start on purpose, so the first real restart is not a surprise.
docs/limitations.mdread.
Step 25: Upgrade and roll back
An upgrade is a rebuild. Per the README, give the running image a name that the build will not move, then build and start. The gateway logs in again, so have the phone ready.
docker tag brokersre-ib-gateway:stable brokersre-ib-gateway:previous
scripts/build-image.sh
docker compose -f compose/docker-compose.example.yml up -d
To roll back, start the old image by name:
IBGW_IMAGE=brokersre-ib-gateway:previous docker compose -f compose/docker-compose.example.yml up -d
Coming from gnzsnz? scripts/migrate-from-gnzsnz.sh old.env > new.env converts a gnzsnz .env file and reports every variable that it dropped or renamed, without printing a value. The script is covered by the project’s CI tests.
Why send the gateway’s logs to Azure Log Analytics?
For three jobs that a phone alert cannot do: keep a record that outlives the host, raise an alarm from outside when the host goes silent, and turn time-to-human into a number that you can chart. The phone alert is for the next two minutes. The log store is for the review, the audit and the trend.
Two terms first. An Azure Log Analytics workspace is “a data store into which you can collect any type of log data from all of your Azure and non-Azure resources and applications” (Microsoft Learn). KQL, the Kusto Query Language, is how you ask it questions. Example: the pack’s first query, IbGwMetrics_CL | summarize Rows = count(), Last = max(TimeGenerated) by Instance, Host, Phase, returns one row per gateway, host and phase.
The repository holds an optional pack for this in azure/: a template, a log shipper, three alert rules, a workbook and seven queries. It does not replace the sidecar. Its README draws the line itself: “for a seconds-scale second-factor page use the sidecar notifier”, not these rules.
| Sidecar notifier | Azure Log Analytics pack | |
|---|---|---|
| The question it answers | Does a person have to act now? | What happened, how often, and how long did it take? |
| Speed | Seconds: 2 seconds to the ntfy server in our one run | Rows are queryable in seconds to a few minutes; rules run every 5 or 15 minutes |
| What it keeps | The current state | Every event, and a metrics sample every 30 seconds |
| When the host dies | Silent, unless you set the dead-man ping | Rule C fires from outside the host |
| Who reads it | The person on call | The desk head, the auditor, an investor’s due-diligence team |
What do you get from it?
- A record that outlives the host. The gateway writes its events and metrics to a volume on its own machine. A dead disk or a removed volume takes that record with it; the copy in the workspace stays.
- An alarm from outside. Rule C fires when no metrics row has arrived for 10 minutes: the gateway, the shipper, the host or the network is down. Its worst case from the last row to the notification is 25 to 30 minutes.
- History that you can query. The pack’s queries show every stretch of time per phase, the share of a month in
logged-in, and the events that never arrived. - Time-to-human as a number. One query gives weekly percentiles from the first second-factor request to the completed login. That is time-to-human plus the seconds of the approval itself, measured and not estimated.
- Evidence in your own tenant. In the README’s words: “Your tenant, your workspace: no Azure Lighthouse, no foreign principal, no RocketEdge identifier.” Several gateways report into one workspace, each under its own
IBGW_INSTANCElabel.
Points 1 and 2 apply a sixth mental model, the Swiss cheese model of James Reason: defensive layers are “more like slices of Swiss cheese, having many holes”, and harm gets through only when the holes line up (Reason, British Medical Journal, 2000). So you stack layers whose holes are in different places. The sidecar’s hole is its host, because the two die together. Rule C watches the same gateway from outside that host.
How does one query measure time-to-human?
This is the body of azure/kql/twofa-approval-time.kql; the comment lines at its top are cut:
IbGwEvents_CL
| where Event in ("twofa_initiated", "login_completed")
| sort by Instance asc, TimeGenerated asc
| extend NewEpisode = Instance != prev(Instance) or prev(Event) == "login_completed"
| extend Episode = row_cumsum(toint(NewEpisode))
| summarize
FirstPrompt = minif(TimeGenerated, Event == "twofa_initiated"),
Prompts = countif(Event == "twofa_initiated"),
Completed = maxif(TimeGenerated, Event == "login_completed")
by Instance, Episode
| where isnotnull(FirstPrompt) and isnotnull(Completed) and Completed >= FirstPrompt
| extend SecondsToApprove = datetime_diff("second", Completed, FirstPrompt)
| summarize
Logins = count(),
P50Seconds = percentile(SecondsToApprove, 50),
P90Seconds = percentile(SecondsToApprove, 90),
P99Seconds = percentile(SecondsToApprove, 99),
MaxSeconds = max(SecondsToApprove),
AvgPrompts = round(avg(Prompts), 2)
by Instance, Week = startofweek(FirstPrompt)
| sort by Instance asc, Week asc
An episode runs from the first second-factor request to the next completed login. A prompt that timed out and was asked again stays in the same episode, so the clock starts at the first prompt. P90 is the value that 90% of the logins stayed at or below. Example (illustrative): a P90Seconds of 240 means that nine logins in ten were approved within four minutes.
The first weeks of rows are your baseline. If P90 is 40 minutes (illustrative), no container setting is your problem; the on-call arrangement is.
What leaves the host, and what does not?
| Data | Shipped | Detail |
|---|---|---|
| Structured events | Yes | Table IbGwEvents_CL |
| Metric samples, every 30 seconds | Yes | Table IbGwMetrics_CL; a value that was not measured is empty, never 0 |
| IBC and launcher text | Only after you opt in | Redacted on your host first: an account id becomes [ACCT:…567] |
| The password, the full account id, the settings volume | Never | |
| The Gateway’s own log files | No | IBKR encrypts them on disk |
| API codes such as 1100 | Not yet | Only an API client sees them; the example strategy writes them to its own log |
The shipper is Vector, an open-source log forwarder, pinned at version 0.61.0. It reads the log volume read-only, redacts on your host before the network, and has no published port. The gateway never depends on it: if the shipper fails, the gateway runs on and rule C fires.
The three rules, as the pack’s README defines them:
| Rule | Runs every | Fires when |
|---|---|---|
| A: a person is needed | 5 minutes | A second-factor prompt has had no completed login for more than 5 minutes, the gateway asked for a person, or it is not logged in for more than 10 minutes outside the maintenance window |
| B: health | 5 minutes | Memory above 85% of the limit for 10 minutes, 3 container starts in 30 minutes, an out-of-memory kill, a low disk, a stalled login, a request for a person or an unknown window |
| C: dead man | 15 minutes | No metrics row for 10 minutes, or rows arrive but the newest sample is more than 10 minutes old |
How do you switch it on?
The short form, from the repository root. The pack’s README has the five steps in full.
az deployment group create -g <resource-group> -n main \
-f azure/bicep/main.bicep -p <your-copy>.bicepparam
docker compose -f compose/docker-compose.example.yml -f compose/docker-compose.azure.yml --profile azure up -d
The first command creates the workspace, the tables, the three rules, the workbook and the query pack. The second starts the shipper with a managed identity on an Azure VM; on Windows or on-premises the profile is azure-cert, with a certificate. Between the two you write the template’s outputs into compose/.env, and each gateway needs its own IBGW_INSTANCE. If the gateway is not running, this up -d starts it too, with a real login.
Status. Deploying the pack is outside the scope of this article. The pack is checked offline: the templates compile, the shipper maps and redacts lines of a real gateway run, and the queries type-check. It has not been deployed to a real workspace yet, which is limitation L19 in docs/limitations.md.
The pack’s README puts the cost at about USD 4 a month for one gateway: USD 3.50 for the three rules and about USD 0.10 for ingestion, at list prices of 12 November 2026.
Not on Azure? Vector is not tied to it. Per the README, the same sources and mappings feed its loki, datadog_logs or aws_s3 sinks.
What does it cost to run?
The project costs nothing: it is MIT-licensed. You pay for the machine, as for any self-hosted gateway, and for a few minutes of it for each build. Prices are USD per month, Linux, pay-as-you-go, 730 hours. The Azure, DigitalOcean and QuantConnect prices were read on 18 November 2026.
| Setup | Arithmetic | Per month |
|---|---|---|
| Azure Standard_B2als_v2 (2 vCPU, 4 GiB) + Standard SSD E4 + public IP, East US | 0.0376 × 730 = 27.45; + 2.40; + 0.005 × 730 = 3.65 | 33.50 |
| Same, Southeast Asia | 0.0472 × 730 = 34.46; + 2.40; + 3.65 | 40.51 |
| Azure Standard_D2as_v5 (2 vCPU, 8 GiB), East US / Southeast Asia | 0.086 × 730 / 0.108 × 730 | 62.78 / 78.84, plus disk and IP |
| DigitalOcean Basic droplet, 2 vCPU / 4 GiB | List price | 24.00 |
| Optional Azure Log Analytics pack, one gateway; not deployed yet | Three alert rules 2 × 1.50 + 0.50 = 3.50; ingestion about 0.10 | About 4 (the pack’s README, 12 November 2026) |
| For scale: QuantConnect Researcher pack, a full platform with one live node | List price | 84.00 |
Four notes keep this table honest:
- Memory. A logged-in paper Gateway used a 459 to 494 MB working set, measured with the earlier image in short sessions. So 4 GiB holds one gateway with room. Memory under heavy load is not measured, and a burstable VM’s CPU baseline is a risk under sustained load.
- Old Azure sizes. Do not plan on B2s or B2ms: new subscriptions cannot deploy them, and they retire on 15 November 2028.
- Not like for like. QuantConnect includes data, backtesting and hosting. The point is narrower: a fund that has its own strategy code does not need a platform to get a supervised gateway.
- Two usernames. Live and paper can share a host with
compose/docker-compose.multi.yml. Each gateway there has a 2 GB memory limit, so two need a larger VM. That file is tested offline only.
What a build costs you
| Item | Measured, 17 November 2026 |
|---|---|
| The image | 1,622,555,830 bytes (1.6 GB) |
| Docker’s build cache of one build | 3.554 GB; docker builder prune frees it |
| The installer cache, per Gateway version | 360,312,642 bytes for 10.50.1h x64; nothing prunes it |
| The build helper image | 231,871,581 bytes, built once per host |
| Download from IBKR per new Gateway version | 360,312,436 bytes (stable x64) |
So plan about 6 GB of free disk and one 360 MB download per new IB Gateway version. Pulling a ready-made image is faster; that is the cost of this design, and we state it.
What does it take off your plate?
It replaces watching with being told. The events below are real and countable. The hours are yours to measure: we publish a formula, not a savings claim.
| What happens | How often | What the image does | Proven? |
|---|---|---|---|
| Weekly full login with the second factor | 52 times a year per username | Phase 2fa-pending; the sidecar sends twofa_pending to a phone | Recognised from IBC’s source text; no real prompt seen yet |
| A wrong or changed password | Rare, costly | Stops at needs-human, never retries; the latch blocks the same files on the next start | IBKR’s rejection dialog seen in a real log with an earlier image; the latch has stated limits |
| A restart outside the daily auto-restart | Any unplanned stop | A full login is needed; the phase and the sidecar say so | Seen on paper with the earlier image; the alert and its resolution seen again with a self-built image in test mode |
| API port open but not answering | Reported in the field | The sidecar’s read-only time request marks the API down when no answer comes | The probe ran on a real logged-in Gateway; a real half-closed-socket case has not been seen |
| A setting that cannot work | At every first setup | doctor names the setting and the fix before anything reaches IBKR | 12 checks passed on a real setup; a real unwritable volume stopped a start |
| IBKR publishes a new Gateway build | On IBKR’s schedule | --print-plan shows it; a rebuild takes it after checking IBKR’s stamp | Seen on 17 November 2026; that build has not logged in |
| The host itself dies | Rare, silent | The dead-man ping stops; an outside check raises the alarm | Delivered to a local receiver only |
| An unexpected Gateway dialog | After IBKR changes | Event unknown_window, optional screenshot | Seen with a real “Paper Account Notice” dialog, earlier image |
The formula, with your own numbers as inputs:
hours per year = 52 × (minutes per weekly login, including checking it worked) / 60
+ (unplanned full logins per year) × (hours each, including the time until someone noticed)
+ (incidents per year: zombie API, out of memory, stale data) × (hours each)
+ (Gateway or image upgrades per year) × (hours each to build, test and roll out)
The second line is time-to-human, priced. The image records the timestamps that measure the first three lines: twofa_initiated to login_completed, login_stalled, oom_kill, and the sidecar’s api_unhealthy duration.
Is it finished?
No. It is a public preview, and the code is under permanent development. Both statements are deliberate.
Still under testing: what is verified
| What | When (UTC) |
|---|---|
| The recipe built IB Gateway 10.50.1h from a clean clone, in Git Bash, PowerShell 7 and Windows PowerShell 5.1; the offline IBC test passed in every build | 17 November 2026 |
| The project’s CI builds the image with the recipe on GitHub’s Ubuntu runner and runs the container tests on it | 17 November 2026 |
Labels, installer SHA-256 and the installed stamp agree with IBKR’s version.json | 17 November 2026 |
doctor: 12 passed, 1 skipped; a start without a login was healthy after 7 seconds | 17 November 2026 |
Sidecar 0.2.2 next to a self-built image in test mode: test message, /readyz, an alert and its resolution on a self-hosted ntfy server | 17 November 2026 |
The example strategy: 25 offline tests with the real ib_async 2.1.0 against a stand-in gateway; its image built with Podman 5.7.0 and run against the same stand-in; Docker Compose v5.8.0 accepted the four files with config | 17 November 2026 |
With the project’s earlier images and a real paper account: the qualification script passed on both channels; the quick start logged in 12 seconds after up -d; the Python and C# clients read IBKR’s server time every 30 seconds | 15 and 16 November 2026 |
Not yet observed
- A login with a self-built image. The build of IBKR’s 10.50.1h has passed only offline tests.
- macOS, an arm64 Linux host, and a login on arm64 hardware.
- A real second-factor prompt; the paper logins asked for none.
- A real daily auto-restart, and a competing session on the same username.
- A live account. Everything above is paper or offline.
- A real corporate proxy; a proxy that inspects TLS cannot work.
- The Windows host kit starting a gateway, and the Azure Log Analytics pack deployed.
- Two gateways on one host with real logins.
- The example strategy against a real Gateway, and its image built with Docker.
Outside the scope of this article: the notification channels other than ntfy, the generic webhook and the dead-man ping. The sidecar’s README records the state of each.
Under permanent development: what that means for you
The repository had 462 commits between 1 and 17 November 2026 (UTC), with 39 merged pull requests, 18 architecture decision records, 16 runbooks and 40 numbered limitations. Our evidence run used commit 7841934.
In the 12 hours 39 minutes after that commit, 34 more commits reached main. Two of them made an unchanged rebuild keep its image id, so that a rebuild no longer replaces a running gateway and forces a new login. Another stopped a proxy password from appearing in an error message. A fourth moved the pin to IBKR’s 10.50.1h, one day after IBKR published it.
Three rules follow:
- The README of the commit that you clone is the source of truth. Commands and outputs in this post are dated for that reason. If the two differ, the README is right.
- Watch the releases. Each new IB Gateway version that the repository pins creates a release. For you a release means: pull the repository and build again.
- Report what you see. A dialog that the image does not know, a host that we did not test, a limit that is wrong: open an issue. The list of limitations shrinks only through real runs.
Build it, run it on a paper account first, qualify your build with one paper login, run an image name that cannot move, and read docs/limitations.md before you put a live session on it.
Alternative Perspectives
“Automate the second factor and be done.” IBKR offers a mobile authenticator (TOTP), and IBGA, ibg-controller and IBeam automate it on purpose. The merit is real: a restart at 03:00 needs nobody. Our position is that a second factor stored next to the password is one factor, and that the account holder, not the tool, carries that risk.
“Building is a tax; a registry is the point of Docker.” It is a fair objection: a pull takes seconds, and this build takes minutes and about 6 GB. We accept the tax because the result is an image whose every input you checked yourself.
Can RocketEdge set it up for you?
Yes. The repository is free and complete, and many teams will need nothing else. For teams that want it running this week, RocketEdge engineers set it up with you:
- A working session on your machine. Your engineer builds the image from the public recipe. We explain each check and each line of output.
- Qualification on your own paper account. You type your own credentials. We do not ask for them, and the second factor stays on your phone.
- Alerts where your team reads them. One channel, the escalation, the dead-man ping, and the runbooks adapted to your contacts.
- The going-live checklist, walked line by line. It ends with a stop and a start on purpose, and a list of what is not proven yet for your setup.
For funds that want the reliability of the whole IBKR session engineered and operated as a service, that is BrokerSRE. Both are engineering and operations work. Neither is trading, and neither is advice.
What does this mean for your trading desk?
- Measure your time-to-human this week. When did the last weekly prompt appear, and when did a person learn of it? Write both times down, and put the weekly login on a calendar with two named people.
- Run steps 1 to 9 today. They need no login and no credential, and they tell you whether the image starts on your host.
- Give the gateway a username of its own, then qualify and pin. One paper login with
scripts/qualify-paper.sh, then run the version tag, never the channel tag. - Wire one channel and one dead-man ping. Then stop the gateway on purpose and time the message.
- Run the example strategy in dry run on your paper account. Read its log through one daily restart. Then replace the seven signal lines with your own.
FAQ
Does IBKR support IB Gateway in Docker?
No. IBKR’s documentation says a headless session without a GUI is not supported. This image runs the regular Gateway on a virtual display; IBKR has not said whether that counts, and we found no IBKR statement for or against containers.
Why is there no IB Gateway Docker image to pull?
The image contains IB Gateway, which is IBKR’s software. RocketEdge decided not to distribute it; you build the image, and your machine downloads IB Gateway from IBKR under your own agreement with IBKR. If you move the image, keep it in a registry that only you can read.
Can the weekly two-factor login be automated?
IB Gateway cannot avoid the weekly login. Automating the second factor is technically possible, and other projects do it with TOTP. This image chooses not to: in the words of IBC’s author, “if 2FA is automated, it has no value”. The image tells a person that the prompt is waiting.
Is it free, and what is the licence?
The project is MIT-licensed and free. An image that you build also contains IBC (GPL-3.0, aggregated, not linked) and IB Gateway, which your machine downloads from IBKR under IBKR’s terms. Your cost is the build and one small VM: USD 24 to 41 a month in our price table.
Is it ready for a live account?
Not without your own qualification. It is a public preview: the build is tested, paper logins passed with the project’s earlier images, and no self-built image has logged in yet. Start on paper, qualify your build with one paper login, and read docs/limitations.md first.
Methodology and disclosure: Outputs marked 17 November 2026 ran from a clean clone of RocketEdge/brokersre-ib-gateway at commit 7841934, without any login to IBKR; the two credential files held a dummy value. Outputs marked 16 November 2026 ran against a real IBKR paper account with the project’s earlier image of IB Gateway 10.50.1g. Facts about other projects were read from each default branch on 18 November 2026 (gnzsnz da2bfb2, ibg-controller 3b930d4, extrange 27084b0, IBeam 1905559, manhinhang e86dc86, IBGA 8cc1f36, UnusualAlpha b9017e3), and star and pull counts from the GitHub and Docker Hub APIs the same day. “None found” means a search of that repository’s documents, code and configuration; it is not proof of absence.
The strategy outputs of steps 21 and 22 ran on 17 November 2026 (UTC) on Linux: Python 3.14 and ib_async 2.1.0 against a stand-in gateway with made-up prices, in an image built with Podman 5.7.0 from the Dockerfile as printed; nothing contacted IBKR. The Azure Log Analytics facts come from azure/README.md and azure/kql/ at commit 0574fcd. The IBKR and Microsoft pages quoted here and the Azure, DigitalOcean and QuantConnect prices were read on 18 November 2026. Research and first draft were produced with Perplexity Computer (Claude Fable 5.2 orchestrator) and edited by Jiri Pik.
About RocketEdge: RocketEdge builds AI-powered trading infrastructure for institutional and professional traders in APAC and globally: the MultiEdge product family on multiedge.ai and reliability engineering for broker connectivity through BrokerSRE, engineered on Azure by practitioners who have shipped low-latency trading, risk and market-data systems at global banks. Want this gateway set up on your own infrastructure? → Book a 30-minute Strategy Call
Disclaimer: This content is for informational purposes only and does not constitute financial, legal or investment advice. The gateway image and the sidecar are engineering software, not investment advice and not a managed trading service; they execute no trades and guarantee no trading outcome. Measurements come from the machines and dates named and will differ on yours. Illustrative figures are labelled as such.
The example strategy is a teaching example and not a recommendation to buy or sell any instrument; it sends orders only when you switch that on. Past performance is not indicative of future results.
Interactive Brokers, IBKR, Trader Workstation, TWS and IB Gateway are trademarks of Interactive Brokers LLC. RocketEdge is an independent engineering firm and is not affiliated with, sponsored by or endorsed by Interactive Brokers.