Hi, I am building my own trading platform on PHP. I just wanted ask using the Web sockets, can I get the live quotes? And will there be any delay in such live quotes as compared to Zerodha kite?
I am not getting binary even after encoding the data structure to JSON.
Here is the sample code. Please help me how to decode the same to get live quotes.
function WebSocketTest() { if ("WebSocket" in window) { // Let us open a web socket var ws = new WebSocket("wss://websocket.kite.trade/?api_key=&user_id=&public_token="); ws.binaryType = "blob"; ws.onopen = function() { // Web Socket is connected, send data using send() var message = {"a": "mode", "v": ["full", [408065]]}; ws.send(JSON.stringify(message)) }; ws.onmessage = function (t) { if(t.data instanceof ArrayBuffer) { if(t.data.byteLength > 2) { //var d = parseBinary(t.data); console.log(t.data); /* if(d) { trigger("tick", [d]); } */ } } if(t.data instanceof Blob){ t.data = new Blob(); console.log(t.data); } }; ws.onclose = function() { // websocket is closed. console.log("Connection is closed..."); }; } else { // The browser doesn't support WebSocket alert("WebSocket NOT supported by your Browser!"); } }
and also, can you please share me the reflink for the websockets?
Here is the docs for Websocket streaming - https://kite.trade/docs/connect/v1/#streaming-websocket
I am not getting binary even after encoding the data structure to JSON.
Here is the sample code. Please help me how to decode the same to get live quotes.
function WebSocketTest() { if ("WebSocket" in window) { // Let us open a web socket var ws = new WebSocket("wss://websocket.kite.trade/?api_key=&user_id=&public_token="); ws.binaryType = "blob"; ws.onopen = function() { // Web Socket is connected, send data using send() var message = {"a": "mode", "v": ["full", [408065]]}; ws.send(JSON.stringify(message)) }; ws.onmessage = function (t) { if(t.data instanceof ArrayBuffer) { if(t.data.byteLength > 2) { //var d = parseBinary(t.data); console.log(t.data); /* if(d) { trigger("tick", [d]); } */ } } if(t.data instanceof Blob){ t.data = new Blob(); console.log(t.data); } }; ws.onclose = function() { // websocket is closed. console.log("Connection is closed..."); }; } else { // The browser doesn't support WebSocket alert("WebSocket NOT supported by your Browser!"); } }
I think i have found the Solution for the same Issue in this forum. Thank you anyway.