GUIDES

IBKR API Setup Guide — Connect Interactive Brokers for Automated Trading

Contents
Connect Interactive Brokers to TraderWe for US market data and order routing. IBKR is the deepest connection TraderWe has. It is the one that gives you both a full order book and live orders — but it also has the most moving parts, because the API lives inside a desktop program that has to stay running.

1. What you need

- An IBKR account. Market data subscriptions are optional — TraderWe adapts to delayed data automatically, and tells you when it has. - TWS or IB Gateway installed on the PC that will trade. Gateway is the better choice for unattended sessions: it is lighter and has fewer popups.

2. Enable the API

- TWS: File → Global Configuration → API → Settings. Tick "Enable ActiveX and Socket Clients". - Note the socket port. Defaults are 7497 for paper and 7496 for live in TWS; IB Gateway uses 4002 and 4001. - Add 127.0.0.1 to trusted IPs so the connection is not challenged every time. - Leave "Read-Only API" unticked if you intend to place orders. With it on, quotes work and orders are rejected.

3. Connect in TraderWe

Settings → Exchange connections → IBKR. Host 127.0.0.1, your port, then Connect. The status line tells you what was negotiated: the server version, your account number, and the first order number IBKR handed out. If several accounts are listed, TraderWe uses the first one. Check that it is the account you meant before arming orders.

4. Market data grade — read this before trusting a price

IBKR only streams real-time prices for instruments you have a market data subscription for. Without one it does not stream at all; it returns an error. Rather than showing you nothing, TraderWe switches that symbol to IBKR's 15-minute delayed feed so the screen and the recording stay alive. When it does, the connection badge changes to Degraded and says "Delayed (15 min)". Do not trade live on delayed data. The badge is there so the state is never hidden from you — a 15-minute-old price looks exactly like a fresh one on a chart.

5. Orders

TraderWe routes four order types to IBKR through the same socket that carries your quotes:
TypeSent asNeeds
MarketMKT
LimitLMTlimit price
StopSTPstop price
Stop limitSTP LMTboth prices
Time in force is sent as you set it — DAY, GTC, IOC, FOK or OPG. A value IBKR does not accept is refused with a message rather than quietly changed. Orders are routed SMART, which lets IBKR choose the venue. Extended hours: when a limit order goes out while the regular session is closed, TraderWe sets IBKR's outside-RTH flag so it can fill in pre-market or after-hours instead of resting until 09:30. Market orders are not sent outside the session — a market order in a thin book has no price control. Fills, cancels and rejections come back on the same socket and appear in your order list. If IBKR rejects an order, the reason is attached to that order rather than being buried in a log. Order routing stays locked until you arm it. Until then, strategies run in paper mode and fill inside TraderWe against live IBKR prices.

6. The two-factor problem

IBKR requires two-factor authentication at login, and in practice that means roughly once a day on weekdays. An unattended session will eventually be logged out. Plan around it rather than being surprised by it: - IB Gateway restarts on a schedule by default. TraderWe reconnects automatically with a widening delay and re-subscribes everything it had. - Do the 2FA before the session you care about, not during it. - If the socket drops mid-session, the connection badge shows Reconnecting. Recording resumes on reconnect; the gap is visible in the recording rather than silently interpolated.

7. Check it worked

- The badge reads Connected with a server version and an account number. - Quotes tick, and the badge does not say Delayed (15 min) for the symbols you care about. - The order book ladder is populated — IBKR is one of the connections that gives real depth.

8. Common problems

"Connection refused" TWS or Gateway is not running, or the port is wrong. Paper and live use different ports, and TWS and Gateway use different ports again. Quotes sit at 0, or the badge says Delayed (15 min) No market data permission for that instrument. TraderWe has fallen back to delayed data. This is a subscription matter on the IBKR side, not a connection fault. The connection works but every order is rejected "Read-Only API" is ticked in the API settings, or the account selected in TraderWe is not the one with trading permission. It disconnects around the same time every day That is the Gateway's scheduled restart plus 2FA. See section 6. Limitations - The API requires TWS or IB Gateway running on the same machine. There is no direct-to-IBKR path without it. - Order fills are reported through the socket session that placed them. If the process restarts, orders already resting at IBKR remain live at IBKR but are no longer tracked by that session — check the TWS order window after any restart. - This guide covers US equities. Options, futures and non-US instruments are not routed by TraderWe today.

Related reading

← All guides

Originally published by TraderWe on July 1, 2026. You may quote and link to this page. Republishing the full text without a link back to the original is not permitted.

6 replies

BacktestBetty· Jul 2026 ago
Two things I'd add from my own setup: (1) run Gateway, not TWS, if you're leaving it up overnight — fewer dialogs to eat your session, and (2) the daily auto-restart is the thing that bit me, so decide up front whether you're restarting the app or just letting it reconnect. Also worth saying: the article mentions the app quietly falls back to delayed data, which is fine for monitoring but if you ever backtest off a feed and forward-test off a different one, you're comparing two different things and you will fool yourself.
N
NightOwl_Yuki· Jul 2026 ago
the read-only tickbox catching people out is so real lol, quotes flow fine so you assume everything's wired up and then orders just bounce. also night owls beware, the desktop program napping while you sleep is not a fun way to find out your machine went to sleep too
L
LurkerLee· Jul 2026 ago
If more than one account shows up and the app just takes the first, is there any way to pick which one? That part got cut off for me.
H
HalfKelly· Jul 2026 ago
Nice clear walkthrough. The bit I'd underline for newcomers is that the first order number it hands you is per-session bookkeeping, not a running count of anything you own — worth understanding before you start reasoning about how many open orders your sizing rules allow.
TraderWeTraderWe Team· Jul 2026 ago
You read it right, and there is no way to pick yet. When IBKR returns more than one managed account we take the first one in the list. The workaround today is to log the Gateway session in under the account you want to trade. A selector is the correct fix and it is written down, but we would rather tell you the current behaviour plainly than leave you guessing which account an order landed in.
F
FiveMinFiona· Aug 2026 ago
The one thing I'd add: Gateway logs itself out on a daily schedule, so if you leave it unattended overnight you'll come back to a dead socket even though nothing was wrong with the setup. Worth setting the auto-restart time in Gateway config to a slot that's outside your session, otherwise it kills the connection mid-day. Also +1 on the read-only tick — I lost a morning to that once, quotes were fine so I assumed everything was fine, and only found out at the first order. Does the Degraded badge stay up for the whole session or does it flip back on its own once a subscription kicks in?
Sign in to reply →