Getting encoded message from web socket in javascript


  • Followed the below steps to create and subscribe to a channel.

    1. Creating websocket for wss://wsfeeds.angelbroking.com/NestHtml5Mobile/socket/stream by passing the CLIENT_CODE and FEED_TOKEN as query params.
    let socket = new WebSocket("wss://wsfeeds.angelbroking.com/NestHtml5Mobile/socket/stream"+"?CLIENT_CODE=" + CLIENT_CODE + "&FEED_TOKEN=" + FEED_TOKEN);
    
    1. sending request for task "cn"
    var _req = '{"task":"cn","channel":"","token":"' + FEED_TOKEN + '","user": "' + CLIENT_CODE + '","acctid":"' + CLIENT_CODE + '"}'; 
    socket.send(_req);
    
    1. Sending the request for task market watch "mw" and channel "mcx_fo|231091"
    var strwatchlistscrips = "mcx_fo|231091";
                var _req = '{"task":"mw","channel":"' + strwatchlistscrips + '","token":"' + FEED_TOKEN + '","user": "' + CLIENT_CODE + '","acctid":"' + CLIENT_CODE + '"}'; 
                socket.send(_req);
    
    1. listening on-message
    socket.onmessage = function (event) {
                console.log(new Date(),'-[ message ]', event.data)
            };
    

    console output:
    Screenshot 2021-09-08 at 2.03.37 PM.png


  • Hi @sammy kindly go through the decode logic from the SDK.


  • HI @sammy We have noted your issue we will update you on this you can also follow below link to use web socket in java script.
    https://github.com/angelbroking-github/smartapi-javascript