๐ŸŽ“ Tutorials

How to Set Up IBKR API Paper Trading (2026)

โš ๏ธ Disclosure: Some links on this page are affiliate links. If you sign up through them, I may earn a commission โ€” at no extra cost to you. I only review tools I actually use.
Algorithmic traders and developers know the golden rule: never deploy untested code to a live account. The Interactive Brokers API is one of the most powerful trading interfaces in the industry, but its complexity means a single typo can cost real money.

IBKR API paper trading solves this. You get a simulated environment with virtual cash to validate your logic, test order routing, and debug connection issues without risking a single cent.

However, setting up the API for paper trading is not as straightforward as flipping a switch. It requires specific configurations in the Trader Workstation (TWS) or IB Gateway, correct API settings, and a clear understanding of how paper trading differs from live trading.

In this guide, I will walk you through the exact steps to set up IBKR API paper trading from scratch. Whether you are using Python, C#, or another supported language, these steps will get your environment running safely.

About this guide: I'm Lawrence, the writer behind supa.is. Between February and May 2026 I've published 150+ articles on supa.is across crypto and brokerage tooling โ€” including 30+ Interactive Brokers-specific guides (recent examples: IBKR Python API 2026, IBKR Paper Trading Setup, IBKR API Error Handling). The most-repeated reader question across that IBKR archive is exactly how to connect the API to the paper trading environment, which is why I'm publishing this standardized guide instead of answering one-off.

Why You Must Use IBKR API Paper Trading First

Before diving into the setup, here is why the IBKR API paper trading environment is non-negotiable for new algo traders.

1. The API Environment is Different from the Web UI

The IBKR web interface is designed for manual trading. The API, on the other hand, relies on precise order types, routing parameters, and state management. A script that works perfectly in the web UI might fail silently in the API if you don't account for API-specific constraints. Paper trading lets you discover these API quirks without financial consequences.

2. Testing Market Data Subscriptions

The IBKR API requires you to subscribe to market data before you can place orders or fetch real-time prices. If your subscription fails, your bot will trade on stale data or fail to execute. Paper trading allows you to test your data subscription logic and ensure your bot is actually receiving ticks.

3. Simulating Slippage and Partial Fills

While paper trading does not perfectly simulate real-world slippage (since it operates on a simulated order book), it does help you understand how the API handles order states, partial fills, and cancellations. This is crucial for debugging your order management logic.
Note: Steps below are reconstructed from official docs (linked). Verify each step against the current UI before relying on it.

Prerequisites: What You Need Before Starting

To set up IBKR API paper trading, you need the following:

  1. An Interactive Brokers Account: You can open a free account using our referral link to qualify for the $1,000 IBKR stock bonus.
  2. TWS or IB Gateway: The Trader Workstation (TWS) is the full-featured platform, while IB Gateway is a lightweight alternative designed specifically for API connections. For paper trading, IB Gateway is often preferred due to lower resource usage.
  3. API Client Language: Python is the most popular, but IBKR also supports Java, C++, C#, and more.

Step 1: Enable Paper Trading in TWS or IB Gateway

Switch your TWS or IB Gateway environment to paper trading. You don't need a funded account for this, but you will start with a simulated balance (usually $100,000 USD).

  1. Download and Install TWS or IB Gateway: If you haven't already, download the latest version of TWS or IB Gateway from the Interactive Brokers download page.
  2. Log In: Enter your username and password.
  3. Select Paper Trading:
- In TWS, you will see a toggle in the top right corner labeled "Live Trading" or "Paper Trading". Click it to switch to Paper Trading. - In IB Gateway, you must select the "Paper Trading" option during the login screen before entering your credentials.
  1. Wait for Initialization: It may take a few minutes for the paper trading environment to load. You will see the account balance update to your simulated funds.

Step 2: Configure API Settings

Once you are in the paper trading environment, you need to enable the API connection. This is where most beginners get stuck.

  1. Open Global Configuration:
- In TWS, go to File > Global Configuration > API > Settings. - In IB Gateway, the settings are usually on the login screen or accessible via the settings menu.
  1. Enable ActiveX and Socket Clients: Ensure the checkbox for "Enable ActiveX and Socket Clients" is checked.
  2. Set the Port: The default port is 7497. You can use this, or change it to a different port if you are running multiple instances of TWS/Gateway.
  3. Allow Connections from External Clients: If you are running your API script on a different machine than TWS/Gateway, you must check "Allow connections from external clients" and enter the IP address of the machine running your script. If both are on the same machine, leave this unchecked.
  4. Apply and Restart: Click "Apply" and "OK". You will be prompted to restart TWS/Gateway for the changes to take effect.

