Interactive Brokers Trading Bot: Setup Guide
By Eric Johansen — Portfolio Manager, Systematic Equities · Published November 7, 2026 · 7 min read
An Interactive Brokers trading bot connects to your IBKR account through IB Gateway or Trader Workstation running on your own computer, using IBKR's own API. With AlgolaneBots, the free Windows desktop app talks to IB Gateway on the same machine, sends the orders and reads your positions back, so your login never leaves your computer and AlgolaneBots cannot withdraw money. Setup comes down to a handful of choices: log in with the IB API, pick paper or live, untick Read-Only API and use the right socket port.
This guide walks through each step in order, then covers how to keep the connection running and the limits that apply to IBKR accounts.
How does a trading bot connect to Interactive Brokers?
AlgolaneBots connects to Alpaca through a sign-in on Alpaca's website. Interactive Brokers works differently. IBKR's trading API is reached through one of its own programs, IB Gateway or Trader Workstation (TWS), logged in on a computer. Software on that computer talks to the program through a local connection called a socket, and the program passes orders on to IBKR.
With AlgolaneBots, the chain looks like this:
- After the US market closes, AlgolaneBots works out what the strategy wants to hold.
- The AlgolaneBots desktop app on your Windows computer receives that target and runs its checks.
- The app sends the orders to IB Gateway (or TWS) on the same computer.
- IB Gateway passes them to IBKR, and they fill at the market open.
- The app reads your positions back so the dashboard matches your account.
Two points follow from this design. First, your IBKR username, password and session stay in IB Gateway on your own machine; AlgolaneBots's servers never see them. Second, the access is limited to placing trades and reading positions. AlgolaneBots cannot move or withdraw money, and it holds no customer money. For the wider picture, see our post on whether it is safe to connect a bot to your broker.
IB Gateway or Trader Workstation?
Both work. IB Gateway is the lighter option: a small program built for API connections, with no charts or order screens. TWS is IBKR's full trading platform, which some people already keep open. If you only want the bot to trade, IB Gateway is the simpler choice. The settings are nearly the same, and the differences are noted below.
What do you need before you start?
| You need | Why |
|---|---|
| An IBKR account, paper or live, able to trade US stocks and ETFs | The four US strategies trade US stocks and funds |
| A Windows computer that is on before the New York open | The desktop app places the orders itself |
| IB Gateway or TWS, installed from IBKR | The bot reaches IBKR through it |
| The free AlgolaneBots desktop app | Connects your computer to your AlgolaneBots account |
| A AlgolaneBots account | Paper trading is free during the 90-day trial |
| For real money: a subscription, consent and a live account | Live trading stays off until all three are in place |
Each broker connection follows one bot, so if you want two strategies trading at IBKR, plan for two connections. Our brokers page lists the notes for every supported broker.
How do you log in to IB Gateway for a bot?
When you open IB Gateway, the login screen asks for two choices before your username.
API Type: choose "IB API". The other option, FIX CTCI, is a different protocol aimed at institutional order routing. The AlgolaneBots desktop app uses the IB API, and it will not connect if FIX CTCI is selected.
Trading Mode: choose Paper or Live. This decides which account the session opens. It also decides which socket port the program listens on, which matters in the next step.
Finding your paper trading username
An IBKR paper account has its own username, separate from your live login. To find it, sign in to IBKR's Client Portal and go to Settings > Account Configuration > Paper Trading Account. Use that paper username, with Trading Mode set to Paper, when you log in to IB Gateway.
Starting on IBKR paper is sensible even if you plan to trade real money. It tests the full chain, from the desktop app to IB Gateway to IBKR, without risking anything. It is a different test from AlgolaneBots's own $10,000 paper account, which needs no broker at all:
| Option | What it tests |
|---|---|
| AlgolaneBots paper account | How the strategies behave, with real prices, next-open fills and a 0.05% cost per fill |
| IBKR paper account | Your setup: login, API settings, ports and order sending |
| IBKR live account | Everything, with real money |
Live logins at IBKR normally ask you to confirm with its second-factor step, so have that ready.
Which API settings does the bot need?
Once logged in, open Configure > Settings > API > Settings in IB Gateway. In TWS the API settings sit in its global configuration. Set them as follows:
| Setting | What to choose | Why |
|---|---|---|
| Read-Only API | Unticked | When ticked, the bot can read positions but every order is refused |
| Allow connections from localhost only | Ticked | Only programs on this computer can connect, and the desktop app runs on this computer |
| Socket port, IB Gateway | 4002 for paper, 4001 for live | The port the desktop app connects to |
| Socket port, TWS | 7497 for paper, 7496 for live | The same, for Trader Workstation |
| Enable ActiveX and Socket Clients (TWS only) | Ticked | TWS ignores API connections without it |
Apply the changes and keep the program open. Then, in the AlgolaneBots desktop app, connect Interactive Brokers using the same paper or live choice you logged in with. A mismatch, such as a paper login with the live port, is an easy mistake and stops the connection.
Leaving "Allow connections from localhost only" ticked is worth stressing. It means nothing outside your computer can talk to IB Gateway, which is exactly what you want. The desktop app does not need any remote access to work.
How do you keep the connection running?
A bot only trades if the chain is up when orders are due. AlgolaneBots sends orders before a 9:28am New York cutoff and skips anything later for that day, so a sleeping computer or a closed IB Gateway means a missed trade rather than a late one.
Three habits help:
- Turn on auto restart. In IB Gateway, go to Configure > Settings > Lock and Exit and choose Auto restart. This lets the program restart itself on a schedule without asking you to log in each time.
- Expect a weekly login. Even with auto restart, IBKR asks for a fresh login about once a week, on Sunday. Make logging back in part of your routine, or the Monday orders will not go out.
- Keep the computer awake. The computer needs to be on, connected to the internet and not asleep when the order run happens before the open.
Each order run also checks subscription, consent, signal age, whether each fund can still be traded, and price gaps that look like a stock split, and every order carries a unique ID so a retry cannot trade twice. If anything looks wrong, the kill switch stops every broker order at once. Our posts on how a trading bot places orders safely and the safety overview explain each check.
What limits apply to IBKR accounts?
Two IBKR-specific limits change how your account will look compared with the strategy's target.
Whole shares only
IBKR does not offer fractional shares through the API, so the bot trades whole shares. Any amount too small to buy one more share stays in cash. As an illustration, if a strategy wants $1,500 in a fund priced at $400, the bot can buy 3 shares for $1,200, and $300 stays as cash. In a large account this gap is small. In a small account holding high-priced stocks, the real holdings can drift noticeably from the target weights, and results can differ from a version that trades fractions.
US dollars only for US stocks
If your account's base currency is not US dollars, only the US dollars you hold can buy US stocks. Money held in another currency is not used for these purchases. Check the dollar balance in your IBKR account, not only the total value, before expecting the bot to trade.
Strategy risk does not change
A careful setup only makes sure orders go where they should. It does not make a strategy profitable, and the US strategies, especially those holding leveraged funds, have had deep falls in historical backtests. Our posts on how much a trading bot can lose and the paper-to-live checklist are worth reading before real money is involved, along with our risk disclosure.
Key takeaways
- A bot reaches Interactive Brokers through IB Gateway or TWS on your own computer; with AlgolaneBots, the Windows desktop app connects to it locally and places the orders.
- Log in with API Type "IB API" (not FIX CTCI), choose Paper or Live, and use the separate paper username from Client Portal for paper.
- Untick Read-Only API, keep "Allow connections from localhost only" ticked, and use port 4002 (paper) or 4001 (live) for IB Gateway, or 7497 and 7496 for TWS with socket clients enabled.
- Turn on auto restart, expect a fresh login about once a week on Sunday, and keep the computer awake before the open.
- The bot trades whole shares only, uses only US dollars held for US stocks, and cannot move or withdraw money.
This is general education, not personal advice.
Try the strategies before connecting IBKR
You do not need IB Gateway to see how the strategies behave. AlgolaneBots gives you a $10,000 paper account and a free 90-day trial with no card needed, and you can connect Interactive Brokers whenever you are ready. Start on paper.
Where the numbers come from: every strategy figure is from AlgolaneBots's own historical backtests, run on past prices with the method on how we test. Nobody earned them, and future results will differ. General market facts are checked against regulator and company sources. This guide is general information, not personal advice. Read the risk disclosure and how we write our guides.