Websocket unable to get token details
-
Find below code in javascript. Getting LTPs of multiple instruments but to identify them, need token details. How to decode ByteArray data of tokens. Kindly help in below code.
var ws = new WebSocket("wss://smartapisocket.angelone.in/smart-stream?clientCode=&feedToken=&apiKey=");
ws.onopen = function() { console.log("WS Open"); var data = { "correlationID": "abcde12345", "action": 1, "params": { "mode": 1, "tokenList": [ { "exchangeType": 2, "tokens": ["41034","41035"] } ] } } ws.send(JSON.stringify(data)); }; ws.onmessage = (event) => { try{ if (event.data instanceof Blob) { const arrayBufferPromise = event.data.arrayBuffer(); arrayBufferPromise.then((data) => { var l = data.byteLength; var d = new DataView(data); let position = 0; var type = d.getInt8(position); if(type == 1){ ltp_price = d.getInt32(43, true) / 100; token = d.getInt8(2, true); console.log(token+" - "+ltp_price); } }); } else { console.log("Result: " + event.data); } }catch (e){ console.log("Error : "+ e); } }; ws.onclose = function() { console.log("Connection is closed..."); };
-
Hello @kashyapgodhani
Could you please use the sdk of python/java/node. it's already handled there so it colud be more helpful for you
Regards,
SmartAPI Team