On this page
Tells you when your positions change, so you can keep a portfolio view current without re-reading it.
wss://api.infinn.in/NorenWSTP/What it does
Pushes changes to your open positions.
The documentation states that position updates are received "if it is made available in the startup (-position_update)" -- a server-side flag. If you subscribe and receive pk but never any pm, the feature is probably not switched on for your account. Ask Infinn.
Position updates fire when a position's composition changes, not on every price tick. For live mark-to-market, take netqty and netavgprc from Positions Book once, then recompute from LTP ticks locally. The formula is on the profit and loss page.
The WebSocket child_orders table includes tsym; the equivalent table on the REST Interoperable Positions Book endpoint does not. The stream appears to carry slightly more.
Messages you send
Subscribe t: "p"
Client → server
Subscribes to position updates.
{ "t": "p", "uid": "IN001" }| Field | Type | Description |
|---|---|---|
| t | string | Always the literal 'p'. |
| uid | string | User ID. |
Unsubscribe t: "up"
Client → server
{ "t": "up" }| Field | Type | Description |
|---|---|---|
| t | string | Always the literal 'up'. |
Messages you receive
Subscribe acknowledgement t: "pk"
Server → client
| Field | Type | Description |
|---|---|---|
| t | string | Always 'pk'. |
| uid | string | User ID. |
Position update t: "pm"
Server → client
Pushed when a position changes.
| Field | Type | Description |
|---|---|---|
| t | string | Always 'pm'. |
| exch | string | Exchange segment. |
| tsym | string | Trading symbol. |
| token | string | Contract token. |
| uid | string | User ID. |
| actid | string | Account ID. For an individual account it equals |
| prd | string | Product name. |
| netqty | string | Net quantity: daybuyqty + cfbuyqty − daysellqty − cfsellqty. |
| daybuyqty | string | Quantity bought today. |
| daysellqty | string | Quantity sold today. |
| daybuyamt | string | Value bought today. |
| daysellamt | string | Value sold today. |
| cfbuyqty | string | Carry-forward buy quantity. |
| cfsellqty | string | Carry-forward sell quantity. |
| cfbuyamt | string | Carry-forward buy value. |
| cfsellamt | string | Carry-forward sell value. |
| openbuyqty | string | Open buy quantity. |
| opensellqty | string | Open sell quantity. |
| openbuyamt | string | Open buy value. |
| opensellamt | string | Open sell value. |
| buyavgprc | string | Buy average price: (daybuyamt + cfbuyamt) / (daybuyqty + cfbuyqty). |
| sellavgprc | string | Sell average price: (daysellamt + cfsellamt) / (daysellqty + cfsellqty). |
| totbuyamt | string | Total buy value. |
| totsellamt | string | Total sell value. |
| totbuyavgprc | string | Total buy average price. |
| totsellavgprc | string | Total sell average price. |
| rpnl | string | Realised profit and loss. The API specification renders this as "Realized panel", which is a typo for P&L. |
| instname | string | Instrument name. |
| upload_prc | string | Upload price. |
| child_orders | object[] | Per-exchange breakdown. Same shape as the parent, minus the identity fields. |
Unsubscribe acknowledgement t: "upk"
Server → client
| Field | Type | Description |
|---|---|---|
| t | string | Always 'upk'. |
Working example
A complete Python client for this feed. It needs only the websocket-client package (pip install websocket-client).
"""Infinn WebSocket client -- Position updates.
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": "p", "uid": UID}))
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()// Infinn WebSocket client -- Position updates
// Node: npm install ws | Browser: use the built-in WebSocket.
const WebSocket = require('ws');
const ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN';
const UID = 'IN001';
// Merged state per token: acknowledgements are snapshots, feeds are deltas.
const state = new Map();
const ws = new WebSocket('wss://api.infinn.in/NorenWSTP/');
ws.on('open', () => {
ws.send(JSON.stringify({
t: 'a',
uid: UID,
actid: UID,
source: 'API',
accesstoken: ACCESS_TOKEN,
}));
});
ws.on('message', (raw) => {
const msg = JSON.parse(raw);
if (msg.t === 'ak') {
// Documented as "Ok or Not_Ok"; the live feed sends "NOT_OK".
if (String(msg.s).toLowerCase() !== 'ok') {
console.error('Authentication refused:', msg);
ws.close();
return;
}
console.log('Authenticated. Subscribing.');
ws.send(JSON.stringify({ t: 'p', uid: UID }));
setInterval(() => ws.send(JSON.stringify({ t: 'h' })), 30000);
return;
}
if (['tk', 'dk', 'lk'].includes(msg.t)) {
state.set(msg.tk, { ...msg }); // snapshot: replace
} else if (['tf', 'df', 'lf'].includes(msg.t)) {
state.set(msg.tk, { ...state.get(msg.tk), ...msg }); // delta: merge
} else {
return;
}
const row = state.get(msg.tk);
console.log((row.ts || row.tk).padEnd(16), String(row.lp ?? '-').padStart(10));
});
// 1008 PolicyViolation is sent when the credentials are rejected.
ws.on('close', (code, reason) => console.log('closed:', code, String(reason)));
ws.on('error', (err) => console.error('error:', err.message));