Web Socket Issues


  • @Moderator_1 I am using smart api for creating a live data feed for stock prices on my site. I am using live websocket streaming service. But issue is in javascript sdk prices of almost 400-500 stocks are received 0. I also tried quote mode but still no success. Can you tell me what could be the issue?

    const getConnection = async () => {
          db = await spp.find({});
          var array = db.map(obj => obj.token);
          var bbb = array.slice(1000,);
          const rtg = await aaaa();
          abc(bbb, rtg);
      };
      
    module.exports = getConnection;
    
    function abc(array, data) {
      const web_socket = new WebSocketV2({
        jwttoken: data.jwtToken,
        apikey: 'API_KEY',
        clientcode: "CLIENT_CODE",
        feedtype: data.feedToken,
      });
    
      web_socket.connect().then((res) => {
        let json_req = {
          "correlationID": "abcde12345",
          "action": 1,
          "mode": 2,
          "exchangeType": 1,
          "tokens": array
        };
    
        web_socket.fetchData(json_req);
        web_socket.on('tick', receiveTick);
        var x = 0;
        async function receiveTick(data) {
          if (data.token !== undefined) {
            
            const io = getIO();
            const tokenWithQuotes = data.token;
            const tokenWithoutQuotes = tokenWithQuotes.replace(/['"]+/g, '');
            
            const price = parseInt(data.last_traded_price, 10) / 100;
            // console.log(tokent_to_stock[tokenWithoutQuotes],price);
            if(price == 0) {
              x++;
              console.log(tokent_to_stock[tokenWithoutQuotes], x);
            }
              io.to(tokent_to_stock[tokenWithoutQuotes]).emit('update', {
                stock: tokent_to_stock[tokenWithoutQuotes],
                price: price
              });
    
              await spp.updateOne(
                { token: tokenWithoutQuotes },
                [{
                  $set: {
                    previousprice: "$currentprice",
                    currentprice: price
                  }
                }]
              );
          }
        }
      });
    }
    

    this is my code.


  • My WebSocket connection in Node.js works fine initially, fetching data as expected. However, after around 1.5 hours, the connection inexplicably drops while the Node.js server remains running. To resume data fetching, I have to manually stop and restart the Node.js server. How can I address this issue?


  • @robin they are not giving any updates why so? i have asked them so many times.


  • @nitish-bane i too facing same problem when i increase tokens to 20+ ticks are late by 2,3 seconds.
    @admin123 Please reply.


  • @Moderator_2 @Moderator_1 Is there any update please i need this.


  • @perceptron I think there is some issue with websockets when more number of tokens are subscribed. I facing a similar problem where I am subscribing to 200 tokens and I am observing delays in receiving ticks.


  • @perceptron @Moderator_1 @Moderator_2 is there any update?


  • @Moderator_2 @Moderator_1 is there any progress on this issue?


  • @Moderator_2 I am initiating 2 sockets basically with first socket having 0 to 1000 NSE stocks and other having the rest. I do not think that should be much of an issue because even when i am initiating request with only one socket and one stock this error persists.


  • HI @perceptron

    We are verifying on the issue. Will update you asap.
    Please check if the websocket connection is initiated within limit (three connection only allowed per client code).

    Regards,
    SmartAPI team