Step 3: Set Up Your API Environment (Python Example)

Now that TWS/Gateway is configured, it's time to set up your local development environment. Python is the easiest language to start with, thanks to the ibapi package provided by Interactive Brokers.

  1. Install the ibapi package:
   pip install ibapi
   
  1. Verify Installation: Open a Python shell and try importing the library:
   from ibapi.client import EClient
   from ibapi.wrapper import EWrapper
   
  1. Create a Basic Connection Script:
Here is a minimal script to test your connection:

   from ibapi.client import EClient
   from ibapi.wrapper import EWrapper
   from ibapi.common import *
   import time

   class TestApp(EWrapper, EClient):
       def __init__(self):
           EWrapper.__init__(self)
           EClient.__init__(self, self)

       def error(self, reqId, errorCode, errorString):
           print(f"Error: {reqId} - {errorCode} - {errorString}")

       def nextValidId(self, orderId):
           print(f"Next valid order ID: {orderId}")

   if __name__ == "__main__":
       app = TestApp()
       app.connect("127.0.0.1", 7497, 0)
       app.run()
   

Run this script. If you see "Next valid order ID: 1" (or a higher number), your API connection to the paper trading environment is successful.

Step 4: Request Market Data

Your API script must subscribe to market data before placing orders. This is mandatory in the IBKR API.

๐Ÿ’ก Interactive Brokers

Like what you're reading? Try it yourself โ€” this link supports ChartedTrader at no cost to you.

Open an IBKR Account โ†’

  1. Define the Contract: You need to specify the instrument you want to trade. For example, Apple stock (AAPL):
   from ibapi.contract import Contract

   contract = Contract()
   contract.symbol = "AAPL"
   contract.secType = "STK"
   contract.exchange = "SMART"
   contract.currency = "USD"
   

  1. Request Market Data: Use the reqMktData method to subscribe to real-time prices:

   reqId = 1
   app.reqMktData(reqId, contract, "", False, False, [])
   

  1. Handle Market Data Updates: You will need to implement the tickPrice method in your EWrapper class to receive the data:

   def tickPrice(self, reqId, tickType, price, attrib):
       print(f"Tick Price: {reqId} - {tickType} - {price}")
   

Run your script again. You should start seeing a stream of price ticks for AAPL. If you don't, double-check that you have the necessary market data subscriptions enabled in your TWS account (even for paper trading, some data feeds require a subscription).

Step 5: Place a Test Order

With a connection and market data, you're ready to place a simulated order.

  1. Define the Order: Create an order object. For a simple market buy:
   from ibapi.order import Order

   order = Order()
   order.action = "BUY"
   order.orderType = "MKT"
   order.totalQuantity = 1
   

  1. Place the Order: Use the placeOrder method:

   orderId = app.nextValidOrderId
   app.placeOrder(orderId, contract, order)
   

  1. Monitor Order Status: Implement the orderStatus method to track the order:

   def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld, mktCapPrice):
       print(f"Order Status: {orderId} - {status} - Filled: {filled}")
   

If everything is set up correctly, you should see the order status change to "Filled" almost instantly. Check your paper trading account balance in TWS to confirm the trade was executed.

Common Pitfalls and How to Avoid Them

The setup is straightforward, but a few common issues can trip you up.

1. "Market Data Not Subscribed" Error

This is the most common error. Even in paper trading, you need to have market data subscriptions active. If you don't have a paid data subscription, you can still trade stocks and options with delayed data, but you must explicitly request delayed data in your API script by setting conId appropriately or using the genericTickList parameter in reqMktData.

2. Port Conflicts

If you are running multiple instances of TWS or IB Gateway, they will conflict on the default port 7497. Make sure to change the port in the API settings of each instance to a unique number (e.g., 7498, 7499).

3. TWS/Gateway Not Fully Loaded

When you first switch to paper trading, TWS/Gateway needs a few minutes to load all the data feeds and initialize the simulated order book. If you try to connect your API script too early, you will get connection errors. Wait until you see your paper trading account balance and positions in the UI before connecting.

4. Using the Wrong Exchange

When defining your contract, make sure you use the correct exchange. For US stocks, "SMART" is usually the best choice as it routes your order to the best available exchange. Using a specific exchange like "NASDAQ" or "NYSE" can result in routing errors or failed orders if the symbol is not listed there.

Paper Trading vs. Live Trading: Key Differences

Paper trading has limitations. Don't let it give you a false sense of security.

