On this page
In plain English

Before you can receive any prices you have to say who you are. You open the connection, send one short message containing your access token, and wait for the acknowledgement. Nothing else works until that acknowledgement arrives.

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

Endpoints

WebSocket URL (LIVE): wss://api.infinn.in/NorenWSTP/

Use the connect message with your access token. Orders placed on live are real. Practise first on Sandbox (UAT / Test — NOT live): https://uat.infinn.in. Then use live.

What it does

Opens the stream and authenticates the session.

A bad token does not fail the handshake -- it fails afterwards

The WebSocket upgrade succeeds regardless of your credentials. Verified against the live endpoint: sending a connect task with an invalid token returns {"t":"ak","s":"NOT_OK"} and the server then closes the connection with code 1008 (PolicyViolation). If your client treats "socket opened" as "authenticated", it will look connected while receiving nothing.

The documented value and the wire value differ

The field table says Ok or Not_Ok. The live feed sent NOT_OK. Normalise before comparing -- String(s).toLowerCase() !== 'ok' is the safe test.

source must match your login

The documentation requires source to be the same value used in the login request. For the GenAcsTok flow documented on this site, these docs use API; set the value your broker has given you if it differs.

Subscribe only after the acknowledgement

Subscriptions sent before ak arrives are not guaranteed to be honoured. Queue them in your client and flush the queue when ak reports success.

Messages you send

Connect task t: "a"

Client → server

The first message on a new connection. Send it immediately after the socket opens.

Example message
{
"t": "a",
"uid": "IN001",
"actid": "IN001",
"source": "API",
"accesstoken": "YOUR_ACCESS_TOKEN"
}
Connect task fields
FieldTypeDescription
tstring

Always the literal 'a'. Identifies this as a connect task.

uidstring

User ID.

actidstring

Account ID. For an individual account it equals uid (confirmed live).

sourcestring

Must match the source used at login: WEB, MOB or API.

accesstokenstring

Your access token -- the same 64-character value GenAcsTok returned. Note the field name is all one word and lower case.

Messages you receive

Connect acknowledgement t: "ak"

Server → client

Confirms -- or refuses -- the session.

Example message
{ "t": "ak", "uid": "IN001", "s": "OK" }
Connect acknowledgement fields
FieldTypeDescription
tstring

Always 'ak'.

uidstring

User ID.

sstring

Session status. The live endpoint sends OK on success and NOT_OK on failure (upper case). Compare case-insensitively.

Working example

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

Python
"""Infinn WebSocket client -- Connect & authenticate.

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.")
      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