not receiving subscribed tokens data

arjunender
Hi,

I am subscribing around 20 tokens with modeFull on page load

but not getting all 20 tokens data at once, but getting if there is any change in the data

I need all 20 takens data at once on page load

Any suggestions

Thanks
  • sujith
    Hi @arjunender,
    You do get one tick for each token when you subscribe for it.
  • arjunender
    Hi Sujith,
    I am able to get all subscribed data after market hours not between market hours

  • sujith
    sujith edited March 2017
    Hi @arjunender,
    Can you check if there is any error and put log inside onDisconnect().
    What client are you using?
  • arjunender
    Hi Sujith,

    I am not receiving any error while subscribing and tick data
    i am using Node.js and angular.js and using ServeEvents

    Thanks
  • sujith
    @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.
  • arjunender
    Hi sujith,

    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
  • sujith
    @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.
  • arjunender
    Hi sujith,

    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





  • sujith
    @arjunender,
    Websocket authentication happens with the public token, try setting public token after you set access token.
Sign In or Register to comment.