No response recieved from ticker (Node.js)

arsh_makker
hi,

I am trying to implement the ticker (websocket client) but I am getting no response from the ticker.
(this might be due to the fact that I am trying this on a weekend or in the night :))
My code snippet:
function startWebSocket (api_key, user_id, public_token){
console.log("-----inside function startWebSocket------");
check(api_key,String);
check(user_id, String);
check(public_token, String);
let KiteTicker = require("kiteconnect").KiteTicker;
let ticker = new KiteTicker(api_key, user_id, public_token);
console.log("-----Getting ticker started ------");
console.log(ticker);
console.log("-----starting the Ticker ------");
ticker.connect();
console.log("Ticker connected: "+ticker.connected());
ticker.on("tick", logTick);
ticker.on("connect", onTickerSubscribe);
ticker.on("unsubscribe", onTickerUnSubscribe);
ticker.on("disconnect", onTickerDisconnet);
function logTick(ticks) {
console.log("-----recieved quote ------");
console.log("Ticks", ticks);
}

function onTickerSubscribe() {
console.log("Ticker connected: "+ticker.connected());
console.log("-----Subscribing to WS ------");
let items = [11654402];
ticker.subscribe(items);
ticker.setMode(ticker.modeLTP, items);
}

function onTickerUnSubscribe(){
console.log("-----Ticker Unsubscribed ------");
console.log("Ticker connected: "+ticker.connected());
}
function onTickerDisconnet () {
console.log("-----Ticker Disconnected ------");
console.log("Ticker connected: "+ticker.connected());
}
}
The logs from the server:
I20170218-07:42:01.999(5.5)? ------REcieved the response from Zerodha server--------
I20170218-07:42:02.005(5.5)? -----inside function startWebSocket------
I20170218-07:42:02.007(5.5)? -----Getting ticker started ------
I20170218-07:42:02.019(5.5)? { modeFull: 'full',
I20170218-07:42:02.019(5.5)? modeQuote: 'quote',
I20170218-07:42:02.020(5.5)? modeLTP: 'ltp',
I20170218-07:42:02.021(5.5)? autoReconnect: [Function],
I20170218-07:42:02.021(5.5)? connect: [Function],
I20170218-07:42:02.022(5.5)? disconnect: [Function],
I20170218-07:42:02.022(5.5)? connected: [Function],
I20170218-07:42:02.022(5.5)? on: [Function],
I20170218-07:42:02.023(5.5)? subscribe: [Function],
I20170218-07:42:02.024(5.5)? unsubscribe: [Function],
I20170218-07:42:02.025(5.5)? setMode: [Function] }
I20170218-07:42:02.027(5.5)? -----starting the Ticker ------
I20170218-07:42:02.028(5.5)? Ticker connected: false
I20170218-07:42:03.174(5.5)? Ticker connected: true
I20170218-07:42:03.175(5.5)? -----Subscribing to WS ------
I20170218-07:42:33.173(5.5)? -----Ticker Disconnected ------
I20170218-07:42:33.174(5.5)? Ticker connected: false
I20170218-07:42:38.199(5.5)? -----Ticker Disconnected ------
I20170218-07:42:38.200(5.5)? Ticker connected: false
Will appreciate any help.

