Skip to content

Streaming Quote Data

wss://stream.samco.in

Samco Trade API platform provides the Broadcast API, as the most effective way to receive quote data for instruments across all exchanges during live market hours. The API provides continuous streaming data of quote based on user request, and primarily consists of fields such as last traded price, open, high, low, close, last traded quantity, last traded volume, last traded time etc.

The API uses WebSocket protocol to establish a dedicated TCP connection after an HTTP handshake to receive streaming quotes and thereby provides seamless streaming of quote data. You need to use a WebSocket client to connect to our broadcast API. If you have already subscribed to our Samco Trade API services, you will be able to access broadcast API too.

Parameters

NameTypeRequiredDescription
bodyobjectfalsenone
streaming_typestringtrueStreaming type. Added for future use. Pass this value as “quote” always.
symbols[string]trueList of symbols containing listing numbers used to get quote.
request_typestringtrueRequest type. This can be Subscribe/Unsubscribe. Subscribe - Receive continuous quote data. UnSubscribe - Stop receiving the continuous quote data. *It's important to unsubscribe when the streaming is no longer needed.
response_formatstringtrueResponse data format. Currently supports json only.

Sample Request Body

json
requestBody={
  "streaming_type": "quote",
  "symbols": "[{'symbol':'-53'},{'symbol':'89017_NFO'}]",
  "request_type": "subscribe",
  "response_format": "JSON"
}

Prefer a typed client? Use the official SDK

The samples below speak the raw WebSocket protocol — copy them when you're integrating from a language without an SDK, or when you want to see exactly what frames go on the wire. For production integrations in Java, Node, or Python, the official SDKs wrap this same protocol with typed QuoteTick objects (LTP / OHLC / volume), connect/reconnect plumbing, and per-stream subscribe helpers:

  • JavaJava SDK READMEStreamingClient + StreamingListener.onQuote(QuoteTick), subscribed via subscribeQuote(...).
  • NodeNode SDK READMEStreamingClient({ onQuote, ... }) + subscribeQuote([...]).
  • PythonPython SDK READMESamcoBridge.set_streaming_data(value, streaming_type=STREAMING_TYPE_QUOTE) and subscribe_quote([...]).

The wire envelope each SDK produces is identical to the raw samples below, so the auth header (x-session-token), the streaming_type: "quote" value, and the subscribe / unsubscribe semantics are the same.

Sample Code

Runtime requirements

WebSocket clients only — cURL / fetch / HttpClient won't work for streaming. Minimum versions: Postman v10+ • Java 17 LTS+ • Node 22+ (npm i ws) • Python 3.8+ (pip install websocket-client).

End every subscribe / unsubscribe frame with \n

The streamer parses incoming messages as newline-delimited JSON. Each subscribe (or unsubscribe) payload must end with a trailing \n — without it, the frame is buffered and the subscription never takes effect. The official SDKs append it for you; in raw examples below it's added explicitly.

text
1.  Postman → File → New → "WebSocket Request"
2.  URL          : wss://stream.samco.in
3.  Headers tab  :
      Key   = x-session-token
      Value = <SESSION_TOKEN>
4.  Click "Connect" — the response panel should show "CONNECTED".
5.  In the Message editor (Body tab → JSON) paste the subscribe frame
    below and click "Send":

    {
      "request": {
        "streaming_type": "quote",
        "data": {
          "symbols": [
            { "symbol": "532826_BSE" }
          ]
        },
        "request_type": "subscribe",
        "response_format": "json"
      }
    }

    >>> Important: enable Postman's "Add newline at end of message"
        toggle (or press Enter once after the closing brace). The
        streamer needs the trailing \n to accept the subscription.

6.  Quote frames will stream into the response panel. To stop, send the
    same frame (with the trailing newline) and
    "request_type": "unsubscribe".
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.WebSocket;
import java.util.concurrent.CompletionStage;

public class StreamingQuoteData {
  public static void main(String[] args) throws Exception {
    String subscribe = """
        {"request":{"streaming_type":"quote",\
"data":{"symbols":[{"symbol":"532826_BSE"}]},\
"request_type":"subscribe","response_format":"json"}}""";

    HttpClient client = HttpClient.newHttpClient();

    WebSocket ws = client.newWebSocketBuilder()
        .header("x-session-token", "<SESSION_TOKEN>")
        .buildAsync(URI.create("wss://stream.samco.in"), new WebSocket.Listener() {
          @Override public void onOpen(WebSocket webSocket) {
            // Streamer parses newline-delimited JSON — the trailing \n is required.
            webSocket.sendText(subscribe + "\n", true);
            WebSocket.Listener.super.onOpen(webSocket);
          }
          @Override public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last) {
            System.out.println("Quote :: " + data);
            return WebSocket.Listener.super.onText(webSocket, data, last);
          }
          @Override public void onError(WebSocket webSocket, Throwable error) {
            error.printStackTrace();
          }
        })
        .join();

