# Connect Scalpel to Interactive Brokers

> Run TWS or IB Gateway, match the API port and watch Scalpel connect. Which program to use, the ports (7497, 7496, 4001) and what the link banner tells you.

Source: https://scalpeltrade.com/guides/connect-interactive-brokers
Guide 1.4, Getting started. Beginner, 6 min read.
Checked with Scalpel 1.14.0 on 2026-11-06. By Scalpel Team.
Video for section 1 (1:56): https://www.youtube.com/watch?v=h5L0d84z-6I

**In short:**

Scalpel reaches your Interactive Brokers account through TWS or IB Gateway running and logged in on the same computer. Enable the API in that program, and make its socket port match Scalpel's (**Settings > Connection > Port**: 7497 by default; IB Gateway uses 4001). When they match, the **IBKR** pill in the bottom-left corner turns green and reads **Connected**. Until then, a banner under the header tells you what Scalpel found and offers a one-click fix.

Scalpel has no data feed of its own and never asks for your IBKR password. Everything it shows (quotes, Level 2, the tape, charts, IBKR's scanner, the news on your account) and every LIVE order goes through the API socket of the IBKR program you already use. That is also why there is nothing else to pay for: no separate data feed, no charting subscription.

**Before you start:**

- Scalpel installed and activated ([guide 1.3](https://scalpeltrade.com/guides/activate-licence)).
- TWS or IB Gateway installed from Interactive Brokers' website, and your IBKR username and two-factor device to hand.
- The API switched on in that program ([guide 1.5](https://scalpeltrade.com/guides/enable-tws-api) has every setting).
- A market data subscription for live US stock quotes and, for Level 2, depth ([guide 1.6](https://scalpeltrade.com/guides/ibkr-market-data-for-day-trading)).

## TWS or IB Gateway: which to run

They are the same program underneath. IB Gateway is TWS without the trading screens: it uses far less memory and serves the same API. Interactive Brokers allows one trading-platform session per username, so logging in to TWS, IB Gateway or IBKR Desktop signs the others out (after asking). That gives three ways to run:

| Setup | Run | Good for |
|---|---|---|
| Scalpel instead of TWS | IB Gateway only | The lightest setup; Scalpel is your only trading screen |
| Scalpel alongside TWS | TWS with the API on | Keeping TWS's own windows; costs nothing extra |
| Both fully open at once | TWS on one username, IB Gateway on a second | Two independent logins. Add the second user in Client Portal; market data is billed per username, so it needs its own subscriptions |

Either program asks for two-factor approval on your phone at login and logs you out once a day unless you set auto-restart in its **Lock and Exit** settings. IB Gateway has no trading screen, but it is not unattended: it still needs those logins.

## The ports

Each program listens on a socket port, and the number depends on the program and on whether you logged in to a live or a paper account:

| Program | Live login | Paper login |
|---|---|---|
| TWS | 7496 | 7497 |
| IB Gateway | 4001 | 4002 |

Scalpel starts on **7497**. Log in with your real username: Scalpel's own SIM mode does the paper trading, against live data, so you do not need IBKR's paper account. That means a live TWS login usually listens on 7496 while Scalpel expects 7497. Change either side, or let the banner switch Scalpel over for you (below).

## Connect

### 1. Start TWS or IB Gateway and log in

Start the program, log in and approve the login on your phone. Wait until it is fully up: TWS shows its main window, IB Gateway its status window.

### 2. Enable the API

In TWS, open the global configuration and go to **API > Settings**. Tick **Enable ActiveX and Socket Clients**, untick **Read-Only API** if you will ever trade LIVE, and note the **Socket port**. IB Gateway has the same page under **Configure > Settings > API > Settings**, with the socket always on. Every option is in [guide 1.5](https://scalpeltrade.com/guides/enable-tws-api).

### 3. Match the port in Scalpel

In Scalpel, open **Settings** (`Ctrl`+`,`), then **Connection**. Under **IBKR TWS (stocks: market data + orders)**, leave **Enabled** ticked and **Host** at **127.0.0.1**, and set **Port** to the program's socket port: 7497 or 7496 for TWS, 4001 or 4002 for IB Gateway. Click **Apply**. Scalpel reconnects straight away, no restart.

*Screenshot: Settings, Connection: Host and Port, outlined. 127.0.0.1 is this computer; the port must be the one TWS or IB Gateway listens on.*

**Tip.**

Leave the host as **127.0.0.1**, not "localhost". TWS refuses some localhost connections, and 127.0.0.1 always works for a program on the same computer.

### 4. Watch the IBKR pill turn green

The status bar along the bottom starts with the **IBKR** pill. It goes amber **Connecting**, then green **Connected**. Within a second or two the trader desks fill with quotes, Level 2 and the tape, the scan desk (desk 1 on a new install) starts listing movers once the IBKR scanner has results, and the voice says the link is up.

*Screenshot: The status bar when Scalpel is connected: a green dot, IBKR, Connected. The build number is on the right.*

## What the IBKR pill says

| Pill | Colour | Meaning |
|---|---|---|
| **Connected** | Green | Data and orders are flowing |
| **Connecting** | Amber | Scalpel is trying; it retries by itself, every second at first and backing off to every 20 seconds |
| **Disconnected:** and a reason | Red | The last attempt failed; the reason comes from the connection |
| **Off** | Grey | You switched the link off. Scalpel stops retrying and hides the banner |

Click the pill to switch the link off or back on. **Off** is handy when you close TWS on purpose for the evening; it is remembered across restarts, so switch it back on next session. If a working connection drops, you get an **IB connection lost** toast and a spoken warning.

## The connection banner

While the link is down, Scalpel checks every 5 seconds which IBKR program is answering on this computer, on 7497 and 7496 for TWS and 4001 and 4002 for IB Gateway, and puts the answer in a banner under the header. There are four cases.

**The right program, on its other port.** Typical for a live TWS login on 7496. Click **Use port 7496**: Scalpel saves the new port and connects.

*Screenshot: TWS is up, but on 7496. Use port 7496 switches Scalpel to it in one click.*

**The other program is running.** You set Scalpel up for TWS but started IB Gateway, or the other way round. Click **Use IB Gateway** (or **Use TWS**).

*Screenshot: Scalpel expects TWS, but IB Gateway is the one running. One click switches over.*

**The program is up but will not let Scalpel in.** The port answers but the API handshake fails: usually TWS is showing a window asking whether to accept the connection, or its API settings do not allow connections from this computer. Check the API settings ([guide 1.5](https://scalpeltrade.com/guides/enable-tws-api), [guide 13.2](https://scalpeltrade.com/guides/fix-not-accepting-connection)).

*Screenshot: TWS is listening on 7497 but refuses the connection: turn on the API in its settings.*

**Nothing is running.** If TWS or IB Gateway is installed in its usual place, the banner offers **Start IB Gateway** and **Start TWS**. Scalpel starts it; you log in, and Scalpel connects by itself.

*Screenshot: Neither program is running. The Start buttons appear for whichever is installed in its default location.*

The **X** at the end of the banner hides it until the link next drops.

**Note.**

Scalpel finds TWS in `C:\Jts` and IB Gateway in `C:\Jts\ibgateway` on Windows (or a Jts folder in your user folder), and both in Applications on a Mac. Installed elsewhere, the Start buttons do not show; start the program yourself.

## What can go wrong

- **Connected, but no quotes or Level 2.** The link is fine; the market data is not. See [guide 1.6](https://scalpeltrade.com/guides/ibkr-market-data-for-day-trading) and [guide 13.4](https://scalpeltrade.com/guides/fix-delayed-data).
- **It connects, then drops every day.** TWS and IB Gateway restart or log out daily. Set auto-restart in their **Lock and Exit** settings; Scalpel reconnects by itself after a restart ([guide 13.1](https://scalpeltrade.com/guides/fix-disconnected)).
- **Logging in somewhere else signs you out.** One session per username: logging in to TWS on another computer, or to IBKR Desktop, ends the session Scalpel uses ([guide 13.3](https://scalpeltrade.com/guides/fix-tws-signed-out)).

**This can cost you money.**

Scalpel's stops are watched by Scalpel itself, not left at the broker. While the link is down, a LIVE position's stop cannot fire. If the pill goes red while you hold a LIVE position, get TWS back or close the position in TWS. See [guide 5.1](https://scalpeltrade.com/guides/how-stops-work).

## Questions

**What port does Scalpel use to connect to TWS?**

7497 by default. Set it in Settings, Connection, Port to whatever TWS or IB Gateway lists as its socket port: usually 7496 for a live TWS login, 7497 for paper, 4001 for IB Gateway live and 4002 for paper.

**Should I use TWS or IB Gateway with Scalpel?**

Either. IB Gateway is lighter and enough if Scalpel is your only trading screen. Use TWS if you also want its own windows. Interactive Brokers allows one session per username, so not both on one login.

**Does Scalpel need my Interactive Brokers password?**

No. You log in to TWS or IB Gateway yourself; Scalpel only talks to their API socket on your own computer.

**Can Scalpel connect to TWS on another computer?**

It is built to run on the same computer as TWS or IB Gateway, at 127.0.0.1. The connection banner and the Start buttons only look at this computer.

**Why does Scalpel keep saying Connecting?**

Nothing is answering on the port it is set to. Read the banner under the header: it says which program is running and on which port, and usually offers a one-click fix.
