On this page
In plain English

A deeper view than touchline. Instead of just the best buy and sell price, you get the best five on each side, with the quantity and the number of orders waiting at each. This is what a depth ladder is built from.

WSwss://api.infinn.in/NorenWSTP/

What it does

Streams five levels of the order book for one or more instruments.

Depth updates are deltas too

The API specification states it outright: "The response in Depth Subscription Updates will display only the modified fields." A depth ladder that re-renders from each raw df message will flicker between full and nearly empty. Merge into a stored snapshot.

Depth is far heavier than touchline

Each instrument carries up to 30 book fields that change constantly. Subscribe to depth for the one or two instruments actually on screen, and use touchline for the rest.

A field name that starts with a digit

52h and 52l are not valid identifiers in most languages. Access them with bracket notation (tick["52h"]) rather than dot notation.

Messages you send

Subscribe t: "d"

Client → server

Subscribes to depth updates.

Example message
{ "t": "d", "k": "NSE|2885" }
Subscribe fields
FieldTypeDescription
tstring

Always the literal 'd'.

kstring

One or more instruments as exchange|token joined with #, for example NSE|22#BSE|508123.

Unsubscribe t: "ud"

Client → server

Example message
{ "t": "ud", "k": "NSE|2885" }
Unsubscribe fields
FieldTypeDescription
tstring

Always the literal 'ud'.

kstring

The instruments to unsubscribe.

Messages you receive

Subscribe acknowledgement (full snapshot) t: "dk"

Server → client

One per instrument in k, each a complete snapshot.

Subscribe acknowledgement (full snapshot) fields
FieldTypeDescription
tstring

Always 'dk'.

estring

Exchange name.

tkstring

Scrip token.

lpstring

Last traded price.

pcstring

Percentage change.

vstring

Volume.

ostring

Open price.

hstring

High price.

lstring

Low price.

cstring

Previous close price.

cpstring

Close price.

apstring

Average trade price.

lttstring

Last trade time.

ltqstring

Last trade quantity.

tbqstring

Total buy quantity across the book.

tsqstring

Total sell quantity across the book.

bq1string

Best buy quantity, level 1. bq2 to bq5 follow the same pattern.

bp1string

Best buy price, level 1. bp2 to bp5 follow.

bo1string

Number of buy orders at level 1. bo2 to bo5 follow.

sq1string

Best sell quantity, level 1. sq2 to sq5 follow.

sp1string

Best sell price, level 1. sp2 to sp5 follow.

so1string

Number of sell orders at level 1. so2 to so5 follow.

lcstring

Lower circuit limit.

ucstring

Upper circuit limit.

52hstring

52-week high. Lifetime high on MCX.

52lstring

52-week low. Lifetime low on MCX.

oistring

Open interest.

poistring

Previous day's closing open interest.

toistring

Total open interest for the underlying.

ftstring

Feed time.

Depth update (changed fields only) t: "df"

Server → client

Sent on every change. Carries only the modified fields, plus two range fields that do not appear in the acknowledgement.

Example message
{
"t": "df",
"e": "NSE",
"tk": "22",
"o": "1166.00",
"h": "1179.00",
"l": "1145.35",
"c": "1152.65",
"ap": "1159.74",
"v": "819881",
"tbq": "120952",
"tsq": "131730",
"bp1": "1156.00", "sp1": "1156.50",
"bp2": "1155.80", "sp2": "1156.55",
"bp3": "1155.75", "sp3": "1156.65",
"bp4": "1155.70", "sp4": "1156.70",
"bp5": "1155.65", "sp5": "1156.75",
"bq1": "4",   "sq1": "10",
"bq2": "67",  "sq2": "63",
"bq3": "83",  "sq3": "1",
"bq4": "139", "sq4": "53",
"bq5": "393", "sq5": "94"
}
Depth update (changed fields only) fields
FieldTypeDescription
tstring

Always 'df'.

estring

Exchange name.

tkstring

Scrip token.

lpstring

Last traded price.

pcstring

Percentage change.

vstring

