How to disconnect from web-socket in NodeJS?

Sowmay
I'm trying to disconnect from a web socket connection using disconnect() and then trying to create new connection after 5 minutes. But instead of disconnecting, 2 connections are created then 3 then 4 and so on.

Also tried using triggerDisconnect() which is showing an error that triggerDisconnect() is not a function.

What I'm trying to achieve is to receive data for multiple stocks with a single call to kite connect with an interval of 5 minutes. Any best practice?
Tagged:
  • sujith
    Hi @Sowmay,
    kiteconnectjs reconnects upon disconnection.
    Did you try setting autoReconnect(false) and try?
  • Sowmay
    Will try tomorrow in market hours.

    What about "triggerDisconnect() is not a function"? What's the work of triggerDisconnect()?
  • sujith
    Hi @Sowmay,
    triggerDisconnect() is an internal function used by kiteconnectjs. You need to use websocket object to disconnect. Websocket object name is ws.
  • Sowmay
    Hi @sujith

    I set autoReconnect(false) but still, the existing connection is not disconnecting.

    ticker.autoReconnect(false)
    function setTick(ticks) {
    console.log("ticks received")
    ticker.disconnect()
    }

    First time single "ticks received" logged out then twice, then thrice and so on. Existing connections are not aborted.

    Any correction above?
  • sujith
    sujith edited April 2017
    @Sowmay,
    Can you log inside onclose callback and check?
Sign In or Register to comment.