Kiteconnect NodeJS Websocket

ananth1994
I'm using official kiteconnect nodejs package to get live market feeds, I'm facing two problems

1) It's reconnecting atleast 100 - 200 times from 09:15 AM to 03:20 PM. Which leads to resubscribe to list of instruments 100 - 200 times. Is there a way to keep the connection alive?

2) After 03:20 PM I don't want to keep this connection alive, Which is keep creating above issue even after market close, So is there a method to disconnect/close the connection?
Tagged:
  • sujith
    Hi @ananth1994,
    Can you paste the complete stack trace?
    Try running in debug mode to get the complete stack trace.

    You need to call unsubscribe and then disconnect method.
  • ananth1994
    Hi @sujith

    1) I'll post the stack trace of kt.on("reconnect",{}) soon.

    2) I did unsubscribe and then disconnect but still it's getting auto reconnect and calling subscribe again & again.
  • ananth1994
    ananth1994 edited November 26
    const KiteTicker = require("kiteconnect").KiteTicker;
    let kt = new KiteTicker({
    api_key: '<<api_key>>',
    access_token: '<<access_token>>'
    });

    function onTicks(ticks) {
    console.log("ticks");
    }

    function subscribe() {
    console.log("subscribe");
    kt.subscribe([341249]);
    kt.setMode(kt.modeFull, [341249]);
    }

    kt.connect();
    kt.on("ticks", onTicks);
    kt.on("connect", subscribe);

    setTimeout(()=>{
    console.log("disconnect");
    kt.unsubscribe([341249]);
    kt.disconnect();
    },5000);
    --------------------------------------------------------------------------
    Result:
    >> subscribe
    >> ticks
    >> disconnect
    >> subscribe
    >> ticks
  • Vivek
    Vivek edited November 26
    1. Getting disconnected could be reliability issue with your network and if you enabled auto connect then it will try to resubscribe after getting connected.
    2. You can disable `autoReconnect` before disconnecting after 3.30. In next release we will add utility method to do this.
    kt.autoReconnect(false, 20, 5);
    kt.disconnect();
This discussion has been closed.