Brokers
Interactive Brokers

Interactive Brokers (IBKR) Setup

IBKR integration uses the Client Portal Web API — a local REST API that runs alongside IB Gateway on your machine. This is the most powerful broker integration in Ordertune, with support for all order types including LOC (Limit on Close) and MOO (Market on Open).

⚠️

IB Gateway must remain running at all times for auto-execution to work. If it stops, Ordertune cannot submit orders.


Requirements

  • An Interactive Brokers account (ibkr.com)
  • IB Gateway installed on your machine (recommended over TWS)
  • An active Ordertune subscription

Step 1 — Install IB Gateway

Download IB Gateway from the IBKR website (opens in a new tab). IB Gateway is lighter than TWS (Trader Workstation) and designed for API use. Both work, but IB Gateway is preferred for automated trading.


Step 2 — Enable the Client Portal Web API

Launch IB Gateway

Start IB Gateway and log in with your IBKR credentials.

Open Configuration

In the IB Gateway menu bar, go to Configure → Settings (or Edit → Global Configuration in some versions).

Enable the API

Navigate to API → Settings in the Configuration panel. Enable the following:

  • Enable ActiveX and Socket Clients — check this box
  • Socket port — note the port number (default: 4001)
  • Allow connections from localhost only — leave enabled for local setups

Enable the Client Portal Web API

Still in the Configuration panel, locate API → Client Portal Web API (may also be called REST API Settings). Enable it. The default gateway URL will be https://localhost:5000.

Restart IB Gateway

Apply your changes and restart IB Gateway for the settings to take effect.


Step 3 — Authenticate via Browser

The Client Portal Web API requires an active browser session to stay authenticated.

Open the Gateway URL

After IB Gateway has restarted, open a browser and navigate to:

https://localhost:5000

Accept the SSL Certificate Warning

IB Gateway uses a self-signed SSL certificate. Your browser will show a security warning. Click Advanced → Proceed to localhost (or equivalent in your browser). This is expected and safe for a local connection.

Log In

You will see the IBKR Client Portal login page. Enter your IBKR credentials and complete any two-factor authentication. After logging in, the API session is active.

The Client Portal Web API session expires after a period of inactivity. You may need to re-authenticate periodically by revisiting https://localhost:5000.


Step 4 — Connect in Ordertune

Open Broker Settings

In Ordertune, go to Settings → Broker → Interactive Brokers.

Enter Gateway URL

Enter the IB Gateway URL. The default for local installations is:

https://localhost:5000

If you are running IB Gateway on a remote machine or VPS, enter the public URL with port (e.g., https://your-server-ip:5000).

Test Connection

Click Test Connection. Ordertune will make a request to your gateway and display your account balance if successful.


Remote / VPS Setup

If you want Ordertune (running in the cloud) to reach your IB Gateway (running on a VPS or home server):

  1. Run IB Gateway on a cloud VPS (Linux-compatible)
  2. Open port 5000 in your firewall
  3. In Ordertune Settings, enter your VPS's public IP: https://<vps-ip>:5000
  4. Consider placing a reverse proxy (nginx) in front of the gateway to enable HTTPS with a valid certificate
⚠️

Exposing IB Gateway to the public internet carries security risks. Restrict access by IP allowlist and ensure your IBKR account has appropriate trading restrictions enabled.


Supported Order Types

IBKR supports the full range of Ordertune order types:

Order TypeSupported
Market on Open (MOO)
Limit on Open (LMT OPG)
Market on Close (MOC)
Limit on Close (LOC)
Intraday Market
Intraday Limit

Troubleshooting

"Connection refused" error → IB Gateway is not running or the Client Portal API is not enabled. Restart IB Gateway and confirm the API settings.

SSL certificate error in Ordertune → Ordertune needs to trust IB Gateway's self-signed certificate. Some environments require you to add the cert to your system's trust store, or use a proxy with a valid cert.

"Not authenticated" error → Your browser session has expired. Go to https://localhost:5000 and log in again.

Orders not appearing in TWS → Confirm you connected with the account that holds your trading permissions. Paper and live accounts are separate in IBKR.