Volume.

ostring

Open price.

hstring

High price.

lstring

Low price.

cstring

Previous close price.

cpstring

Close price.

apstring

Average trade price.

lttstring

Last trade time.

ltqstring

Last trade quantity.

tbqstring

Total buy quantity across the book.

tsqstring

Total sell quantity across the book.

bq1string

Best buy quantity, level 1. bq2 to bq5 follow the same pattern.

bp1string

Best buy price, level 1. bp2 to bp5 follow.

bo1string

Number of buy orders at level 1. bo2 to bo5 follow.

sq1string

Best sell quantity, level 1. sq2 to sq5 follow.

sp1string

Best sell price, level 1. sp2 to sp5 follow.

so1string

Number of sell orders at level 1. so2 to so5 follow.

lcstring

Lower circuit limit.

ucstring

Upper circuit limit.

52hstring

52-week high. Lifetime high on MCX.

52lstring

52-week low. Lifetime low on MCX.

oistring

Open interest.

poistring

Previous day's closing open interest.

toistring

Total open interest for the underlying.

ftstring

Feed time.

uestring

Exchange high range. Appears on updates only.

lestring

Exchange low range. Appears on updates only.

Unsubscribe acknowledgement t: "udk"

Server → client

Unsubscribe acknowledgement fields
FieldTypeDescription
tstring

Always 'udk'.

kstring

The instruments that were unsubscribed.

Working example

A complete Python client for this feed. It needs only the websocket-client package (pip install websocket-client).

Python
"""Infinn WebSocket client -- Market depth feed.

Requires: pip install websocket-client
"""
import json
import threading
import time

import websocket  # websocket-client

ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
UID = "IN001"

# Merged state per token. The acknowledgement carries a full snapshot and
# every later update carries only what changed, so updates must be MERGED
# into this, never used to replace an entry.
state = {}


def on_open(ws):
  # Step 1: authenticate. Nothing else is honoured until "ak" arrives.
  ws.send(json.dumps({
      "t": "a",
      "uid": UID,
      "actid": UID,
      "source": "API",
      "accesstoken": ACCESS_TOKEN,
  }))


def on_message(ws, raw):
  msg = json.loads(raw)
  kind = msg.get("t")

  if kind == "ak":
      # The documentation says "Ok or Not_Ok"; the live feed sends "NOT_OK".
      # Compare case-insensitively.
      if str(msg.get("s", "")).lower() != "ok":
          print("Authentication refused:", msg)
          ws.close()
          return
      print("Authenticated. Subscribing.")
      ws.send(json.dumps({"t": "d", "k": "NSE|2885#NSE|3045"}))
      threading.Thread(target=heartbeat, args=(ws,), daemon=True).start()
      return

  # Acknowledgements carry a full snapshot; feeds carry deltas.
  if kind in ("tk", "dk", "lk"):
      state[msg["tk"]] = dict(msg)
  elif kind in ("tf", "df", "lf"):
      state.setdefault(msg["tk"], {}).update(msg)
  elif kind == "hk":
      return  # heartbeat acknowledged
  else:
      print(kind, msg)
      return

  row = state[msg["tk"]]
  print(f'{row.get("ts", row["tk"]):<16} {row.get("lp", "-"):>10}')


def heartbeat(ws):
  # No interval is published. 30s is comfortably inside any plausible
  # idle timeout for a feed of this kind.
  while ws.keep_running:
      time.sleep(30)
      try:
          ws.send(json.dumps({"t": "h"}))
      except Exception:
          return


def on_error(ws, err):
  print("error:", err)


def on_close(ws, code, reason):
  # 1008 (PolicyViolation) is what the server sends when it rejects
  # your credentials.
  print(f"closed: {code} {reason}")


if __name__ == "__main__":
  websocket.WebSocketApp(
      "wss://api.infinn.in/NorenWSTP/",
      on_open=on_open,
      on_message=on_message,
      on_error=on_error,
      on_close=on_close,
  ).run_forever()
Esc
↑↓ navigate↵ openEsc close/ to search