FeaturePaper TradingLive Trading
CapitalSimulated (usually $100k)Real funds
Order ExecutionInstant, no slippageSubject to market conditions
LiquidityUnlimitedReal-time market depth
FeesNoneReal commissions and fees
Market DataMay be delayed if unsubscribedReal-time (if subscribed)
API Rate LimitsRelaxedStrict
Because paper trading does not account for slippage, liquidity, or fees, a strategy that looks profitable in paper trading might lose money in live trading. Always use paper trading to validate your logic, but never deploy a strategy to live trading without first backtesting it against historical data and adjusting for real-world costs.

Advanced Tip: Using IB Gateway for Headless API Trading

If you are running your API script on a server or a machine without a monitor, IB Gateway is the way to go. It is designed to be lightweight and can run in the background.

  1. Download IB Gateway: Available from the same Interactive Brokers download page.
  2. Run in Headless Mode: IB Gateway can be configured to run without a GUI. You can pass command-line arguments to start it automatically with your paper trading credentials.
  3. Set Up Auto-Login: For security, you can use IBKR's two-factor authentication (2FA) via the IBKR Mobile app, but for API automation, you may want to set up a static IP address and use the "Allow connections from external clients" feature to avoid manual login every time.

Conclusion

Paper trading is the only safe way to test your code, debug connection issues, and validate your strategy. Once you've got your environment running, remember that it's not a perfect simulation. Always backtest your strategies against historical data and account for real-world costs before going live.

If you are ready to start trading with Interactive Brokers, you can open a free account using our referral link and qualify for the $1,000 IBKR stock bonus.

FAQ

Can I use IBKR API paper trading without a funded account?

Yes. Paper trading does not require you to deposit real funds. You will start with a simulated balance (usually $100,000 USD) that resets when you log out or after a certain period.

Is the data in paper trading real-time?

It depends on your market data subscription. If you have a paid data subscription, you will receive real-time data in paper trading. If you don't, you will receive delayed data (typically 15 minutes behind).

Can I run multiple API scripts connected to the same paper trading account?

Yes, but you need to be careful with order ID management. Each script must use a unique clientId when connecting to TWS/Gateway to avoid conflicts. You can set the clientId in the EClient constructor.

Why am I getting a "Market Data Not Subscribed" error?

This usually means you don't have the necessary market data subscriptions enabled in your TWS account. Even for paper trading, some data feeds require a subscription. You can check your subscriptions in TWS under File > Global Configuration > Market Data.

How do I switch from paper trading to live trading?

To switch to live trading, you must log out of paper trading, deposit real funds into your account, and then log in using the "Live Trading" option in TWS or IB Gateway. Make sure to update your API script to connect to the live environment and use the correct account ID.

Risk Warning

Risk Warning: Crypto trading involves substantial risk of loss. Never invest more than you can afford to lose. This is not financial advice.

๐Ÿงฎ Free IBKR calculator

IBKR Margin Calculator โ†’
Reg-T initial / maintenance / margin call price + IBKR Pro interest cost
Interactive Brokers

Ready to get started? Use the link below โ€” it helps support ChartedTrader at no cost to you.

Open an IBKR Account โ†’
๐Ÿ“ˆ

About the author

I'm a systematic trader running live strategies on IB (USDJPY momentum) and Hyperliquid (crypto perps). Every tool reviewed here is something I've used with real capital. Questions? Reach out.

๐Ÿ“š Related Articles

๐Ÿ“ˆ
Strategy & Systems

Interactive Brokers Python API: Momentum Strategy (2026)

Build a monthly seasonal momentum model on USDJPY using IBKR's TWS API and Python. Includes code, risk gates, and common pitfalls for algo traders.

February 23, 2026 โฑ 13 min read
๐Ÿฆ
Brokers & Exchanges

IB Python API 2026: Build a Live Trading System

ib_insync vs ibapi vs ib-async for IBKR Python automation in 2026: which library handles 24/7 live trading without dropping orders, the connection-recovery pattern that survives nightly resets, and a working strategy template.

February 27, 2026 โฑ 13 min read
๐Ÿฆ
Brokers & Exchanges

Interactive Brokers TWS API: 'Market Data Not Subscribed' โ€” How to Fix Every Cause (2026)

Getting error 354 'Requested market data is not subscribed' from the IB TWS API? This guide covers every cause โ€” missing subscriptions, paper trading quirks, wrong contract definitions, and reqMarketDataType settings โ€” with exact fixes from a production algo trading system.

March 28, 2026 โฑ 12 min read