On this page
In plain English

Tells you when your positions change, so you can keep a portfolio view current without re-reading it.

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

What it does

Pushes changes to your open positions.

This feed may not be enabled

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.

You can compute live P&L without this feed

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.

child_orders field list omits tsym in the REST version

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.

Example message
{ "t": "p", "uid": "IN001" }
Subscribe fields
FieldTypeDescription
tstring

Always the literal 'p'.

uidstring

User ID.

Unsubscribe t: "up"

Client → server

Example message
{ "t": "up" }
Unsubscribe fields
FieldTypeDescription
tstring

Always the literal 'up'.

Messages you receive

Subscribe acknowledgement t: "pk"

Server → client

Subscribe acknowledgement fields
FieldTypeDescription
tstring

Always 'pk'.

uidstring

User ID.

Position update t: "pm"

Server → client

Pushed when a position changes.

Position update fields
FieldTypeDescription
tstring

Always 'pm'.

exchstring

Exchange segment.

tsymstring

Trading symbol.

tokenstring

Contract token.

uidstring

User ID.

actidstring

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

prdstring

Product name.

netqtystring

Net quantity: daybuyqty + cfbuyqty − daysellqty − cfsellqty.

daybuyqtystring

Quantity bought today.

daysellqtystring

Quantity sold today.

daybuyamtstring

Value bought today.

daysellamtstring

Value sold today.

cfbuyqtystring

Carry-forward buy quantity.

cfsellqtystring

Carry-forward sell quantity.

cfbuyamtstring

Carry-forward buy value.

cfsellamtstring

Carry-forward sell value.

openbuyqtystring

Open buy quantity.

opensellqtystring

Open sell quantity.

openbuyamtstring

Open buy value.

opensellamtstring

Open sell value.

buyavgprcstring

Buy average price: (daybuyamt + cfbuyamt) / (daybuyqty + cfbuyqty).

sellavgprcstring

Sell average price: (daysellamt + cfsellamt) / (daysellqty + cfsellqty).

totbuyamtstring

Total buy value.

totsellamtstring

Total sell value.

totbuyavgprcstring

Total buy average price.

totsellavgprcstring

Total sell average price.

rpnlstring

Realised profit and loss. The API specification renders this as "Realized panel", which is a typo for P&L.

instnamestring

Instrument name.

upload_prcstring

Upload price.

child_ordersobject[]

Per-exchange breakdown. Same shape as the parent, minus the identity fields.

Unsubscribe acknowledgement t: "upk"

Server → client

Unsubscribe acknowledgement fields
FieldTypeDescription
tstring

Always 'upk'.

Working example

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

Python
"""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()
Esc
↑↓ navigate↵ openEsc close/ to search