# Interactive Brokers

> Connect Interactive Brokers to TradeLabs by running TWS or IB Gateway locally with the API enabled, then adding the account in the Brokers page.

*Source: https://tradelabs.org/docs/reference/brokers/interactive-brokers*

Interactive Brokers connects through the Trader Workstation (TWS) or IB Gateway software running on the same computer as TradeLabs. TradeLabs talks to it over a local loopback connection, so there is no API key to paste. Keep TWS or IB Gateway signed in and running, and TradeLabs connects to it.

| What it trades | Supported |
| --- | --- |
| Stocks | Yes |
| Options | Yes |
| Spreads | Yes |
| Futures | Yes |
| RSA, crypto, memecoins | No |

TradeLabs uses port **7496** for a live account and **7497** for a paper account. Whichever mode you pick when adding the account, TWS or IB Gateway must be running in the matching mode.

> **Note**
>
> Interactive Brokers supports one connection per machine, so you add a single Interactive Brokers account.

## Before you start

- An Interactive Brokers account, funded on the Interactive Brokers website.
- An options market-data subscription (OPRA) on the Interactive Brokers side if you want real-time options quotes.
- TWS or IB Gateway installed on the same computer as TradeLabs.
- The TradeLabs Companion installed and running.

> **Note**
>
> If your balance is under $25,000, a cash account avoids Pattern Day Trader restrictions. Cash or margin is up to you and does not change how TradeLabs connects.

## Install TWS or IB Gateway

Download the IBKR Trader Workstation (TWS) or IB Gateway from the [Interactive Brokers TWS download page](https://www.interactivebrokers.com/en/trading/tws-updatable-latest.php) and install the build for your operating system. Sign in and keep it running whenever you want TradeLabs to trade.

## Enable the IBKR API

TradeLabs reaches Interactive Brokers through the TWS or IB Gateway API on a local socket. Enable the API in TWS so TradeLabs can connect.

*Enable socket clients, trust localhost, and confirm the port for your mode.*

Open the TWS API settings and:

- Enable the socket clients option so external applications can connect.
- Allow connections from the local machine (127.0.0.1).
- Confirm the socket port matches your mode: **7496** for live, **7497** for paper.

Keep TWS or IB Gateway running and signed in whenever you want TradeLabs to trade.

## Connect it in the app

Once TWS or IB Gateway is running with the API enabled, add the account in TradeLabs.

1. Open the **Brokers** page, find the **Interactive Brokers** card, and click **Add account**.
2. Set **Mode** to **Live** (real trading, port 7496) or **Paper** (practice, port 7497). Give the account a **Label** if you want a name that is easy to recognize.
3. Click **Save account**. TradeLabs connects to TWS or IB Gateway and checks the connection on its own.

![The Interactive Brokers connect form](/docs-assets/brokers-connect-ibkr.png)
*Set Mode to Live (port 7496) or Paper (port 7497) to match how TWS or IB Gateway is running*

To re-check the link later, open the account row menu and choose **Check connection**.

> **Heads up**
>
> Make sure the mode you pick here matches the mode TWS or IB Gateway is running in. A live account cannot reach a Gateway running in paper mode, and the reverse is also true.

## Fixing common problems

- **Connection fails:** confirm TWS or IB Gateway is running and signed in, the API socket clients option is enabled, and 127.0.0.1 is trusted.
- **Wrong port:** the mode you chose in TradeLabs must match the port TWS or IB Gateway is listening on (7496 live, 7497 paper).
- **Options quotes missing:** confirm your OPRA options market-data subscription is active on the Interactive Brokers side.
