Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Web Socket Issues

    Bugs
    0
    10
    101
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      perceptron last edited by

      @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.

      M P 2 Replies Last reply Reply Quote 1
      • M
        Moderator_2 @perceptron last edited by

        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

        P 1 Reply Last reply Reply Quote 1
        • P
          perceptron @Moderator_2 last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • P
            perceptron last edited by

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

            1 Reply Last reply Reply Quote 0
            • P
              perceptron @perceptron last edited by

              @perceptron @Moderator_1 @Moderator_2 is there any update?

              1 Reply Last reply Reply Quote 0
              • N
                nitish.bane last edited by

                @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.

                R 1 Reply Last reply Reply Quote 0
                • P
                  perceptron last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • R
                    robin @nitish.bane last edited by

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

                    P 1 Reply Last reply Reply Quote 0
                    • P
                      perceptron @robin last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • P
                        pratima last edited by

                        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?

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post