On this page
One connection, held open, over which Infinn pushes everything that changes: prices, order updates, position updates, alerts and market status. It replaces every polling loop you would otherwise write.
wss://api.infinn.in/NorenWSTP/A normal request is a phone call: you dial, ask one question, get one answer, hang up. To ask again you dial again.
A WebSocket is leaving the line open. You say who you are once, say what you are interested in, and then simply listen. When the price changes, Infinn speaks. You did not have to ask.
For anything that changes constantly, the second is not just faster - it is the only approach that fits inside the rate limit.
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.
Why it matters here
The sequence
- Open the socketConnect to
wss://api.infinn.in/NorenWSTP/. The handshake succeeds regardless of your credentials - which is worth knowing, because it means a successful connection tells you nothing about whether you are authenticated. - Send the connect taskA single message with
t: "a"carrying your user ID, account ID, source and access token. Fields - Wait for the acknowledgement
{"t":"ak","s":"Ok"}means you are in. Anything else means you are not - and the server will close the connection shortly afterwards. - SubscribeSend a subscription for the feed you want. Each instrument in the subscription produces one acknowledgement carrying a full snapshot.
- Merge the updatesUpdates that follow carry only the fields that changed. Merge them into the snapshot; do not replace it.
- Keep it aliveSend
{"t":"h"}periodically. Without it an idle connection will be dropped by something between you and Infinn, and a dead feed looks exactly like a quiet market.
What is available
| Feed | What it carries | Message types |
|---|---|---|
| Connect & authenticate | Opens the stream and authenticates the session. | a, ak |
| Heartbeat | Keeps the connection alive. | h, hk |
| Touchline feed | Streams the top-of-book snapshot for one or more instruments. | t, tk, tf, u, uk |
| Market depth feed | Streams five levels of the order book for one or more instruments. | d, dk, df, ud, udk |
| LTP feed | Streams only the last traded price -- the lightest feed. | l, lk, lf, ul, ulk |
| Order updates | Pushes every change to your orders as it happens. | om, uo, uok |
| Position updates | Pushes changes to your open positions. | p, pk, pm, up, upk |
| Alert updates | Pushes notifications when a price alert or GTT triggers. | am |
| Admin messages | Pushes administrative messages from the broker. | rm |
| Market status updates | Pushes changes to each exchange segment's trading status. | ms |
Message types at a glance
Every message carries a t field, and both sides dispatch on it. The naming is consistent once you see it: a bare letter is a request, k appended is its acknowledgement, f appended is a feed update, and u prefixed is an unsubscribe.
t | Direction | Message | Documented on |
|---|---|---|---|
a | Client → server | Connect task | Connect & authenticate |
ak | Server → client | Connect acknowledgement | Connect & authenticate |
h | Client → server | Heartbeat | Heartbeat |
hk | Server → client | Heartbeat acknowledgement | Heartbeat |
t | Client → server | Subscribe | Touchline feed |
tk | Server → client | Subscribe acknowledgement (full snapshot) | Touchline feed |
tf | Server → client | Touchline update (changed fields only) | Touchline feed |
u | Client → server | Unsubscribe | Touchline feed |
uk | Server → client | Unsubscribe acknowledgement | Touchline feed |
d | Client → server | Subscribe | Market depth feed |
dk | Server → client | Subscribe acknowledgement (full snapshot) | Market depth feed |
df | Server → client | Depth update (changed fields only) | Market depth feed |
ud | Client → server | Unsubscribe | Market depth feed |
udk | Server → client | Unsubscribe acknowledgement | Market depth feed |
l | Client → server | Subscribe | LTP feed |
lk | Server → client | Subscribe acknowledgement (full snapshot) | LTP feed |
lf | Server → client | LTP update | LTP feed |
ul | Client → server | Unsubscribe | LTP feed |
ulk | Server → client | Unsubscribe acknowledgement | LTP feed |
om | Server → client | Order update | Order updates |
uo | Client → server | Unsubscribe from order updates | Order updates |
uok | Server → client | Unsubscribe acknowledgement | Order updates |
p | Client → server | Subscribe | Position updates |
pk | Server → client | Subscribe acknowledgement | Position updates |
pm | Server → client | Position update | Position updates |
up | Client → server | Unsubscribe | Position updates |
upk | Server → client | Unsubscribe acknowledgement | Position updates |
am | Server → client | Alert update | Alert updates |
rm | Server → client | Admin message update | Admin messages |
ms | Server → client | Market status update | Market status updates |
Three things that catch people out
The acknowledgement gives you a complete picture. Every update after it contains only what changed - often just a token and a price.
Replace your stored object with an update and you lose the symbol, the day's range and everything else. Merge, always.
Verified against the live endpoint on 2026-10-08: connecting with an invalid token succeeds at the TLS and WebSocket level, returns {"t":"ak","s":"NOT_OK"}, and the server then closes with code 1008 (PolicyViolation).
Note also that the live value is NOT_OK in upper case, while the documentation says Not_Ok. Compare case-insensitively.
Nothing that happens while you are disconnected is redelivered. An order that fills during a reconnect simply never produces a message you will see.
So every reconnect must be followed by re-reading state over REST - the order book, the positions book - and then resubscribing. The order-tracking guide shows the pattern.
A complete client
Connects, authenticates, subscribes, merges deltas, heartbeats, and reconnects with backoff. Runnable as it stands.
"""A complete Infinn WebSocket client.
Handles the five things a toy example leaves out: authentication ordering,
delta merging, heartbeats, reconnection with backoff, and resubscription
after a reconnect.
Requires: pip install websocket-client
"""
import json
import logging
import random
import threading
import time
import websocket # websocket-client
WS_URL = "wss://api.infinn.in/NorenWSTP/"
HEARTBEAT_SECONDS = 30
log = logging.getLogger("infinn.ws")
class InfinnFeed:
def __init__(self, uid, access_token, on_tick=None, on_order=None):
self.uid = uid
self.access_token = access_token
self.on_tick = on_tick or (lambda row: None)
self.on_order = on_order or (lambda row: None)
# Tokens we want, as "NSE|2885". Kept so a reconnect can restore them.
self.subscriptions = set()
# Merged state per (exchange, token).
self.state = {}
self._ws = None
self._authenticated = threading.Event()
self._stop = threading.Event()
self._lock = threading.Lock()
# --- public ------------------------------------------------------------
def subscribe(self, keys):
"""Subscribes to touchline for keys like 'NSE|2885'."""
with self._lock:
self.subscriptions.update(keys)
if self._authenticated.is_set():
self._send({"t": "t", "k": "#".join(keys)})
def run_forever(self):
"""Connects, and keeps reconnecting until stop() is called."""
attempt = 0
while not self._stop.is_set():
try:
self._connect_once()
attempt = 0 # a clean run resets the backoff
except Exception as err:
log.warning("feed error: %s", err)
if self._stop.is_set():
return
# Full jitter, capped. Without jitter, every client of a broker
# that just restarted reconnects on the same tick.
delay = min(60, 2 ** min(attempt, 6))
time.sleep(random.uniform(1, max(2, delay)))
attempt += 1
log.info("reconnecting")
def stop(self):
self._stop.set()
if self._ws:
self._ws.close()
# --- internals ----------------------------------------------------------
def _connect_once(self):
self._authenticated.clear()
self._ws = websocket.WebSocketApp(
WS_URL,
on_open=self._on_open,
on_message=self._on_message,
on_error=lambda ws, e: log.warning("socket error: %s", e),
on_close=self._on_close,
)
self._ws.run_forever(ping_interval=0) # we send our own heartbeat
def _send(self, message):
if self._ws:
self._ws.send(json.dumps(message))
def _on_open(self, ws):
log.info("socket open, authenticating")
# The handshake succeeding proves nothing. Authenticate, then wait.
self._send({
"t": "a",
"uid": self.uid,
"actid": self.uid,
"source": "API",
"accesstoken": self.access_token,
})
def _on_close(self, ws, code, reason):
# 1008 PolicyViolation is what Infinn sends when it rejects the
# credentials -- distinguishing it stops a pointless reconnect loop.
if code == 1008:
log.error("authentication rejected (1008). Check the token and "
"that this machine's IP is registered. Not retrying.")
self._stop.set()
else:
log.info("socket closed: %s %s", code, reason)
def _on_message(self, ws, raw):
msg = json.loads(raw)
kind = msg.get("t")
if kind == "ak":
# Documented as "Ok or Not_Ok"; the live feed sends "NOT_OK".
if str(msg.get("s", "")).lower() != "ok":
log.error("authentication refused: %s", msg)
ws.close()
return
self._authenticated.set()
log.info("authenticated")
self._resubscribe()
threading.Thread(target=self._heartbeat, daemon=True).start()
return
if kind == "hk":
return # heartbeat acknowledged
# Snapshots replace; feeds merge. Getting this backwards is the most
# common bug in clients for this feed.
if kind in ("tk", "dk", "lk"):
key = (msg.get("e"), msg.get("tk"))
self.state[key] = dict(msg)
self.on_tick(self.state[key])
elif kind in ("tf", "df", "lf"):
key = (msg.get("e"), msg.get("tk"))
row = self.state.setdefault(key, {})
row.update(msg)
self.on_tick(row)
elif kind == "om":
self.on_order(msg)
elif kind in ("am", "rm", "ms"):
log.info("%s: %s", kind, msg.get("dmsg") or msg)
def _resubscribe(self):
with self._lock:
keys = sorted(self.subscriptions)
if keys:
# One message can carry many instruments.
self._send({"t": "t", "k": "#".join(keys)})
log.info("subscribed to %d instruments", len(keys))
def _heartbeat(self):
# No interval is published. 30s is well inside any plausible idle
# timeout and costs nothing.
while self._authenticated.is_set() and not self._stop.is_set():
time.sleep(HEARTBEAT_SECONDS)
try:
self._send({"t": "h"})
except Exception:
return
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format="%(asctime)s %(levelname)s %(message)s")
feed = InfinnFeed(
uid="IN001",
access_token="YOUR_ACCESS_TOKEN",
on_tick=lambda row: print(
f'{row.get("ts", row.get("tk")):<18} {row.get("lp", "-"):>10}'),
)
# NSE|2885 is RELIANCE-EQ, NSE|3045 is SBIN-EQ, NSE|26000 is Nifty 50.
feed.subscribe(["NSE|2885", "NSE|3045", "NSE|26000"])
try:
feed.run_forever()
except KeyboardInterrupt:
feed.stop()Choosing a feed
| Need | Feed | Per-update payload |
|---|---|---|
| A price, and nothing else, for many instruments | LTP | 4 fields |
| A watchlist or ticker row | Touchline | Up to ~19 fields |
| A depth ladder | Depth | Up to ~30 fields |
| Order status | Order updates | No subscription needed |
| Position changes | Position updates | May not be enabled on your account |
The documentation publishes no maximum subscription count. In practice feeds of this family stop adding instruments past an undocumented ceiling without returning an error - you simply never receive data for the surplus.
So count your acknowledgements. You should get one per token you asked for; fewer means some were silently dropped. Subscribe to the visible rows, and unsubscribe when they scroll away.
Sentinel values
The general guidelines state that an at-the-open price is sent as 42949672.95. That is 232−1 divided by 100 - an unsigned 32-bit maximum being reused as a marker.
Treat it as absent, not as a price. Rendered literally it will make a chart unreadable and a portfolio total absurd.
ATO_SENTINEL = 42949672.95
def price(value):
"""Returns a usable price, or None when the feed is signalling 'no price'."""
parsed = num(value)
if parsed == 0 or abs(parsed - ATO_SENTINEL) < 0.01:
return None
return parsed