It looks like you're new here. If you want to get involved, click one of these buttons!
//ForWebSocket
exports.connectSocket = function(req,res) {
const { id } = req.params;
UserModels.getRequestToken(id, function(err, result){
var accessToken = result.access_token;
console.log("accessToken => "+ accessToken);
var ticker = new KiteTicker({
api_key: process.env.apiKey,
access_token: accessToken
});
ticker.autoReconnect(true, 10, 5)
ticker.connect();
ticker.on("connect", subscribe);
ticker.on("ticks", onTicks);
ticker.on("connect", function() {
console.log("connect");
});
ticker.on("noreconnect", function() {
console.log("noreconnect");
});
ticker.on("reconnecting", function(reconnect_interval, reconnections) {
console.log("Reconnecting: attempt - ", reconnections, " innterval - ", reconnect_interval);
});
function onTicks(ticks) {
console.log("Ticks 2 => ", ticks);
var data = ticks;
for (let index = 0; index < data.length; index++) {
var subscribRecords = new SubscribRecords(data[index]);
InstrumentsModels.saveSubscribRecords(subscribRecords),function(err,result){
};
}
}
<b class="Bold"> function subscribe() {
InstrumentsModels.getInstrumentsSelected(function(err,result){
var instrument= [];
//var items = [260105,256265,21490690,21490946,21491202];
for(var i =0; i < result.length; i++){
instrument.push(result[i].instrument_token);
}
ticker.subscribe(instrument);
ticker.setMode(ticker.modeFull, instrument);
});
}</b>
});
res.redirect('/');
}
Also, you can print the array that you are sending and check.