How the Shoonya WebSocket feed is structured, and when to use it instead of REST polling.
Overview
The WebSocket gateway delivers independent feed types over one connection: live touchline ticks, market depth, and order-status updates. You connect once, then subscribe to each feed type separately.
Purpose
Use the WebSocket for anything that needs to react to price movement or fills in real time — strategy engines, live dashboards, risk monitors. It replaces polling Market Quotes or Order Book in a loop.
Connection flow
Open a WebSocket connection to wss://api.shoonya.com/NorenWSAPI/.
Send a connect frame (t: "a") with uid, actid, source, and accesstoken.
Wait for the connect acknowledgment (t: "ak") and check s is "Ok" before subscribing to anything.
Not_Ok means an invalid user ID or session/access token — do not proceed to subscribe.
Don't confuse this with the touchline ackt: "ak" is the connect handshake response only. The touchline subscribe acknowledgment is a different message with t: "tk" — see Subscribe to Market Feed. Mixing the two up is a common source of parsing bugs since both arrive as JSON with a t field early in the connection.
# WebSocket connections aren't expressible in cURL —# use `websocat` for a quick command-line test:
websocat wss://api.shoonya.com/NorenWSAPI/
Error handling
DisconnectsThe gateway will drop idle connections. Implement exponential-backoff reconnect logic, re-send the connect frame, and re-send every subscription after every reconnect — nothing persists across a dropped socket.
Best practices
Run one WebSocket connection per process; multiplex symbols over it rather than opening one socket per instrument.
Process incoming ticks on a separate thread/queue from your order-placement logic so a slow strategy calculation never blocks the read loop.
Always check s: "Ok" on the connect ack before subscribing — subscribing on a failed connect silently produces no data.
Overview
The WebSocket gateway delivers independent feed types over one connection: live touchline ticks, market depth, and order-status updates. You connect once, then subscribe to each feed type separately.
Purpose
Use the WebSocket for anything that needs to react to price movement or fills in real time — strategy engines, live dashboards, risk monitors. It replaces polling Market Quotes or Order Book in a loop.
Connection flow
wss://api.shoonya.com/NorenWSAPI/.t: "a") withuid,actid,source, andaccesstoken.t: "ak") and checksis"Ok"before subscribing to anything.Connect request (t: 'a')
aWEB/MOB/APIConnect acknowledgment (t: 'ak')
akOk/Not_OkNot_Okmeans an invalid user ID or session/access token — do not proceed to subscribe.t: "ak"is the connect handshake response only. The touchline subscribe acknowledgment is a different message witht: "tk"— see Subscribe to Market Feed. Mixing the two up is a common source of parsing bugs since both arrive as JSON with atfield early in the connection.Request example
Error handling
Best practices
s: "Ok"on the connect ack before subscribing — subscribing on a failed connect silently produces no data.Python example
Notes
See Subscribe to Market Feed and Order Update Feed for the exact frame formats of each subscription type.