REgards
ARsh
  • sujith
    @arsh_makker,
    You should subscribe inside onConnected() not OnSubscribed().
  • arsh_makker
    hi @sujith

    I cant find the onConnected() in the kiteconnectjs documentation, but if you were referring to my code; i have modified it as per your recommendation here:
    startWebSocket: function (api_key, user_id, public_token){
    console.log("-----inside function startWebSocket------");

    check(api_key,String);
    check(user_id, String);
    check(public_token, String);

    let KiteTicker = require("kiteconnect").KiteTicker;
    let ticker = new KiteTicker(api_key, user_id, public_token);
    console.log("-----Getting ticker started ------");
    console.log(ticker);
    console.log("-----starting the Ticker ------");

    ticker.autoReconnect(true,10);
    ticker.on("tick", logTick);
    ticker.on("connect", onTickerConnected);
    ticker.on("unsubscribe", onTickerUnSubscribe);
    ticker.on("disconnect", onTickerDisconnet);
    ticker.on("reconnecting", onTickerReconnecting);

    ticker.connect();
    console.log("Ticker connected: "+ticker.connected());

    function onTickerReconnecting(interval){
    console.log("-----reconnecting ------");
    console.log("duration:" +duration);
    }


    function logTick(ticks) {
    console.log("-----recieved quote ------");
    console.log("Ticks:"+ticks);
    }

    function onTickerConnected() {
    console.log("Ticker connected: "+ticker.connected());
    console.log("-----Subscribing to WS ------");
    let items = [11654402];
    ticker.subscribe(items);
    ticker.setMode(ticker.modeLTP, items);
    }

    function onTickerUnSubscribe(){
    console.log("-----Ticker Unsubscribed ------");
    console.log("Ticker connected: "+ticker.connected());
    }

    function onTickerDisconnet () {
    console.log("-----Ticker Disconnected ------");
    console.log("Ticker connected: "+ticker.connected());
    }
    }
    still the same results:
    I20170223-10:02:48.778(5.5)? ------Recieved the request Token from Zerodha server--------
    I20170223-10:02:48.789(5.5)? -----inside function startWebSocket------
    I20170223-10:02:48.791(5.5)? -----Getting ticker started ------
    I20170223-10:02:48.807(5.5)? { modeFull: 'full',
    I20170223-10:02:48.808(5.5)? modeQuote: 'quote',
    I20170223-10:02:48.808(5.5)? modeLTP: 'ltp',
    I20170223-10:02:48.809(5.5)? autoReconnect: [Function],
    I20170223-10:02:48.810(5.5)? connect: [Function],
    I20170223-10:02:48.810(5.5)? disconnect: [Function],
    I20170223-10:02:48.810(5.5)? connected: [Function],
    I20170223-10:02:48.811(5.5)? on: [Function],
    I20170223-10:02:48.812(5.5)? subscribe: [Function],
    I20170223-10:02:48.812(5.5)? unsubscribe: [Function],
    I20170223-10:02:48.813(5.5)? setMode: [Function] }
    I20170223-10:02:48.815(5.5)? -----starting the Ticker ------
    I20170223-10:02:48.828(5.5)? Ticker connected: false
    I20170223-10:02:49.852(5.5)? Ticker connected: true
    I20170223-10:02:49.852(5.5)? -----Subscribing to WS ------
    I20170223-10:03:19.851(5.5)? -----Ticker Disconnected ------
    I20170223-10:03:19.853(5.5)? Ticker connected: false
    I20170223-10:03:24.870(5.5)? -----Ticker Disconnected ------
    I20170223-10:03:24.871(5.5)? Ticker connected: false
  • sujith
    @arsh_makker,
    We just copy pasted your code and changed instrument token to liquid scrip. Above code works fine.
  • arsh_makker
    could u give me the instrument_token for the liquid scrip please?
  • arsh_makker
    arsh_makker edited February 2017
    nope didnt work, any other options.... the function logTick is never triggered :(
    psst.. I am behind a firewall currently, does that have an affect on this?
  • vishnus
    @arsh_makker

    It could. We tried your exact same code and it was working for us. Can you try in different network?
  • arsh_makker
    I tried this from my home, and still the same issue (without the firewall)..
    While debugging i found out that the Binary data was coming in the form of 'MessageEvent.data' which had 'Blob' type but in the kiteconnectjs the code is checking for 'ArrayBuffer'. I think this might be an issue.

    is this by design?.. if yes please suggest what else I can do?
  • sujith
    Hi @arsh_makker,
    I didn't understand
    i found out that the Binary data was coming in the form of 'MessageEvent.data' which had 'Blob' type but in the kiteconnectjs the code is checking for 'ArrayBuffer'.
    . Can you elaborate?
  • arsh_makker
    in kiteconnectjs, I found the following code:
    if(e.data instanceof ArrayBuffer) {
    if(e.data.byteLength > 2) {
    var d = parseBinary(e.data);
    if(d) {
    trigger("tick", [d]);
    }
    }
    }
    but when I make a websocket connection on the client end (no nodejs, just plain old javascript), i get the
    (e.data instanceof Blob) === true 
    and not of ArrayBuffer.

    Any relations, you think?
  • sujith
    Hi @arsh_makker,
    You get binary data there, it is array of bytes. It is not blob. You can check out more information about packet structure here. I don't think you should be making any changes there.
  • arsh_makker
    yup, i did check it from there, but please do notice that when i start a javascript websocket at the front end, it works but when i use the kiteconnect... ticker in the server environment it does not work.
    currenlty i am trying to figure out how to debug the nodejs code in the server side. only then can i really be sure. :)
  • arsh_makker
    Hi,

    I have just reconfigured the vanila websocket on the server, and still the kite connect websocket does not give any response, except the heartbeat.

    has anyone else used kiteconnect nodejs client on server till date? if yes, can you please share your code?
    Regards
    Arsh
  • arsh_makker
    I was able to figure it out, please close this thread.
This discussion has been closed.