IB Gateway vs. TWS
- IB Gateway is an alternative to TWS that is geared entirely towards API functionality without a GUI for account information.
- Both programs are nearly identical from an API perspective.
- Equivalent versions of TWS and IB Gateway are always released together.
- IB Gateway requires fewer resources and is a smaller application.
Installing TWS
- Download and Install:
- Run the installer from the Interactive Brokers website.
- A new icon will be created on the desktop after installation.
- Login:
- Double-click the TWS icon to bring up the login screen.
- Enter your username and password.
- Choose to log in to either your live or paper account.
- If you don’t have an IB account, you can try the demo by clicking “Try the Demo” and using an email address.
Configuring TWS for API Use
- Initial Login:
- Fully log into TWS and let it load completely.
- Enable API Connection:
- Go to Global Configuration.
- Navigate to
API->Settings. - Check the box labeled “Enable ActiveX and Socket Clients”.
- Socket Port Settings:
- Default ports:
- TWS: 7496 for live sessions, 7497 for paper sessions.
- IB Gateway: 4001 for live sessions, 4002 for paper sessions.
- Ensure the socket port in TWS matches the port used in the API client’s
connect()function.
- Default ports:
- Connection Settings:
- Check “Allow Connections from Localhost Only” to:
- Only accept incoming connections from API applications on the same computer.
- Avoid the need to manually accept incoming API connections.
- Check “Allow Connections from Localhost Only” to:
API Logging
- Enable API Message Log:
- Create an API log file by enabling “Create API Message Log”.
- Include market data in the log by checking “Include market data in API log file”.
- Set the “Logging Level” to “Detail” for comprehensive logging of all API traffic.
Order Settings
- Global Configuration:
- Read-Only: By default, it is enabled and will block all API orders. Uncheck it to allow orders from the API.
- Precautions: Certain orders may not transmit by default if they exceed precautionary settings until manually confirmed in TWS.
- Some order attributes not settable from the API can be configured in TWS, e.g., “Active order in pre-open session”.