Skip to main content

Overview

Instead of repeatedly calling the REST API to check for updates, you can open a Socket.IO connection and have PHS push data to you the moment it changes. This is the recommended way to build:
  • A live-updating priceboard
  • Real-time order status tracking (placed / matched / cancelled / amended)
  • Live buying power and portfolio updates
There are two separate socket connections — they are not combined into one:
These two connections use different hosts, paths, and message formats. Mixing them up is the most common integration mistake — see Troubleshooting below.

Prerequisites

  • A Socket.IO client library. The examples below use socket.io-client for Node.js.
  • For the Order / Asset connection, an access_token from the login endpoint.
  • Your trading sub-account number, for subscribing to your own order/asset updates.

Connection 1: Market Data

Connects to PHS’s market data gateway and streams live price ticks for any symbol you subscribe to. No authentication required.
To watch another symbol, call socket.emit("subscribe", ...) again with a different symbol in the topic string. To stop watching a symbol, use the same topic string with socket.emit("unsubscribe", ...).

Connection 2: Order / Asset

Connects to PHS’s account gateway and streams updates about your own orders, buying power, and portfolio. Requires your access_token.
Choose the correct path for your account type. /realtime/eqt/socket.io (underlying/cash) and /realtime/fno/socket.io (derivatives) are not interchangeable — subscribing on the wrong path will silently return nothing.

Understanding account events

All account-related updates — order changes, buying power changes, and portfolio changes — arrive through the same account event. There is no separate OM, CI, or SE event name. Instead, look at the eventtype field inside the payload to know what kind of update you received:
A very common mistake is writing socket.on("OM", ...) expecting it to fire directly. It never will — always listen on socket.on("account", ...) and branch on eventtype inside the payload.

Field reference

The tables below cover the most commonly used fields. Field names are intentionally short (legacy naming) — this is your lookup table.

instrument fields (market data)

trade fields (matched trades)

account fields when eventtype = OM (underlying) or OO (derivatives)

Underlying (FLEX) and derivatives (FDS) accounts use slightly different field names for the same concept (e.g. orderprice vs. order_price). Match the field names to your account type.

Troubleshooting


Best practices

  • Keep access_token and any client secrets on your server, never in browser-side JavaScript.
  • Call unsubscribe for symbols or accounts you no longer need to reduce unnecessary traffic.
  • Use a single connection per gateway and subscribe to multiple topics on it, rather than opening a new connection per symbol.
  • Never commit real tokens into source control — treat a leaked token the same as a leaked password.