Using which api can I get the latest price of NIFTY 50 and NIFTYBANK?

I want to get the latest underlying value of NIFTY 50 and NIFTYBANK. I tried to use live date api but it did not work. This is the URL I call :

(https://developer.paytmmoney.com/data/v1/price/live?mode=FULL&pref=[{"actionType":"ADD","modeType":"FULL","scripType":"INDEX","exchangeType":"NSE","scripId":"13"},{"actionType":"ADD","modeType":"FULL","scripType":"INDEX","exchangeType":"NSE","scripId":"25"}])

But I get 400 error. Please let me know the correct api to call. also let me know if I want to fetch the latest LTP using Web socket for nifty and nifybank , then how can I do it ?

Please give me an example

thank you .

Hi @spratap124
You are calling the correct API for fetching the latest price but the query parameters you are passing are wrong which is why you are getting a 400 Bad Request error as a response. Please find the cURL for the live Market Data API below

curl --location --request GET 'https://developer.paytmmoney.com/data/v1/price/live?mode={MODE_TYPE}&pref={PREFERENCES}' \
--header 'x-jwt-token: {YOUR_JWT_TOKEN}'

You need to pass two query params:

  1. mode: we currently support three modes- LTP, QUOTE, FULL
  2. pref: list of scrips for which you want to fetch the live price
    • Structure of Pref: {Exchange}:{ScripId}:{ScripType}
      • Exchange: NSE or BSE
      • ScripId: Security id (use security master API to fetch latest scrip ids)
      • ScripType: INDEX, EQUITY, ETF, FUTURE, or OPTION

You also need to pass your jwt in the headers. Live Market Data API can be accessed using {access_token} or {read_access_token}. Use Generate Acess Token API for generating the jw token.

Sample cURL for fetching the Latest Price for Nifty 50 and nifty bank:

curl --location --request GET 'https://developer.paytmmoney.com/data/v1/price/live?mode=LTP&pref=NSE:13:INDEX,NSE:25:INDEX' \
--header 'x-jwt-token: {access_token}'

For more details check out the API docs For LIVE MARKET DATA API

Please follow the below steps for fetching data via our Live Market data WebSocket Streaming feature:

  1. Create a Public Access Token (JWT Token) using the get access token API. You can access Live Market Data WebSocket Streaming API using public access token only.
  2. To create a web socket connection with the Live Market Data WebSocket Streaming service, send a web socket connection request to
wss://developer-ws.paytmmoney.com/broadcast/user/v1/data?x_jwt_token={{PUBLIC_ACCESS_TOKEN}}
  1. Once successfully connected, you may send a preference to receive live market data.
// Subscribe to Multiple scrips 
            var preferences = 
            [
              {
                "actionType": "ADD",
                "modeType": "LTP",
                "scripType": "INDEX",
                "exchangeType": "NSE",
                "scripId": "13"
              },
              {
                "actionType": "ADD",
                "modeType": "LTP",
                "scripType": "INDEX",
                "exchangeType": "NSE",
                "scripId": "25"
              }
            ]; 
            
            socket.send(JSON.stringify(preferences));

For more details check the API docs for Live Market data WebSocket Streaming

1 Like

Thanks @AbhishekMehta Live api now working , but websocket is still returning {} only

Hi @spratap124

Can you share your implementation?

Or also you can try the Sample Client-Side Implementation from the API docs Live Market data WebSocket Streaming.

Just add/change the following things :

  1. const WebSocket = require('ws').WebSocket; add this at the top of the code to import WebSocket.
  2. Change data = message.datadata = message.data.buffer; in the code.
  3. Run npm install ws in terminal to install ws library.
  4. Then run the js file.

@AbhishekMehta May I know from where can i get pml id? I don’t see the same in security master list.