Interactive Brokers
IBKR Client Portal Web API

Streaming WebSocket Data


Interactive Brokers Web API offers WebSocket streaming for market data, orders and pnl updates. To connect to the WebSocket follow the Getting Started Instructions to authenticate the gateway session. Once you receive the message "Client login succeeds" a websocket connection can now be established using the endpoint: wss://localhost:5000/v1/api/ws

There are two types of messages: Format for solicated message types: TOPIC+{ARGUMENTS}
Available Topics
Topic Definition
Solicated Message Types
smd+conid / umd + conid market data + contract identifier
sor / uor live orders
spl / upl profit and loss
ech+hb echo + heartbeat
Unsolicated Message Types
system system connection
sts status
ntf notification
blt bulletin


Try the websocket connection here:

Note: Make sure to first launch gateway and authenticate.

wss:// 





Solicited Message Types

Market Data (Level I)

Using the Web API, you can request real time data for trading and analysis. For streaming top of the book (level I) data, the topic is smd+conid. The conid (contract identifier) uniquely defines an instrument in IBKR's database and is needed for many endpoints. To find the conid for a stock, the endpoint /iserver/secdef/search can be used, for futures /trsrv/futures and for options there is an additional step described here. For the topic: smd+conid it is required to specify the argument fields. The field value is a JSON Object which are a comma separated list of available tick types as described in the endpoint /iserver/marketdata/snapshot. Additional field values can be added to an existing market data request by resending smd+conid. To unsubscribe from market data, the topic is umd+conid.

Format: smd+conid+{"fields":[]}

Format: umd+conid+{}


Live Orders

As long as an order is active, it is possible to retrive it using the Web API. For streaming live orders the topic is sor. When live orders are requested we will start to relay back updates. To receive all orders for the current day the endpoint /iserver/account/orders?force=false can be used. To unsubscribe from live orders, the topic is uor.

Format: sor+{}

Format: uor+{}

Live Order - Updates: When there is an update to your order only the change to the order is relayed back along with the orderId. Most commonly this would involve status changes and partial fills.

Profit and Loss

For existing positions it is possible to receive Profit and Loss updates to the Web API using the topic spl. In the payload response the daily profit and loss (dpl) and unrealized profit and loss (upl) are received as a total value for all positions. Updates are relayed back as quickly as once per second but can vary based on market activity. To unsubscribe from profit and loss the topic is upl.

Format: spl+{}

Format: upl{}


Echo

To maintain an active websocket connection the topic ech is used to send a hearbeat with the argument hb. It is advised to send a heatbeat at least once per minute.

Format: ech+hb



Unsolicited Message Types

System Connection

When initially connecting to websocket the topic system relays back a confirmation with the corresponding username. While the websocket is connecting every 10 seconds there after a heartbeat with corresponding unix time (in millisecond format) is relayed back.

Authentication Status

When connecting to websocket the topic sts will relay back the status of the authentication. Authentication status is already relayed back if there is a change, such as a competing sessions.

Notifications

If there is a brief message regarding trading activity the topic ntf will be sent.

Bulletins

If there is an urgent message concerning exchange issues, system problems and other trading information the topic blt is sent along with the message argument.


© Interactive Brokers 2020