Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs
    1. Home
    2. Jeet Pattani
    J
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Jeet Pattani

    @Jeet Pattani

    2
    Reputation
    29
    Posts
    13
    Profile views
    0
    Followers
    1
    Following
    Joined Last Online

    Jeet Pattani Follow

    Best posts made by Jeet Pattani

    • Cannot connect more than one websocket connection

      On the docs it says that a client ID can have 3 concurrent websocket connection. But I get an Error everytime I try to connect to for 2nd websocket connection.

      Screenshot from Docse06bdf16-d508-4525-bad0-53996e50fa87-image.png

      Using the below code I try to connect to the websocket. Please do tell if I can have more than one connections because before a few weeks the same code worked to have more than one connection.

      const express = require('express');
      const WebSocket = require('ws');
      require("dotenv").config();
      const app = express();
      const port = 3001;
      
      // WebSocket URL
      const url = 'ws://smartapisocket.angelone.in/smart-stream';
      
      // Authentication headers
      const headers = {
        'Authorization': 'Bearer '+process.env.jwtToken,
        'x-api-key': 'Q906QkvT',
        'x-client-code': 'P529774',
        'x-feed-token': process.env.feedToken
      };
      
      
      // Create a WebSocket instance
      const socket = new WebSocket(url, { headers });
      
      // Map to store tokenID to tokenName mapping
      const tokenMapping = {
          '99926037':'NIFTY FINANCIAL SERVICES',
      };
      
      const tokenIDArray = Object.keys(tokenMapping);
      
      // Store the received data in an array
      //let receivedData = [];
      
      // Handle WebSocket connection open
      socket.on('open', () => {
        //console.log('WebSocket connected');
      
         // Send a subscription request
         const subscriptionRequest = {
          //correlationID: '',
          action: 1,
          params: {
            mode: 2,
            tokenList: [
              {
                exchangeType: 1,
                tokens: ['99926037'],
              },
            ],
          },
        };
      
        socket.send(JSON.stringify(subscriptionRequest));
      });
      
      // Store the latest data for each instrument
      const latestData = {};
      
      // Handle received messages from the WebSocket
      socket.on('message', (message) => {
        const data = new Uint8Array(message);
      
        // Check if the message is a heartbeat response
        if (data.length === 4 && data[0] === 112 && data[1] === 111 && data[2] === 110 && data[3] === 103) {
          // Ignore heartbeat response
          return;
        }
      
        // Parse the received binary data based on the provided response contract
      
        // Extract the Last Traded Price (LTP) and Token ID from the received data
        const ltpBytes = data.slice(43, 47);
        const closePriceBytes = data.slice(115, 122);
        const tokenIDBytes = data.slice(2, 27);
        const ltpValue = ltpBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const closePrice = closePriceBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const ltp = ltpValue / 100;
        const yesterdayPrice = closePrice / 100;
        const priceChange = parseFloat((ltp-yesterdayPrice).toFixed(2));
        const percentChange = parseFloat(((priceChange/ltp)*100).toFixed(2));
      
      //  const decoder = new TextDecoder('utf-8');
        const tokenID = new TextDecoder().decode(tokenIDBytes).replace(/\u0000/g, '');//To decode from Bytes and remove the null characters at the end of tokenID
        const tokenName = tokenMapping[tokenID];
      
        // Create a JSON object with tokenID and ltp
        const jsonData = {
          tokenName: tokenName,
          ltp: ltp,
          yesterdayPrice:yesterdayPrice,
          change:priceChange,
          percentChange:percentChange,
        };
      
        // Store the latest data for the instrument
        latestData[tokenID] = jsonData;
        //console.log(latestData)
        // Display the JSON object
        console.log(jsonData);
      });
      
      // Handle WebSocket connection close
      socket.on('close', () => {
        console.log('WebSocket connection closed');
      });
      
      // Send heartbeat message every 30 seconds to keep the connection alive
      setInterval(() => {
        if (socket.readyState === WebSocket.OPEN) {
          socket.send('ping');
        }
      }, 29000);
      
      // Enable CORS
      app.use((req, res, next) => {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
        next();
      });
      
      // a GET endpoint to retrieve the latest data for all instruments
      app.get('/api/prices', (req, res) => {
          res.json(latestData);
        });
      // a GET endpoint to retrieve the latest tokenMapping for the instruments
        app.get('/api/mappings', (req, res) => {
          res.json(tokenMapping);
        });
      // Start the Express server
      app.listen(port, () => {
        console.log(`Server listening on port ${port}`);
      });
      
      posted in Bugs
      J
      Jeet Pattani

    Latest posts made by Jeet Pattani

    • Cannot Retrieve live market data
      //This provides LTP/OHLC/FULL market data only during market hours
      
      const axios = require('axios');
      const credentials = require('./config');
      
      var data = JSON.stringify({
          "mode": "FULL",
          "exchangeTokens": {
              "NSE": ["3045"]
          }
      });
      
      var config = {
        method: 'post',
        url: 'https://apiconnect.angelbroking.com/rest/secure/angelbroking/market/v1/quote/',
        headers: {
          'Authorization': 'Bearer '+credentials.jwtToken, 
          'Content-Type': 'application/json', 
          'Accept': 'application/json', 
          'X-UserType': 'USER', 
          'X-SourceID': 'WEB', 
          'X-ClientLocalIP': 'CLIENT_LOCAL_IP', 
          'X-ClientPublicIP': 'CLIENT_PUBLIC_IP', 
          'X-MACAddress': 'MAC_ADDRESS', 
          'X-PrivateKey': credentials.apiKey,
        },
        data : data,
      };
      
      axios(config)
      .then(function (response) {
        console.log(JSON.stringify(response.data));
      })
      .catch(function (error) {
        console.log(error);
      });
      

      I am getting the below error since past three hours

      {"message":"Internal Error","errorcode":"AB2001","status":false,"data":null}
      

      LTP, Websocket, and Historical Data APIs work correctly. Just the Live Market Data API is not responding. Please tell if there is anything wrong with the code or the API?

      posted in Bugs
      J
      Jeet Pattani
    • RE: Re: How to fetch nifty spot data using ltpData()

      @piyushpk Try using the symboltoken as 26009 and tradingsymbol as BANKNIFTY. Except Nifty and BankNIFTY you cannot get the ltp from getLTP endpoint. Please do tell me if you are able to get other than these two.

      posted in Python SDK
      J
      Jeet Pattani
    • RE: error in fatching live data using websocket in reactJS

      @mani-upa11 It seems that this is an older way, right now websocketV2 is used.

      posted in Bugs
      J
      Jeet Pattani
    • RE: Cannot connect more than one websocket connection

      @admin I got Error 429 while trying to create a 2nd connection. But it was resolved after I emailed this issue on smartapi@angelbroking.com.

      posted in Bugs
      J
      Jeet Pattani
    • RE: error in fatching live data using websocket in reactJS

      @surendaracg Try using the below nodejs code it works perfectly

      const express = require('express');
      const WebSocket = require('ws');
      //require("dotenv").config();
      const config = require('./config');
      const app = express();
      const port = 3000;
      
      // WebSocket URL
      const url = 'ws://smartapisocket.angelone.in/smart-stream';
      
      // Authentication headers
      const headers = {
        'Authorization': 'Bearer '+config.jwtToken,
        'x-api-key': config.apiKey,
        'x-client-code': config.clientCode,
        'x-feed-token': config.feedToken,
      };
      
      
      // Create a WebSocket instance
      const socket = new WebSocket(url, { headers });
      
      // Map to store tokenID to tokenName mapping
      const tokenMapping = {
          '99919000':'SENSEX',
          '26000': 'NIFTY 50',
          '99926009': 'NIFTY BANK',
          '99926017': 'INDIA VIX',
          '99926013':'NIFTY NEXT 50',
          /*'99926011',: 'NIFTY MIDCAP 100',
          '99926032',: 'NIFTY SMALLCAP 100',
          '99926037',:'NIFTY FINANCIAL SERVICES',
          '99926012',:'NIFTY 100',
          '99926033',:'NIFTY 200',
          '99926004',:'NIFTY 500',
          '99926011','NIFTY MIDCAP 100',
          */
          '2885': 'RELIANCE',
          '3045': 'SBIN',
          '3432':'TATACONSUM',
          '11723':'JSWSTEEL',
          '3499':'TATASTEEL',
          '11630':'NTPC',
          '14977':'POWERGRID',
          '10604':'BHARTIARTL',
          '16675':'BAJAFINSV',
          '317':'BAJFINANCE',
          '1348':'HEROMOTOCO',
          '5258':'INDUSINDBK',
          '1333':'HDFCBANK',
          '1922':'KOTAKBANK',
          '11536':'TCS',
          '1594':'INFY',
          '1363':'HINDALCO',
          '17388':'ADANIPOWER',
          '236':'ASIANPAINT',
          '3506':'TITAN',
          '25780':'APLAPOLLO',
          '17963':'NESTLEIND',
          '1660':'ITC',
          '2475':'ONGC',
          '3351':'SUNPHARMA',
          '1232':'GRASIM',
          '10940':'DIVISLAB',
          '881':'DRREDDY',
          '7229':'HCLTECH',
          '3787':'WIPRO',
          '547':'BRITANNIA',
          '694':'CIPLA',
          '910':'EICHERMOT',
          '10999':'MARUTI',
          '14937':'MAHINDCIE',
          '21676':'HINDMOTORS',
          '526':'BPCL',
          '20374':'COALINDIA',
          '13538':'TECHM',
          '1394':'HINDUNILVR',
          '3563':'ADANIGREEN',
          '25':'ADANIENT',
          '5097':'ZOMATO',
          '2664':'PIDILITIND',
          '9819':'HAVELLS',
          '772':'DABUR',
          '3103':'SHREECEM',
          '13611':'IRCTC',
          '9480':'LICI',
          '4204':'MOTHERSON',
          '305':'BAJAJHLDNG',
          '2181':'BOSCHLTD',
      };
      
      const tokenIDArray = Object.keys(tokenMapping);
      
      // Store the received data in an array
      //let receivedData = [];
      
      // Handle WebSocket connection open
      socket.on('open', () => {
        //console.log('WebSocket connected');
      
         // Send a subscription request
         const subscriptionRequest = {
          //correlationID: '',
          action: 1,
          params: {
            mode: 2,
            tokenList: [
              {
                exchangeType: 1,
                tokens: tokenIDArray,
              },
              {
                exchangeType: 3,
                tokens: ['99919000'],
              },
            ],
          },
        };
      
        socket.send(JSON.stringify(subscriptionRequest));
      });
      
      // Store the latest data for each instrument
      const latestData = {};
      
      // Handle received messages from the WebSocket
      socket.on('message', (message) => {
        const data = new Uint8Array(message);
      
        // Check if the message is a heartbeat response
        if (data.length === 4 && data[0] === 112 && data[1] === 111 && data[2] === 110 && data[3] === 103) {
          // Ignore heartbeat response
          return;
        }
      
        // Parse the received binary data based on the provided response contract
      
        // Extract the Last Traded Price (LTP) and Token ID from the received data
        const ltpBytes = data.slice(43, 47);
        const closePriceBytes = data.slice(115, 122);
        const tokenIDBytes = data.slice(2, 27);
        const ltpValue = ltpBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const closePrice = closePriceBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const ltp = ltpValue / 100;
        const yesterdayPrice = closePrice / 100;
        const priceChange = parseFloat((ltp-yesterdayPrice).toFixed(2));
        const percentChange = parseFloat(((priceChange/ltp)*100).toFixed(2));
      
      //  const decoder = new TextDecoder('utf-8');
        const tokenID = new TextDecoder().decode(tokenIDBytes).replace(/\u0000/g, '');//To decode from Bytes and remove the null characters at the end of tokenID
        const tokenName = tokenMapping[tokenID];//retrieves token name for the corresponding tokenID from the tokenMapping
        // Create a JSON object with tokenID and ltp
        const jsonData = {
          tokenName: tokenName,
          ltp: ltp,
          yesterdayPrice:yesterdayPrice,
          change:priceChange,
          percentChange:percentChange,
        };
      
        // Store the latest data for the instrument
        latestData[tokenID] = jsonData;
        //console.log(latestData)
        // Display the JSON object
         console.log(jsonData);
      });
      
      // Handle WebSocket connection close
      socket.on('close', () => {
        console.log('WebSocket connection closed');
      });
      
      // Send heartbeat message every 30 seconds to keep the connection alive
      setInterval(() => {
        if (socket.readyState === WebSocket.OPEN) {
          socket.send('ping');
        }
      }, 1000);
      
      // Enable CORS
      app.use((req, res, next) => {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
        next();
      });
      
      // a GET endpoint to retrieve the latest data for all instruments
      app.get('/api/prices', (req, res) => {
          res.json(latestData);
        });
      // a GET endpoint to retrieve the latest tokenMapping for the instruments
        app.get('/api/mappings', (req, res) => {
          res.json(tokenMapping);
        });
      // Start the Express server
      app.listen(port, () => {
        console.log(`Server listening on port ${port}`);
      });
      
      posted in Bugs
      J
      Jeet Pattani
    • Cannot connect more than one websocket connection

      On the docs it says that a client ID can have 3 concurrent websocket connection. But I get an Error everytime I try to connect to for 2nd websocket connection.

      Screenshot from Docse06bdf16-d508-4525-bad0-53996e50fa87-image.png

      Using the below code I try to connect to the websocket. Please do tell if I can have more than one connections because before a few weeks the same code worked to have more than one connection.

      const express = require('express');
      const WebSocket = require('ws');
      require("dotenv").config();
      const app = express();
      const port = 3001;
      
      // WebSocket URL
      const url = 'ws://smartapisocket.angelone.in/smart-stream';
      
      // Authentication headers
      const headers = {
        'Authorization': 'Bearer '+process.env.jwtToken,
        'x-api-key': 'Q906QkvT',
        'x-client-code': 'P529774',
        'x-feed-token': process.env.feedToken
      };
      
      
      // Create a WebSocket instance
      const socket = new WebSocket(url, { headers });
      
      // Map to store tokenID to tokenName mapping
      const tokenMapping = {
          '99926037':'NIFTY FINANCIAL SERVICES',
      };
      
      const tokenIDArray = Object.keys(tokenMapping);
      
      // Store the received data in an array
      //let receivedData = [];
      
      // Handle WebSocket connection open
      socket.on('open', () => {
        //console.log('WebSocket connected');
      
         // Send a subscription request
         const subscriptionRequest = {
          //correlationID: '',
          action: 1,
          params: {
            mode: 2,
            tokenList: [
              {
                exchangeType: 1,
                tokens: ['99926037'],
              },
            ],
          },
        };
      
        socket.send(JSON.stringify(subscriptionRequest));
      });
      
      // Store the latest data for each instrument
      const latestData = {};
      
      // Handle received messages from the WebSocket
      socket.on('message', (message) => {
        const data = new Uint8Array(message);
      
        // Check if the message is a heartbeat response
        if (data.length === 4 && data[0] === 112 && data[1] === 111 && data[2] === 110 && data[3] === 103) {
          // Ignore heartbeat response
          return;
        }
      
        // Parse the received binary data based on the provided response contract
      
        // Extract the Last Traded Price (LTP) and Token ID from the received data
        const ltpBytes = data.slice(43, 47);
        const closePriceBytes = data.slice(115, 122);
        const tokenIDBytes = data.slice(2, 27);
        const ltpValue = ltpBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const closePrice = closePriceBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const ltp = ltpValue / 100;
        const yesterdayPrice = closePrice / 100;
        const priceChange = parseFloat((ltp-yesterdayPrice).toFixed(2));
        const percentChange = parseFloat(((priceChange/ltp)*100).toFixed(2));
      
      //  const decoder = new TextDecoder('utf-8');
        const tokenID = new TextDecoder().decode(tokenIDBytes).replace(/\u0000/g, '');//To decode from Bytes and remove the null characters at the end of tokenID
        const tokenName = tokenMapping[tokenID];
      
        // Create a JSON object with tokenID and ltp
        const jsonData = {
          tokenName: tokenName,
          ltp: ltp,
          yesterdayPrice:yesterdayPrice,
          change:priceChange,
          percentChange:percentChange,
        };
      
        // Store the latest data for the instrument
        latestData[tokenID] = jsonData;
        //console.log(latestData)
        // Display the JSON object
        console.log(jsonData);
      });
      
      // Handle WebSocket connection close
      socket.on('close', () => {
        console.log('WebSocket connection closed');
      });
      
      // Send heartbeat message every 30 seconds to keep the connection alive
      setInterval(() => {
        if (socket.readyState === WebSocket.OPEN) {
          socket.send('ping');
        }
      }, 29000);
      
      // Enable CORS
      app.use((req, res, next) => {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
        next();
      });
      
      // a GET endpoint to retrieve the latest data for all instruments
      app.get('/api/prices', (req, res) => {
          res.json(latestData);
        });
      // a GET endpoint to retrieve the latest tokenMapping for the instruments
        app.get('/api/mappings', (req, res) => {
          res.json(tokenMapping);
        });
      // Start the Express server
      app.listen(port, () => {
        console.log(`Server listening on port ${port}`);
      });
      
      posted in Bugs
      J
      Jeet Pattani
    • Not able to get indices data

      I am not able to get the data of indices like NIFTY 100, NIFTY 500, NIFTY FIN SERVICES using the getLtpData url, however, I can get data for Nifty and BANKNIFTY only. However I am able to get the indices data using websocket but after some responses the data I get from the websocket is ng 0 and then again for sometime I get the live feed then again I get ng 0. Any help is appreciated Thank You !

      Code using the getLtpData

      var axios = require('axios');
      var data = JSON.stringify({
        "exchange":"NSE",
        "tradingsymbol":"Nifty 100",
        "symboltoken":"99926012"
      });
      
      
      
      
      
      var config = {
        method: 'post',
        url: 'https://apiconnect.angelbroking.com/order-service/rest/secure/angelbroking/order/v1/getLtpData',
        headers: {
          'Authorization': 'Bearer JWT_TOKEN', 
          'Content-Type': 'application/json', 
          'Accept': 'application/json', 
          'X-UserType': 'USER', 
          'X-SourceID': 'WEB', 
          'X-ClientLocalIP': 'CLIENT_LOCAL_IP', 
          'X-ClientPublicIP': 'CLIENT_PUBLIC_IP', 
          'X-MACAddress': 'MAC_ADDRESS', 
          'X-PrivateKey': 'API_KEY'
        },
        data : data,
      };
      
      axios(config)
      .then(function (response) {
        console.log(JSON.stringify(response.data));
      })
      .catch(function (error) {
        console.log(error);
      });
      
      
      

      Output

      {"status":true,"message":"SUCCESS","errorcode":"","data":null}
      
      posted in Bugs
      J
      Jeet Pattani
    • RE: I got binary response from websocket. How to convert from binary to JSON?

      @muthukumardab
      Try the below code

      //Working Code which fetches prices of reliance, sbi, and nifty
      
      const WebSocket = require('ws');
      
      // WebSocket URL
      const url = 'ws://smartapisocket.angelone.in/smart-stream';
      
      // Authentication headers
      const headers = {
        'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IlA1Mjk3NzQiLCJyb2xlcyI6MCwidXNlcnR5cGUiOiJVU0VSIiwiaWF0IjoxNjg2NzE2ODYwLCJleHAiOjE2ODY4MDMyNjB9.WmoIdanOGGXox-We42Bre-qSK6yyZQlcci4h3JnLxc8Dt7WgmJZa7IzergbdB2VWPviVg7uKWAi-rOr0H5ijQw',
        'x-api-key': 'erZDHFHD',
        'x-client-code': 'P529774',
        'x-feed-token': 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IlA1Mjk3NzQiLCJpYXQiOjE2ODY3MTY4NjAsImV4cCI6MTY4NjgwMzI2MH0.fWOQ57fcTGqzuVlktvzFYVe7ztZrt8TFIkrLXvX-Z2HqOtR3cSxsDRW9uv8a9YSCKxt348gAmSondkaHmGaBBA'
      };
      
      // Create a WebSocket instance
      const socket = new WebSocket(url, { headers });
      
      // Handle WebSocket connection open
      socket.on('open', () => {
        console.log('WebSocket connected');
      
        // Send a subscription request
        const subscriptionRequest = {
          //correlationID: '',
          action: 1,
          params: {
            mode: 1,
            tokenList: [
              {
                exchangeType: 1,
                tokens: ['26000','2885','3045','99926009','99926011']
      
                /*
                NIFTY-50: 26000
                RELIANCE-EQ: 2885
                SBIN-EQ: 3045
                NIFTY BANK:99926009
                NIFTY MIDCAP 100:99926011
                SENSEX: 99919000
      
                */
      
              },
             /* {
                exchangeType: 5,
                tokens: ['234230', '234235', '234219']
              }*/
            ]
          }
        };
      
        socket.send(JSON.stringify(subscriptionRequest));
      });
      
      // Handle received messages from the WebSocket
      socket.on('message', (message) => {
        // Parse the received binary data based on the provided response contract
      
        // Example: Extract the Last Traded Price (LTP) from the received data
        const data = new Uint8Array(message);
        const ltpBytes = data.slice(43, 47);
        const ltpValue = ltpBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const ltp = ltpValue / 100;
      
        console.log('Received LTP:', ltp);
      });
      
      // Handle WebSocket connection close
      socket.on('close', () => {
        console.log('WebSocket connection closed');
      });
      
      // Send heartbeat message every 30 seconds to keep the connection alive
      setInterval(() => {
        if (socket.readyState === WebSocket.OPEN) {
          socket.send('ping');
        }
      }, 30000);
      
      
      

      P.S. I also had one question which I am not able to find answer to, how to get the price for SENSEX I am not able to find the correct token for it. Please do tell if you know how to get the ltp for sensex.

      posted in Bugs
      J
      Jeet Pattani
    • The Below JS Code Works

      Re: WebSocket 2.0 Streaming is not Receiving the Live Price Feed

      //Working Code which fetches prices of reliance, sbi, and nifty
      
      const WebSocket = require('ws');
      
      // WebSocket URL
      const url = 'ws://smartapisocket.angelone.in/smart-stream';
      
      // Authentication headers
      const headers = {
        'Authorization': 'Bearer JWT_TOKEN',
        'x-api-key': 'erZDHFHD',
        'x-client-code': 'P529774',
        'x-feed-token': 'FEED_TOKEN'
      };
      
      // Create a WebSocket instance
      const socket = new WebSocket(url, { headers });
      
      // Handle WebSocket connection open
      socket.on('open', () => {
        console.log('WebSocket connected');
      
        // Send a subscription request
        const subscriptionRequest = {
          //correlationID: '',
          action: 1,
          params: {
            mode: 1,
            tokenList: [
              {
                exchangeType: 1,
                tokens: ['26000','2885','3045','99926009','99926011']
      
                /*
                NIFTY-50: 26000
                RELIANCE-EQ: 2885
                SBIN-EQ: 3045
                NIFTY BANK:99926009
                NIFTY MIDCAP 100:99926011
                SENSEX: 99919000
      
                */
      
              },
             /* {
                exchangeType: 5,
                tokens: ['234230', '234235', '234219']
              }*/
            ]
          }
        };
      
        socket.send(JSON.stringify(subscriptionRequest));
      });
      
      // Handle received messages from the WebSocket
      socket.on('message', (message) => {
        // Parse the received binary data based on the provided response contract
      
        // Example: Extract the Last Traded Price (LTP) from the received data
        const data = new Uint8Array(message);
        const ltpBytes = data.slice(43, 47);
        const ltpValue = ltpBytes.reduce((value, byte, index) => value + byte * Math.pow(256, index), 0);
        const ltp = ltpValue / 100;
      
        console.log('Received LTP:', ltp);
      });
      
      // Handle WebSocket connection close
      socket.on('close', () => {
        console.log('WebSocket connection closed');
      });
      
      // Send heartbeat message every 30 seconds to keep the connection alive
      setInterval(() => {
        if (socket.readyState === WebSocket.OPEN) {
          socket.send('ping');
        }
      }, 30000);
      
      
      
      posted in General Discussion
      J
      Jeet Pattani
    • RE: How to get the live data from market feed for different stocks ?

      @admin I also used the wss url but it still showed error.

      posted in Bugs
      J
      Jeet Pattani