Interactive Brokers

Global equities, options, futures, forex via TWS / IB Gateway. Connect with one line.

Interactive Brokers is the institutional workhorse: global equities, options, futures, forex, bonds, structured products. The Horizon venue wraps ib_async which speaks the TWS / IB Gateway socket API.

Prerequisites

  1. TWS or IB Gateway running locally (download from IB).
  2. Enable the API in Global Configuration → API → Settings:
    • Enable ActiveX and Socket Clients.
    • Socket port: 7497 for TWS paper, 7496 TWS live, 4002 IB Gateway paper, 4001 IB Gateway live.
    • Trusted IPs: add 127.0.0.1.

Connect

python
import horizon as hz

ex = hz.connect("ibkr",
    host="127.0.0.1",
    port=4002,                    # IB Gateway paper
    client_id=1,
)
ex.buy("AAPL", qty=10, limit=180.0)
print(ex.balance())
ex.close()

No API keys — IBKR authenticates via the desktop app session. Rotate sessions, not keys.

Kwargs

KwargTypeDefaultNotes
hoststr"127.0.0.1"Where TWS / Gateway is listening.
portint4002See port table above.
client_idint1Unique per connection. Collisions disconnect the earlier client.
accountstr \| NoneNoneFor master accounts; sub-account the orders flow to.
timeout_sfloat5.0Connect timeout.
ibAnyNoneInject a pre-built ib_async.IB instance (tests).

Install

bash
pip install horizon[ibkr]
# or
pip install ib_async

Status

  • Equities, options, futures, forex submit / cancel: shipped.
  • Market data subscriptions: shipped (delayed free, real-time paid).
  • Bracket / OCO, algo parents (VWAP, TWAP, IBALGO): follow-up.

Full integration notes — contract qualification, symbology, market-data entitlements, error codes: IBKR (professionals).