Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs
    1. Home
    2. perceptron
    3. Best
    P
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by perceptron

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

      posted in Bugs
      P
      perceptron
    • RE: Not getting connected to Websocket2.0

      @Moderator_2 I am still getting the same error anyway. I have just initiated one socket.

      posted in General Discussion
      P
      perceptron