    Thread.currentThread().join();
  }
}
js
// Install once: npm i ws
const WebSocket = require('ws');

const ws = new WebSocket('wss://stream.samco.in', {
  headers: { 'x-session-token': '<SESSION_TOKEN>' }
});

ws.on('open', () => {
  const subscribe = {
    request: {
      streaming_type: 'quote',
      data: { symbols: [{ symbol: '532826_BSE' }] },
      request_type: 'subscribe',
      response_format: 'json'
    }
  };
  // Streamer parses newline-delimited JSON — the trailing \n is required.
  ws.send(JSON.stringify(subscribe) + '\n');
});

ws.on('message', (msg) => console.log('Quote ::', msg.toString()));
ws.on('error', (err) => console.error(err));
ws.on('close', () => console.log('Connection closed'));
py
# Install once: pip install websocket-client
import json
import websocket

SESSION_TOKEN = "<SESSION_TOKEN>"

def on_open(ws):
    subscribe = {
        "request": {
            "streaming_type": "quote",
            "data": {"symbols": [{"symbol": "532826_BSE"}]},
            "request_type": "subscribe",
            "response_format": "json",
        }
    }
    # Streamer parses newline-delimited JSON — the trailing \n is required.
    ws.send(json.dumps(subscribe) + "\n")

def on_message(ws, msg):
    print("Quote ::", msg)

def on_error(ws, error):
    print(error)

def on_close(ws, code, reason):
    print("Connection closed")

ws = websocket.WebSocketApp(
    "wss://stream.samco.in",
    header={"x-session-token": SESSION_TOKEN},
    on_open=on_open,
    on_message=on_message,
    on_error=on_error,
    on_close=on_close,
)
ws.run_forever()

Sample Response

json
{
  "aPr": "44561.00",
  "bPr": "44554.00",
  "aSz": "1",
  "bSz": "1",
  "sym": "2885_NSE",
  "avgPr": "44371.85",
  "c": "44119.00",
  "h": "44786.00",
  "l": "43969.00",
  "o": "44105.00",
  "oI": "361290",
  "oIChg": "22350.00",
  "ch": "435.00",
  "chPer": "0.99",
  "lTrdT": "01 Oct 2019, 06:47:03 PM",
  "ltp": "44554.00",
  "ltq": "1",
  "ltt": "01 Oct 2019, 06:47:03 PM",
  "lttUTC": "01 Oct 2019, 01:17:03 PM",
  "tBQ": "973",
  "tSQ": "610",
  "ttv": "782763833.41",
  "vol": "782763833.41",
  "yH": "44786.00",
  "yL": "0.00",
  "streaming_type": "quote"
}

Response Schema

Status Code 200

NameTypeDescription
aPrstringAsk Price that the seller is willing to accept for the scrip.
bPrstringBid Price that the buyer is willing to pay for the scrip.
aSzstringAsk size/quantity available for trading.
bSzstringBid size/quantity offered for trading.
symstringActual symbol name of the scrip.
avgPrstringAverage trading price of the equity or derivative.
cstringClose value of the market snapshot.
hstringHigh value of the market snapshot.
lstringLow value of the market snapshot.
ostringOpening price of the market snapshot.
oIstringOpen interest, which is the total number of outstanding derivative contracts that have not been settled.
oIChgstringChange in open interest value.
chstringChange value, which is the difference between the current value and the previous day's market close.
chPerstringPercentage change between the current value and the previous day's market close.
lTrdTstringTime of the last transaction.
ltpstringLast traded price at which the most recent transaction occurred.
ltqstringQuantity of the last transaction.
lttstringLast transaction time in milliseconds.
lttUTCstringLast transaction time in UTC time zone format.
tBQstringTotal quantity of BUY transactions.
tSQstringTotal quantity of SELL transactions.
ttvstringTotal trading volume done.
volstringTotal amount of security traded today.
yHstring52-week high.
yLstring52-week low.
streaming_typestringStreaming type. Added for future use. Pass this value as “quote” always.