Guide 1.5
Beginner, 5 min read. Checked with Scalpel 1.12.8 on .
In short
In TWS, open the global configuration, go to API > Settings, tick Enable ActiveX and Socket Clients, untick Read-Only API, keep Allow connections from localhost only ticked and note the Socket port. In IB Gateway the same page is under Configure > Settings > API > Settings, with the socket always on. Then set the same port in Scalpel's Settings > Connection > Port (7497 by default for TWS, 4001 for IB Gateway) and click Apply.
TWS and IB Gateway ship with the API closed or read-only, so a fresh install will not talk to Scalpel until you change three or four settings. You do this once; both programs remember it.
Before you start
In TWS, open File > Global Configuration (in the Classic layout, Edit > Global Configuration). In the tree on the left, expand API and click Settings. Scalpel's connection banner calls this page Configure > API > Settings.
This opens the socket Scalpel connects to 1. Without it, nothing answers on the port and Scalpel's banner says neither TWS nor IB Gateway is running.
With Read-Only API ticked 2, Scalpel can read data and your account but every LIVE order is refused. SIM works either way, because SIM orders never reach IBKR. Untick it before you trade LIVE; leave it ticked while you only practise if you prefer the extra lock.
Socket port 3 is the number Scalpel must use. TWS suggests 7496 after a live login and 7497 after a paper one. Either set it to 7497 (Scalpel's default) or leave it and set Scalpel to match in the last step.
Leave Allow connections from localhost only ticked 4. Scalpel runs on the same computer and connects from 127.0.0.1, which this always allows, and nothing else on your network can reach your account. If you ever untick it, add 127.0.0.1 to Trusted IPs 5 with Create, or TWS asks you to accept every connection.
Leave Master API client ID empty.
TWS applies the settings at once; no restart needed.
IB Gateway always has its socket open, so there is no Enable ActiveX checkbox. The rest is the same:
Open Settings (Ctrl+,) > Connection. Set Port to the socket port you noted: 7497 or 7496 for TWS, 4001 or 4002 for IB Gateway. Keep Host at 127.0.0.1. Click Apply; Scalpel reconnects at once, and the IBKR pill in the status bar turns green.
These are optional, but traders who skip them meet the problems later:
| Setting (TWS or IB Gateway) | Change it to | Why |
|---|---|---|
| Lock and Exit: auto restart | On, at a time you never trade | Both programs log out daily otherwise, and Scalpel loses its connection until you log back in |
| API > Precautions | Review the order precautions | TWS can hold back API orders with its own size and price warnings. Scalpel has its own caps (guide 7.2) |
| Other API tools | Do not reuse Scalpel's client IDs | Scalpel opens several API connections with client IDs 1, 2, 10 and 70 to 72 (100 and up with data recording on). Another tool on the same ID knocks one of them off |