WebSocket Streaming¶
Our WebSocket API provides a fast, efficient, and low-latency way to receive real-time data, including market quotes and order status updates. This is the preferred method for streaming high-frequency data.
We offer two distinct WebSocket endpoints for different types of real-time data:
- Price Feed WebSocket - For live market data including LTP (Last Traded Price) and real-time quotes
- Order Updates WebSocket - For real-time updates on your order statuses and trade confirmations
Authentication for both endpoints is handled via an Authorization header passed during the initial connection handshake.
Price Feed¶
Use this endpoint to stream live market data for instruments.
Endpoint: wss://ws-prices.indstocks.com/api/v1/ws/prices
Subscription
Once connected, you send JSON messages to subscribe to or unsubscribe from instrument feeds.
Request Structure A subscription message consists of an action, a mode, and an array of instruments.
| Parameter | Type | Description |
|---|---|---|
action | string | The action to perform. Enum: "subscribe", "unsubscribe" |
mode | string | The data mode. Enum: "ltp", "quote" |
instruments | array | An array of instrument tokens to subscribe to. |
Instrument Format Instrument tokens are strings that identify a specific security or index, formatted as SEGMENT:TOKEN.
| Type | Prefix | Example |
|---|---|---|
| NSE Equity | NSE: | "NSE:2885" |
| BSE Equity | BSE: | "BSE:500325" |
| NSE Derivatives (F&O) | NFO: | "NFO:51011" |
| BSE Derivatives (F&O) | BFO: | "BFO:12345" |
| NSE Index | NIDX: | "NIDX:26000" |
| BSE Index | BIDX: | "BIDX:1" |
Subscription Examples
-
To subscribe to LTP mode for an instrument:
-
To subscribe to Quote mode:
Data Response
The data from the server will be a JSON string. You will need to parse this string to get the JSON object.
- LTP Response Format:
Order Updates Feed¶
This endpoint streams all real-time updates for your orders.
Endpoint: wss://ws-order-updates.indstocks.com/api/v1/ws/trades
Subscription
To start receiving order updates, send a single subscription message after connecting.
- Subscription Message: Once subscribed, all updates for your orders (e.g., placement, execution, cancellation) will be pushed to you automatically.
Order Update Response
Updates are published as a JSON-encoded string. Decode the frame to obtain the string, then decode that string to obtain the update object.
The example below is an execution update, which carries every field this feed sends. Updates earlier in the order's life carry a subset; the When sent column in the field table states which.
-
Example frame:
Text Only"{\"mode\":\"order_update\",\"timestamp\":1789628366550,\"data\":{\"order_id\":\"97603202\",\"entity_name\":\"SENSEX 17 SEP 74400 CE\",\"lot\":1,\"order_type\":\"BUY\",\"order_status\":\"S\",\"executed_price\":306.45,\"elapsed_time\":8,\"error_message\":\" \",\"timestamp\":1789628366544,\"req_quantity\":20,\"requested_lot\":1}}" -
The same frame, decoded:
JSON{ "mode": "order_update", "timestamp": 1789628366550, "data": { "order_id": "97603202", "entity_name": "SENSEX 17 SEP 74400 CE", "lot": 1, "order_type": "BUY", "order_status": "S", "executed_price": 306.45, "elapsed_time": 8, "error_message": " ", "timestamp": 1789628366544, "req_quantity": 20, "requested_lot": 1 } }
Message envelope
| Field | Type | Description |
|---|---|---|
mode | string | Message type. This feed publishes order_update. Filter on this field, as other message types share the connection. |
timestamp | integer | Epoch milliseconds (UTC) at which the update was published. Sequence your messages on this field. |
data | object | The order update. |
data fields
| Field | Type | When sent | Description |
|---|---|---|---|
order_id | string | Every update | Order reference, numeric and sent as a string. Use it to correlate updates with Get Order Book. |
entity_name | string | Every update | Instrument name, provided for display. |
order_type | string | Every update | Side of the order: BUY or SELL. |
order_status | string | Every update | Short status code. See the table below. |
req_quantity | integer | Every update | Quantity requested, in units. |
requested_lot | integer | Every update | Number of lots requested. |
timestamp | integer | Every update | Epoch milliseconds recorded by the order management system, provided for reference. Sequence your messages on the envelope timestamp. |
lot | integer | On execution | Number of lots filled. Sent with order_status S. |
executed_price | number | On execution | Price at which the order was executed. Sent with order_status S. |
elapsed_time | integer | With P and S | Time taken to place the order at the exchange, in milliseconds. Reported for the individual update. |
error_message | string | With elapsed_time | A single space indicates no message. |
data omits a field rather than sending it at its default value, so check that a field is present before reading it. elapsed_time and error_message are sent together.
order_status values
The order_status field carries a short code for the order's state at the moment the update was generated. This feed uses the short codes below; the long-form status names listed under Order Status Types are returned by the REST order endpoints.
| Code | Meaning |
|---|---|
R | Received |
P | Pending |
S | Success (executed) |
F | Failed |
C | Cancelled |
RJ | Rejected |
PF | Partially filled |
PFC | Partially filled, remaining quantity cancelled |
Order lifecycle
An order publishes a sequence of updates as it progresses. A market order that fills moves through R → P → S:
{
"mode": "order_update",
"timestamp": 1789628366508,
"data": {
"order_id": "97603202",
"entity_name": "SENSEX 17 SEP 74400 CE",
"order_type": "BUY",
"order_status": "R",
"timestamp": 1789628366508,
"req_quantity": 20,
"requested_lot": 1
}
}
{
"mode": "order_update",
"timestamp": 1789628366540,
"data": {
"order_id": "97603202",
"entity_name": "SENSEX 17 SEP 74400 CE",
"order_type": "BUY",
"order_status": "P",
"elapsed_time": 11,
"error_message": " ",
"timestamp": 1789628366537,
"req_quantity": 20,
"requested_lot": 1
}
}
{
"mode": "order_update",
"timestamp": 1789628366550,
"data": {
"order_id": "97603202",
"entity_name": "SENSEX 17 SEP 74400 CE",
"lot": 1,
"order_type": "BUY",
"order_status": "S",
"executed_price": 306.45,
"elapsed_time": 8,
"error_message": " ",
"timestamp": 1789628366544,
"req_quantity": 20,
"requested_lot": 1
}
}
Sequencing updates
Sequence updates on the envelope timestamp, which carries the time the update was published.
Applying updates
A status may be published more than once for the same order, and repeated updates need not carry the same fields. Key your state on order_id, sequence on the envelope timestamp, and apply the most recent update. Take fill details from the most recent update that carries them.
Heartbeats
The server may send periodic heartbeat messages to keep the connection alive. Your client should be configured to handle these, typically by ignoring them.
See Also¶
- Market Quotes — REST alternative for on-demand (rather than streaming) quotes
- Orders — reconcile order state via Get Order Book instead of blindly retrying after a dropped connection
- Glossary & Constants —
SEGMENT:TOKENinstrument format used only on WebSocket