@arjunender, Can you give us some tokens for which you tried? You need to use instrument tokens in instrument file and not exchange tokens. For example, you can get live data for Nifty 50 with instrument token 256265.
not only these, if i subscirbe other token in between if there is any change in the data then only i am getting the data for example DABUR17APRFUT - 11865090
@arjunender, The expected behavior is, when you subscribe for 20 tokens you will get one tick for all tokens and then you will get data only when there is a change in data. Same websockets is being used on all our platforms and we haven't received any complaint like this.
If it is not working as expected then paste your code here.
var getquote_response = ""; var KiteConnect = require("kiteconnect").KiteConnect; var kc = new KiteConnect(api_key); var KiteTicker = require("kiteconnect").KiteTicker; var ticker = new KiteTicker();
// in this method assigning public token,access token etc app.get('/ck', function (req, res) { try { userid = req.query.val1.toString(); access_token = req.query.val2.toString(); public_token = req.query.val3.toString(); request_token = req.query.val4.toString(); ticker = new KiteTicker(api_key, userid, public_token, "wss://websocket.kite.trade/"); kc.setAccessToken(access_token);
You do get one tick for each token when you subscribe for it.
I am able to get all subscribed data after market hours not between market hours
Can you check if there is any error and put log inside onDisconnect().
What client are you using?
I am not receiving any error while subscribing and tick data
i am using Node.js and angular.js and using ServeEvents
Thanks
Can you give us some tokens for which you tried?
You need to use instrument tokens in instrument file and not exchange tokens. For example, you can get live data for Nifty 50 with instrument token 256265.
Below are tokens which i am subscribing
11532802 IOC17MARFUT
11507202 BPCL17MARFUT
11521794 HDFCBANK17MARFUT
11521026 HDFC17MARFUT
11557890 RECLTD17MARFUT
11556354 PFC17MARFUT
11807746 NIFTY17APRFUT
11860738 COALINDIA17APRFUT
11906562 HDFCBANK17APRFUT
11807746 NIFTY17APRFUT
11932930 INDUSINDBK17APRFUT
11910146 ICICIBANK17APRFUT
11906562 HDFCBANK17APRFUT
11910146 ICICIBANK17APRFUT
not only these, if i subscirbe other token in between if there is any change in the data then only i am getting the data for example DABUR17APRFUT - 11865090
any suggestions
Thanks
The expected behavior is, when you subscribe for 20 tokens you will get one tick for all tokens and then you will get data only when there is a change in data.
Same websockets is being used on all our platforms and we haven't received any complaint like this.
If it is not working as expected then paste your code here.
Here is my code :
App.js
var getquote_response = "";
var KiteConnect = require("kiteconnect").KiteConnect;
var kc = new KiteConnect(api_key);
var KiteTicker = require("kiteconnect").KiteTicker;
var ticker = new KiteTicker();
// in this method assigning public token,access token etc
app.get('/ck', function (req, res) {
try {
userid = req.query.val1.toString();
access_token = req.query.val2.toString();
public_token = req.query.val3.toString();
request_token = req.query.val4.toString();
ticker = new KiteTicker(api_key, userid, public_token, "wss://websocket.kite.trade/");
kc.setAccessToken(access_token);
ticker.connect();
ticker.on("tick", setTick);
ticker.on("connect", subscribe);
sess = req.session;
res.json("success")
} catch (e) {
res.json(e.message)
}
});
function setTick(ticks) {
getquote_response = ticks;
}
app.post('/subscribe_symbols', function (req, res) {
items.push(all tokens here)
ticker.subscribe(items);
ticker.setMode(ticker.modeFull, items);
res.json("")
});
var openConnections = [];
app.get('/getdata', function (req, res) {
try {
req.socket.setTimeout(Number.MAX_VALUE);
} catch (e) {
console.write(e.message)
}
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
"Access-Control-Allow-Origin": "*"
});
openConnections.push(res);
req.on("close", function () {
var toRemove;
for (var j = 0; j < openConnections.length; j++) {
if (openConnections[j] == res) {
toRemove = j;
break;
}
}
openConnections.splice(j, 1);
console.log(openConnections.length);
});
});
setInterval(function () {
openConnections.forEach(function (resp) {
var d = new Date();
resp.write('id: ' + d.getMilliseconds() + '\n');
resp.write('data:' + senddata() + '\n\n'); // Note the extra newline
});
}, 1000);
function senddata() {
return JSON.stringify(getquote_response);
}
angular js
first fetching tokens from Database and subscribing
$http.post('/subscribe_symbols', { params: tokens }).then(
function (response) {
//subscribed successfully
},
function (res) { }
);
after that calling serverevents
var source = new EventSource('/getdata');
source.addEventListener('message', handleCallback, false);
var handleCallback = function (response) {
var ds = JSON.parse(response.data)
alert(ds.length)
}
Thanks
Websocket authentication happens with the public token, try setting public token after you set access token.