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
- TWS or IB Gateway running locally (download from IB).
- Enable the API in Global Configuration → API → Settings:
- Enable ActiveX and Socket Clients.
- Socket port:
7497for TWS paper,7496TWS live,4002IB Gateway paper,4001IB 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
| Kwarg | Type | Default | Notes |
|---|---|---|---|
host | str | "127.0.0.1" | Where TWS / Gateway is listening. |
port | int | 4002 | See port table above. |
client_id | int | 1 | Unique per connection. Collisions disconnect the earlier client. |
account | str \| None | None | For master accounts; sub-account the orders flow to. |
timeout_s | float | 5.0 | Connect timeout. |
ib | Any | None | Inject 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).