June 29, 2026

Interactive Brokers is one of the most powerful brokers available to retail and professional traders — deep liquidity, global market access, low commissions, and a mature API that has been a favorite of algorithmic traders for over a decade. If you want to run a trading bot through IBKR, this guide walks you through exactly how to do it, from account configuration to your first automated order.
Whether you plan to write your own bot in Python or use a no-code platform like TradersPost or PickMyTrade, the setup process starts in the same place: the TWS API.
Before touching any configuration, make sure you have the following in place:
An Interactive Brokers account. If you don't have one, open a live account at interactivebrokers.com. IBKR automatically provisions a paper trading account alongside your live account — you'll use this for testing before risking real capital.
Trader Workstation (TWS) or IB Gateway installed. These are the two client applications that expose the API. TWS is the full desktop trading platform with charts and order entry. IB Gateway is a lightweight, headless version built specifically for API connections — it uses far fewer system resources and is the better choice for running a bot.
A clear strategy. Know what you're automating before you connect anything. The API does exactly what you tell it to do. A bot connected to a live account with no guardrails will execute whatever your code sends.
This is the first decision most people get wrong. Here's the difference:
TWS is the full trading platform. It's useful if you're actively managing positions alongside your bot, but it's resource-heavy and not designed to run continuously in the background.
IB Gateway is a minimal application that does one thing: accept API connections and relay them to IBKR's servers. No charts, no order panels — just a connection. For dedicated bot use, IB Gateway is the right choice. It starts faster, uses less memory, and is more stable for 24/7 operation.
Download both from the IBKR website under Trading > TWS Platform. Install whichever fits your setup — you can always switch later.
Once TWS or IB Gateway is installed and you're logged in (use your paper trading credentials for testing), you need to enable the API socket connection.
In TWS: Go to Edit → Global Configuration → API → Settings.
In IB Gateway: The settings panel appears immediately after login.
In both cases, make sure the following options are configured:
127.0.0.1 (localhost) is sufficient. If your bot runs on a remote server or VPS, add that server's IP here.Click Apply and OK. The API is now listening.
Before writing a single line of bot logic, confirm the connection works.
If you're using Python, the official IBKR Python API library is available via pip. The more popular option is ib_insync, a community wrapper that makes the official async API much easier to use with a clean synchronous interface.
Install it with:
pip install ib_insync Then run a quick connection test:
from ib_insync import IB
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1) # 7497 = paper trading port
print(ib.accountValues())
ib.disconnect() If this returns your account data without errors, you're connected. If you get a connection refused error, double-check that TWS or IB Gateway is running, the socket port matches, and the IP is trusted.
Not every trader wants to write Python. Several no-code platforms sit between your strategy signals and the IBKR API, handling the connection for you.
TradersPost connects directly to IBKR and lets you route TradingView webhook alerts into automated orders on stocks, options, and futures. Setup takes about 10 minutes: connect your IBKR account via OAuth, define your strategy rules in TradersPost, and point your TradingView alert webhook at their endpoint. No code required.
PickMyTrade is another popular option specifically for options automation on IBKR. It supports multi-leg options strategies, order routing, and position sizing — all configurable through a web interface.
For traders already using TradingView with Pine Script strategies, this no-code path is often faster to go live than building a custom Python bot from scratch. The tradeoff is that you're dependent on a third-party service and have less control over execution logic.
See our guides on TradingView trading bot setup and how to use TradingView alerts with a trading bot for the full webhook flow.
The IBKR API can trade any asset class your account is approved for — stocks, options, futures, forex, crypto. But you need the right permissions enabled first.
Log into Client Portal (the IBKR web dashboard) and navigate to Settings → Account Settings → Trading Permissions. From here you can request access to:
Options in particular require approval — IBKR will ask about your trading experience before granting access. If you're planning to run an options bot (covered calls, the Wheel strategy, spreads), apply for at least Level 2 options permission. See our guide on options trading bots for more context on what strategies are automatable.
This step is non-negotiable. Before connecting your bot to a live account, run it on your IBKR paper trading account for at minimum two weeks.
Paper trading on IBKR uses real market data with virtual money. It behaves identically to live trading from the API's perspective — the same order types, the same fills simulation, the same error responses. The only differences are that fills are simulated and real market impact doesn't apply.
What to verify during paper testing:
Jumping to live trading before this step is one of the most common and expensive mistakes in bot trading. See our full guide on how to test a trading bot before going live for a complete testing framework.
Connection refused on port 7496/7497: TWS or IB Gateway is not running, or the socket port in Global Configuration doesn't match what your code is targeting. Confirm the application is open and logged in.
"Not connected" error after successful connection: IBKR has a 15-second auto-disconnect idle timer by default. Either send a keep-alive ping at regular intervals or disable the auto-disconnect in TWS settings under API → Settings.
Order rejected with error 201 (Order rejected — reason: no trading permissions): The asset class your bot is trying to trade isn't enabled on your account. Request the appropriate trading permissions through Client Portal.
Duplicate orders after reconnect: If your bot doesn't track its own order state, it may re-send pending orders after a disconnect. Build in a startup reconciliation step that checks open orders before placing new ones.
Daily session restart: IB Gateway and TWS require a daily restart to refresh authentication. Schedule this during off-hours (IBKR typically uses 11:45 PM – 12:00 AM ET). If you're running a bot on a VPS, automate the restart with a scheduled task.
If you want your bot running 24/7 without tying up your personal computer, deploy it to a VPS (Virtual Private Server). QuantVPS and similar services offer pre-configured environments optimized for IBKR bots, with IB Gateway pre-installed and auto-restart scripts included.
For manual VPS setup, the basic approach is: install IB Gateway on the VPS using a headless Linux configuration (IBC — the IB Controller project on GitHub — automates login and session management), deploy your bot script, and use a process manager like pm2 or systemd to keep it running.
This setup is more involved than running locally but gives you a reliable, always-on execution environment that doesn't depend on your home internet connection or your computer staying powered on.
Connecting Interactive Brokers to a trading bot is one of the most capable setups available to retail algorithmic traders. The TWS API gives you full programmatic control over every order type IBKR supports — with deep liquidity, broad asset class access, and a proven infrastructure behind it.
The path forward depends on your technical comfort: Python with ib_insync gives you maximum flexibility, while no-code platforms like TradersPost let you automate strategies without writing a line of code. Either way, the setup process is the same — enable the API, test on paper, verify permissions, then go live with proper risk controls in place.
Before going live, review our guide on AI trading bot risk management to make sure your position sizing, stop losses, and drawdown limits are configured correctly.
Get our free Top 5 Bots for Early Retirement report plus The Bot Report newsletter — the bots we'd actually trust to compound over the long term.
Join The Bot Report newsletter and get our free guide to the five trading bots most likely to help you retire early — backed by real reviews and verified performance.