Guide

Connect ANT to IB Gateway.

Four steps, from signing in to IB Gateway to your first order on an IBKR Paper account. IB Gateway is Interactive Brokers' own small program; ANT sends your orders through it, on this computer only.

ANT is still in developmentANT is not a finished product. It can contain errors, and it can stop working. You use ANT at your own risk, and you are responsible for every order sent from your account.

What you need

  • ANT installed on your computer.
  • Your own Interactive Brokers account, with its Paper Trading account.
  • IB Gateway, downloaded from Interactive Brokers' own website and running on the same computer as ANT.

The four ports

4002
IB Gateway, Paper
4001
IB Gateway, Live
7497
TWS, PaperANT's default broker port.
7496
TWS, Live

These are Interactive Brokers' default numbers. The port only says where ANT connects. ANT decides Paper or Live from the account itself, never from the port.

1. Sign in to IB Gateway

  1. Open IB Gateway.
  2. Choose IB API, not FIX CTCI.
  3. Choose Paper Trading for your first sessions.
  4. Type your Interactive Brokers username and password and finish the two-factor login.

You sign in, in Interactive Brokers' own window. ANT never asks for your Interactive Brokers username or password and stores neither.

Illustration of the IB Gateway sign-in window with IB API and Paper Trading selected.
Illustration, not a screenshot. The real windows look different, and Interactive Brokers can change its menus.

2. Check the API settings

In IB Gateway, open the API settings. In current versions they are under Configure, Settings, API, Settings.

  1. Read-Only API: off. Interactive Brokers turns it on by default, and while it is on IB Gateway accepts no orders from ANT.
  2. Socket port: note the number. It is 4002 for Paper and 4001 for Live unless you changed it.
  3. Allow connections from localhost only: on. ANT connects from this computer (127.0.0.1) and from nowhere else.

Turning Read-Only API off lets any program on this computer that reaches this port send orders to your account. Keep the localhost-only setting on.

Illustration of the IB Gateway API settings: Read-Only API off, socket port 4002, localhost only.
Illustration, not a screenshot. The real windows look different, and Interactive Brokers can change its menus.

3. Connect from ANT

In ANT, open Settings, Broker & Accounts.

  1. Account ID: type your own account ID. A Paper account starts with DU, a Live account with U. ANT only accepts the account you typed.
  2. Broker port: change it to the socket port from step 2. ANT starts on 7497, the TWS Paper port, so for IB Gateway you type 4002.
  3. Broker client ID and host: leave them as they are (118 and 127.0.0.1) unless ANT tells you the client ID is already in use.
  4. Press Check port. ANT says whether something is listening on that port.
  5. Press Connect and verify.
Illustration of ANT's Broker and Accounts settings with account ID, broker port 4002, client ID 118 and host 127.0.0.1.
Illustration, not a screenshot. The real windows look different, and Interactive Brokers can change its menus.

4. Read the status, then trade

  • PAPER VERIFIED, CONFIRM: ANT recognised a Paper account. Confirm it once, then turn on IBKR Paper orders for this session.
  • IBKR PAPER, CONFIRMED: the Paper account is confirmed. Once its orders are turned on for the session, you can send Paper orders.
  • LIVE ACCOUNT DETECTED: IB Gateway is signed in to your real account. LIVE trading becomes ready by itself once ANT's account checks pass.
  • NOT CONNECTED or ERROR: nothing can be sent. See the fixes below.

An order is sent only when you send it, from the ticket or with a hotkey you have set up. Trading hotkeys have no keys until you assign them.

Illustration of ANT's Interactive Brokers status labels for Paper, Live and not connected.
Illustration, not a screenshot. The real windows look different, and Interactive Brokers can change its menus.

Before you connect a LIVE account

  • On LIVE, a BUY or SELL hotkey sends a real order with one press, with no confirmation.
  • ANT sets no limit on order size on LIVE.
  • ANT places no protective stop and has no emergency stop button.
  • You are responsible for every order sent from your account.

Read the draft Risk Disclosure. Practise on your Paper account first and start with small size.

If it does not connect

  • Check port says nothing is listening: IB Gateway is not running, is not signed in, or uses a different socket port.
  • Client ID already used: choose another broker client ID in ANT.
  • Connected but orders are refused: Read-Only API is still on in IB Gateway.
  • Wrong account: the account ID you typed in ANT must be the account IB Gateway is signed in to.
  • It worked yesterday: IB Gateway is designed to restart every day and asks you to sign in again from time to time. Sign in again, then connect in ANT.

Still stuck? Ask in the Discord community or write to us. Never post your account ID, username or password.

ANT is not affiliated with Interactive Brokers. IB Gateway and Trader Workstation are Interactive Brokers' programs; for anything about them, their own documentation is the authority.