Guide 13.1
Beginner, 4 min read. Checked with Scalpel 1.12.8 on .
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.
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.
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.
In TWS: Configure > API > Settings > Enable ActiveX and Socket Clients. In IB Gateway: Configure > Settings > API. Every screen is in guide 1.5.
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.
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).
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").
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.
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.
The same happens for IB Gateway on 4001 (live) and 4002 (paper).
You run the other program. Click Use IB Gateway (or Use TWS) to switch.
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.
The port is open but the API refuses Scalpel. See guide 13.2.
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). 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.
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.