Error connecting to KiteTicker

akash_bhatiya
import { KiteTicker } from "kiteconnect";

export const watchOverMarket = async (requestToken) => {
const ticker = new KiteTicker({
api_key: process.env.ZERODHA_KEY,
access_token: requestToken,
});

ticker.connect();
ticker.autoReconnect(true, -1, 5);
ticker.on("ticks", onTicks);
ticker.on("connect", subscribe);
ticker.on("disconnect", onDisconnect);
ticker.on("error", onError);
ticker.on("close", onClose);
ticker.on("order_update", onTrade);
};

const onTicks = (ticks) => {
console.log("Ticks", ticks);
};

const subscribe = () => {
// const tokens = [738561, 256265];
const tokens = [2615553];
ticker.subscribe(tokens);
ticker.setMode(ticker.modeFull, tokens);
};

const onDisconnect = (error) => {
console.log("Closed connection on disconnect", error);
};

const onError = (error) => {
console.log("Closed connection on error", error);
};

const onClose = (reason) => {
console.log("Closed connection on close", reason);
};

const onTrade = (order) => {
console.log("Order update", order);
};


???????????????????????????????????????????getting below error???????????????????????????????????????????


Closed connection on close CloseEvent {
target: WebSocket {
_events: [Object: null prototype] {
open: [Function],
message: [Function],
error: [Function],
close: [Function]
},
_eventsCount: 4,
_maxListeners: undefined,
readyState: 3,
protocol: '',
_binaryType: 'arraybuffer',
_closeFrameReceived: false,
_closeFrameSent: false,
_closeMessage: '',
_closeTimer: null,
_closeCode: 1006,
_extensions: {},
_receiver: null,
_sender: null,
_socket: null,
_isServer: false,
_redirects: 0,
url: 'wss://ws.kite.trade/?api_key=bq8sahjxpifuiq72&access_token=t8QDnhlSqVCinxZkKJSB4Xl29Aic0rSK&uid=1725286324288',
_req: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /?api_key=bq8sahjxpifuiq72&access_token=t8QDnhlSqVCinxZkKJSB4Xl29Aic0rSK&uid=1725286324288 HTTP/1.1\r\n' +
'Sec-WebSocket-Version: 13\r\n' +
'Sec-WebSocket-Key: queyZBsE8aJhRUvGbDl+dw==\r\n' +
'Connection: Upgrade\r\n' +
'Upgrade: websocket\r\n' +
'X-Kite-Version: 3\r\n' +
'User-Agent: kiteconnectjs/5.0.0\r\n' +
'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n' +
'Host: ws.kite.trade\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: undefined,
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
joinDuplicateHeaders: undefined,
path: '/?api_key=bq8sahjxpifuiq72&access_token=t8QDnhlSqVCinxZkKJSB4Xl29Aic0rSK&uid=1725286324288',
_ended: false,
res: [IncomingMessage],
aborted: true,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'ws.kite.trade',
protocol: 'https:',
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(errored)]: null,
[Symbol(kHighWaterMark)]: 16384,
[Symbol(kRejectNonStandardBodyWrites)]: false,
[Symbol(kUniqueHeaders)]: null,
[Symbol(kError)]: undefined
},
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
type: 'close',
wasClean: false,
reason: '',
code: 1006
}

Tagged:
  • rakeshr
    type: 'close',
    wasClean: false,
    reason: '',
    code: 1006
    Can you paste here, the complete error stack trace? Error code:1006 states, the websocket was disconnected, reason would be available in the complete error trace.
Sign In or Register to comment.