Brokers
↳ Quick Start (CP Gateway)

Quick Start — CP Gateway

This method uses the IBKR Client Portal Web API (CP Gateway) — a local web server that IB Gateway runs on your machine. When you click "Confirm Buy" or "Confirm Sell" in Ordertune, your browser connects directly to the gateway running on localhost:5000 and submits the order.

Why it works: IBKR's same-machine constraint requires API calls to come from the same IP address as the authenticated browser session. Since your browser and the CP Gateway are both on your machine, this constraint is satisfied naturally.

⚠️

You must be logged into the CP Gateway browser session whenever you want to execute orders. If the session expires or IB Gateway is closed, order execution will fail until you re-authenticate.


Prerequisites

  • IB Gateway installed on your machine
  • An active Ordertune subscription with 2FA enabled
  • Your browser running on the same machine as IB Gateway

Step 1 — Install IB Gateway

Download and install IB Gateway from interactivebrokers.com (opens in a new tab).

IB Gateway is a lighter alternative to TWS (Trader Workstation). It is designed for API-driven use and runs without a full trading GUI.


Step 2 — Enable the Client Portal Web API

Launch IB Gateway

Open IB Gateway and log in with your IBKR credentials and two-factor authentication.

Open Settings

In the IB Gateway menu bar: Configure → Settings (some versions show Edit → Global Configuration).

Enable the REST API

Navigate to API → Settings. Enable:

  • Enable ActiveX and Socket Clients — required for the socket API (TWS API)
  • Socket port — default 4001 for live, 4002 for paper

Then navigate to API → Client Portal Web API (may appear as REST API in some versions). Enable it. The default URL is:

https://localhost:5000

Restart IB Gateway

Apply the changes and restart IB Gateway.


Step 3 — Configure CORS (required)

IB Gateway blocks cross-origin requests by default. You need to add platform.ordertune.com as an allowed origin so your browser can send requests from the Ordertune page to your local gateway.

Find the IB Gateway config directory

The configuration file is typically at:

  • Windows: C:\Jts\ibgateway\<version>\root\conf.yaml
  • macOS: ~/Jts/ibgateway/<version>/root/conf.yaml
  • Linux: ~/Jts/ibgateway/<version>/root/conf.yaml

Edit conf.yaml

Add or update the cors section:

cors:
  allowed_origins:
    - https://platform.ordertune.com

If conf.yaml does not exist yet, create it in the root/ folder with the content above.

Restart IB Gateway

Changes take effect after a full restart.

If you do not configure CORS, order execution will fail with a CORS error when Ordertune's dashboard page tries to reach your local gateway.


Step 4 — Authenticate the browser session

Open the gateway URL

In your browser, navigate to:

https://localhost:5000

Accept the SSL warning

IB Gateway uses a self-signed certificate. Your browser will show a security warning. Click Advanced → Proceed to localhost (exact wording varies by browser). This is expected and safe.

Log in

Enter your IBKR credentials and complete two-factor authentication. Once logged in, the CP Gateway session is active.

⚠️

The CP Gateway session expires after 24 hours of inactivity (or when you close IB Gateway). You must re-authenticate by visiting https://localhost:5000 in your browser before executing orders the next day.


Step 5 — Connect in Ordertune Settings

Open Settings

In Ordertune, go to Settings → Broker.

Select Interactive Brokers — Quick Start

In the broker selector, choose Interactive Brokers and then select the Quick Start option.

Enter your Gateway URL

The default is:

https://localhost:5000

Use this default unless you changed the port in IB Gateway settings.

Toggle Paper Trading (optional)

Enable the Paper Trading toggle if you want to connect to your IBKR paper account instead of your live account. Make sure you also authenticated with your paper credentials in Step 4.

Save

Click Connect Broker. Your broker is now configured.


How order execution works

When you click Confirm Buy or Confirm Sell on a signal in Ordertune's dashboard:

  1. Ordertune's server calculates the order parameters (symbol, quantity, price) and returns them to your browser
  2. Your browser resolves the IBKR contract ID for the symbol
  3. Your browser submits the order directly to https://localhost:5000/v1/api/iserver/account/.../orders
  4. The result (order ID or error) is sent back to Ordertune's server for logging

All IBKR API calls happen browser-to-localhost — the Ordertune server never directly contacts your gateway.


Paper trading

Paper trading uses the same flow with a separate IBKR paper account. In IB Gateway, log in with your paper credentials (the same IBKR username, but select "Paper Trading" at login). The CP Gateway URL remains the same (https://localhost:5000). In Ordertune Settings, enable the Paper Trading toggle when connecting.


Troubleshooting

CORS error when executing orders → The platform.ordertune.com origin is not in your CP Gateway CORS config. Add it to conf.yaml and restart IB Gateway (see Step 3 above).

"CP Gateway returned 401. Is it authenticated?" → Your browser session has expired. Navigate to https://localhost:5000 and log in again.

"Could not fetch account from CP Gateway. Is it running?" → IB Gateway is not running, or the CP Gateway REST API is not enabled. Start IB Gateway, confirm the API is enabled in settings, and re-authenticate.

"No IBKR contract found for [ticker]" → The symbol could not be resolved to an IBKR contract. Confirm you have US equity market data permissions on your IBKR account.

Connection test says "connected" but orders fail → The connection test only verifies that a broker connection record exists in Ordertune. Actual CP Gateway connectivity is verified at order execution time. Ensure the gateway is running and authenticated.