It is a heartbeat tick from the server to check if the connection to client is intact or not. You need to send a subscribe message in order to get ticks.
Hello, I am using laravel. Let me share my code here. I am already sending subscribe request. I have one question. I think, once I send subscribe requet to socket server, then from next, I will get real time update via websocket. right?
var api_key="{{$api_key}}"; var access_token="{{$access_token}}" var ws = new WebSocket(`wss://ws.kite.trade?api_key=${api_key}&access_token=${access_token}`); var instrument_tokens=JSON.parse(`<?php echo json_encode($instrument_tokens); ?>`); for(let i=0;i<instrument_tokens.length;i++) instrument_tokens[i]=parseInt(instrument_tokens[i]); // var message = {"a": "mode", "v": ["full", instrument_tokens]}; var message = {"a": "subscribe", "v": instrument_tokens};
ws.addEventListener('open', function (event) { ws.send(JSON.stringify(message)) });
ws.addEventListener('message', function (event) { var data=event.data; // if(data.type!="") console.log('Message from server ', data); });
Message from server {"type":"order","id":"","data":{"placed_by":"ZT8813","order_id":"200313002588328","exchange_order_id":"1300000005114990","parent_order_id":null,"status":"COMPLETE","status_message":null,"status_message_raw":null,"order_timestamp":"2020-03-13 12:31:57","exchange_update_timestamp":"2020-03-13 12:31:57","exchange_timestamp":"2020-03-13 11:05:39","variety":"regular","exchange":"NSE","tradingsymbol":"RELIANCE","instrument_token":738561,"order_type":"LIMIT","transaction_type":"SELL","validity":"DAY","product":"MIS","quantity":50,"disclosed_quantity":0,"price":1065,"trigger_price":0,"average_price":1065,"filled_quantity":50,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"meta_raw":null,"meta":{},"tag":null,"guid":"01XbVWgX3D7BLCS","account_id":"ZT8813","unfilled_quantity":0,"app_id":1,"checksum":""}}
I am using laravel.
Let me share my code here.
I am already sending subscribe request.
I have one question.
I think, once I send subscribe requet to socket server, then from next, I will get real time update via websocket. right?
var api_key="{{$api_key}}";
var access_token="{{$access_token}}"
var ws = new WebSocket(`wss://ws.kite.trade?api_key=${api_key}&access_token=${access_token}`);
var instrument_tokens=JSON.parse(`<?php echo json_encode($instrument_tokens); ?>`);
for(let i=0;i<instrument_tokens.length;i++)
instrument_tokens[i]=parseInt(instrument_tokens[i]);
// var message = {"a": "mode", "v": ["full", instrument_tokens]};
var message = {"a": "subscribe", "v": instrument_tokens};
ws.addEventListener('open', function (event) {
ws.send(JSON.stringify(message))
});
ws.addEventListener('message', function (event) {
var data=event.data;
// if(data.type!="")
console.log('Message from server ', data);
});
Message from server {"type":"order","id":"","data":{"placed_by":"ZT8813","order_id":"200313002588328","exchange_order_id":"1300000005114990","parent_order_id":null,"status":"COMPLETE","status_message":null,"status_message_raw":null,"order_timestamp":"2020-03-13 12:31:57","exchange_update_timestamp":"2020-03-13 12:31:57","exchange_timestamp":"2020-03-13 11:05:39","variety":"regular","exchange":"NSE","tradingsymbol":"RELIANCE","instrument_token":738561,"order_type":"LIMIT","transaction_type":"SELL","validity":"DAY","product":"MIS","quantity":50,"disclosed_quantity":0,"price":1065,"trigger_price":0,"average_price":1065,"filled_quantity":50,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"meta_raw":null,"meta":{},"tag":null,"guid":"01XbVWgX3D7BLCS","account_id":"ZT8813","unfilled_quantity":0,"app_id":1,"checksum":""}}
That is all I can get via websocket.
Can you echo sent instrument_token and it's data type and paste the response here?
These are instrument tokens.
v: [121345, 5633, 3350017, 6599681, 5436, ...]}
These are message for subscribe request.
How many instruments are you subscribing in a single connection?
Also, can check it's data type?
message = {"a": "mode", "v": ["ltp", [884737]]};
ws.send(JSON.stringify(message))
They are converting array into string.
var instrument_tokens=JSON.parse(`<?php echo json_encode($instrument_tokens); ?>`);
for(let i=0;i<instrument_tokens.length;i++)
instrument_tokens[i]=parseInt(instrument_tokens[i]);
and I am already making int.