# Scalpel says Disconnected: fix the IBKR connection

> Scalpel cannot reach TWS or IB Gateway? Check the program is running and logged in, the API is on and the port matches, and use the banner's fix.

Source: https://scalpeltrade.com/guides/fix-disconnected
Guide 13.1, Troubleshooting. Beginner, 4 min read.
Checked with Scalpel 1.12.8 on 2026-10-15. By Scalpel Team.

**In short:**

Scalpel reaches Interactive Brokers only through TWS or IB Gateway running and logged in on the same computer, with the API switched on and its socket port matching **Settings** > **Connection** > **Port**. While the link is down, a banner under the header says which program it found (TWS on 7497 or 7496, IB Gateway on 4001 or 4002) and offers a one-click fix: **Use port 7496**, **Use IB Gateway** or **Start TWS**.

The **IBKR** pill at the bottom left of the status bar shows the link. Anything other than **Connected** means no quotes, no Level 2 and no orders.

*Screenshot: The IBKR pill's four states. Click it to switch the link off or on. Demo data.*

The text after **Disconnected:** is the reason your computer gave. On Windows, "No connection could be made because the target machine actively refused it" means nothing is listening on that port: the program is closed, still logging in, or on another port.

## Check these first

### 1. Log in to TWS or IB Gateway

Start TWS or IB Gateway on this computer and finish logging in, including the two-factor approval on your phone. The API only opens once the login is complete.

### 2. Turn the API on

In TWS: **Configure** > **API** > **Settings** > **Enable ActiveX and Socket Clients**. In IB Gateway: **Configure** > **Settings** > **API**. Every screen is in [guide 1.5](https://scalpeltrade.com/guides/enable-tws-api).

### 3. Match the port

The **Socket port** there must equal **Port** in Scalpel's **Settings** > **Connection**. Scalpel starts on 7497 for TWS and 4001 for IB Gateway. Change either side, then click **Apply**: Scalpel reconnects without a restart.

### 4. Make sure the pill is not Off

**Off** (grey) means you switched the link off. Click the pill, or tick **Enabled** next to **IBKR TWS** in Settings > Connection. While it is off, Scalpel does not retry and shows no banner.

Then read the banner under the header. It is checked every 5 seconds while the link is down, and only when **Host** is this computer (127.0.0.1).

## Neither TWS nor IB Gateway is running on this machine. Start one and log in; Scalpel connects by itself.

Nothing answers on 7497, 7496, 4001 or 4002. If Scalpel finds TWS or IB Gateway installed in its usual place, the banner offers **Start TWS** or **Start IB Gateway**. Click one, log in, and Scalpel connects by itself ("Starting TWS: log in, then Scalpel connects").

*Screenshot: Nothing running: the banner offers to start what is installed, and the pill reads Disconnected. Demo data.*

If TWS is running and logged in but you still see this, its API is off or uses a port outside the four standard ones. Turn the API on, or type its port into Settings > Connection.

## TWS is not answering on port 7497, but it is running on port 7496.

The most common one. Interactive Brokers sets TWS to port 7496 for a live login and 7497 for a paper login; Scalpel starts on 7497. Click **Use port 7496** (1): Scalpel saves the port and connects ("Connecting to TWS on port 7496"). Or change TWS's socket port to 7497.

*Screenshot: One click switches Scalpel to the port TWS is really using (1). Demo data.*

The same happens for IB Gateway on 4001 (live) and 4002 (paper).

## TWS is not answering on port 7497, but IB Gateway is running on port 4001.

You run the other program. Click **Use IB Gateway** (or **Use TWS**) to switch.

*Screenshot: The other program is up: switch to it. Demo data.*

With a custom port the banner reads "Nothing answers on port 7500, but IB Gateway is running on port 4001." and offers the same switch.

## TWS is running on port 7497 but is not accepting the connection.

The port is open but the API refuses Scalpel. See [guide 13.2](https://scalpeltrade.com/guides/fix-not-accepting-connection).

## Disconnected mid-session: IB connection lost

An amber toast **IB connection lost** and a spoken alert mean the link dropped while you were trading: TWS or IB Gateway closed, restarted (both restart once a day unless you set auto-restart), or another login took the session ([guide 13.3](https://scalpeltrade.com/guides/fix-tws-signed-out)). Scalpel retries by itself, every few seconds and at least every 20, and picks your LIVE positions back up from Interactive Brokers when it reconnects.

**This can cost you money.**

While the link is down, Scalpel gets no prices, so it cannot see your stop being hit, and it cannot send orders. Your LIVE position is still open at Interactive Brokers. If you cannot reconnect quickly, manage it in TWS or the IBKR app. See [guide 5.1](https://scalpeltrade.com/guides/how-stops-work).

## Disconnected: TWS refused the connection (client id in use?), retrying

TWS turned the connection away. Usually a second copy of Scalpel is open, another API program on this computer uses the same client ids, or Scalpel restarted a moment ago and TWS has not released the old connection yet. Close the other copy or program; otherwise wait a minute, and Scalpel retries by itself.

## Questions

**Why does Scalpel say Disconnected when TWS is open?**

TWS must be fully logged in with Enable ActiveX and Socket Clients ticked, and its socket port must match Settings > Connection > Port. Live TWS uses 7496 by default and Scalpel starts on 7497: click Use port 7496 on the banner.

**Which port does Scalpel use?**

7497 for TWS and 4001 for IB Gateway at first. Interactive Brokers' defaults are TWS 7496 live and 7497 paper, IB Gateway 4001 live and 4002 paper. Scalpel checks all four and offers to switch.

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

Scalpel is built to run next to TWS or IB Gateway on the same computer, and the banner's checks only work for 127.0.0.1.

**Do my stops work while Scalpel is disconnected?**

No. Stops are watched by Scalpel and need live prices. The position stays open at Interactive Brokers, so manage it in TWS if the link does not come back.
