CodeForFinance
Broker API

Interactive Brokers API Review for Algo Trading

Interactive Brokers (IBKR) is the most popular broker for algorithmic traders. Their Trader Workstation (TWS) API allows you to execute trades, receive real-time market data, and manage your portfolio programmatically. The ib_insync Python library by Ewald de Wit makes the API significantly easier to use. IBKR offers access to 150+ markets across 33 countries.

Pricing

IBKR LiteFree commissions on US stocks
  • No account minimum
  • Free US stock trades
  • Limited API access
  • Basic market data
IBKR Pro$0.005/share (min $1)
  • Full API access
  • Professional market data
  • Direct market routing
  • All order types
Market Data$1-$35/month per exchange
  • Real-time Level 1
  • Level 2 depth
  • Streaming quotes
  • Historical data

Pros

  • + Access to 150+ global markets
  • + Very low commissions
  • + ib_insync makes Python integration easy
  • + Paper trading account for testing
  • + Supports complex order types (brackets, algos, etc.)

Cons

  • - TWS must be running for API access (or use IB Gateway)
  • - Connection can be flaky and needs reconnection logic
  • - Market data subscriptions add up quickly
  • - API documentation is complex and sometimes outdated
  • - Learning curve is steep for beginners

Who Is It For?

IBKR is for serious algorithmic traders who want to automate their trading with real money. If you are building a trading bot that needs to execute orders across multiple markets, IBKR is the industry standard. Not for beginners who are still learning to code.

Code Example

# Using ib_insync (recommended Python library)
# pip install ib_insync

from ib_insync import *

# Connect to TWS or IB Gateway
ib = IB()
ib.connect("127.0.0.1", 7497, clientId=1)  # 7497 for paper trading

# Get account summary
account = ib.accountSummary()
for item in account:
    if item.tag in ["TotalCashValue", "NetLiquidation", "UnrealizedPnL"]:
        print(f"{item.tag}: {item.value} {item.currency}")

# Get real-time market data
contract = Stock("AAPL", "SMART", "USD")
ib.qualifyContracts(contract)

# Request market data
ticker = ib.reqMktData(contract)
ib.sleep(2)  # Wait for data
print(f"AAPL: {ticker.marketPrice()}")

# Historical data
bars = ib.reqHistoricalData(
    contract,
    endDateTime="",
    durationStr="30 D",
    barSizeSetting="1 day",
    whatToShow="MIDPOINT",
    useRTH=True
)
df = util.df(bars)
print(df.tail())

# Place an order
order = LimitOrder("BUY", 10, 190.00)
trade = ib.placeOrder(contract, order)
print(f"Order status: {trade.orderStatus.status}")

# Cancel order
ib.cancelOrder(order)

ib.disconnect()

Alternatives

AlpacaTD Ameritrade APITradier

Recommended Reading

Algorithmic Trading with Python →

As an Amazon Associate we may earn from qualifying purchases.

Browse All Tools →

Developer Essentials

As an Amazon Associate we may earn from qualifying purchases.