Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/anurag-roy/kiteconnect-ts/llms.txt

Use this file to discover all available pages before exploring further.

KiteTicker is the WebSocket client for Kite Connect’s streaming quotes service. You instantiate it once with your credentials, call connect() to open the socket, then use subscribe() and setMode() to stream live market ticks. The class uses an exponential back-off algorithm for auto-reconnection and exposes a typed event system so you can react to ticks, order updates, connection state changes, and errors.

Public constants

The three tick-mode constants mirror the string literals accepted by setMode(). Use the constants rather than bare strings to benefit from TypeScript autocompletion.
ConstantValueDescription
modeFull'full'Full quote including 5-level market depth (184 bytes for tradable, 32 bytes for indices)
modeQuote'quote'Quote excluding market depth (44 bytes for tradable, 28 bytes for indices)
modeLTP'ltp'Last traded price only (8 bytes)

Constructor

constructor(params: KiteTickerParams)
Creates a new KiteTicker instance and configures auto-reconnect based on the supplied params. The WebSocket connection is not opened by the constructor — call connect() to initiate it.
import { KiteTicker } from 'kiteconnect-ts';

const ticker = new KiteTicker({
  api_key: 'YOUR_API_KEY',
  access_token: 'YOUR_ACCESS_TOKEN',
});

Connection methods

connect()

connect(): void
Opens the WebSocket connection to wss://ws.kite.trade/. If the socket is already in CONNECTING or OPEN state, the call is a no-op. Once the connection is established, the connect event fires. Register your subscribe call inside that event handler to ensure tokens are sent only after the socket is ready.
ticker.connect();

ticker.on('connect', () => {
  ticker.subscribe([738561, 779521]);
  ticker.setMode(ticker.modeFull, [738561, 779521]);
});

disconnect()

disconnect(): void
Closes the WebSocket connection. If the socket is already CLOSING or CLOSED, the call is a no-op. Calling disconnect() does not suppress auto-reconnect — call autoReconnect(false) first if you want to terminate permanently.
ticker.disconnect();

connected()

connected(): boolean
Returns true if the underlying WebSocket is in the OPEN state, false otherwise. Use this to guard calls that require an active connection.
if (ticker.connected()) {
  ticker.subscribe([738561]);
}

Event methods

on()

on<K extends TickerEvent>(e: K, callback: TickerEvents[K]): void
Registers a callback for a named WebSocket event. You can register multiple callbacks for the same event; they are called in registration order.
e
TickerEvent
required
The name of the event to listen for. One of: connect, ticks, disconnect, error, close, reconnect, noreconnect, message, order_update.
callback
TickerEvents[K]
required
The typed callback function. The signature depends on the event — see the TickerEvents type for the full map.
ticker.on('ticks', (ticks) => {
  console.log('Received ticks:', ticks);
});

ticker.on('disconnect', (error) => {
  console.error('Disconnected:', error);
});

ticker.on('reconnect', (count, interval) => {
  console.log(`Reconnecting — attempt ${count}, next in ${interval}s`);
});

ticker.on('order_update', (order) => {
  console.log('Order update:', order.order_id, order.status);
});
Available events
EventCallback signatureFired when
connect() => voidConnection established
ticks(ticks: any[]) => voidTick packets received
disconnect(error: Error) => voidConnection dropped
error(error: Error) => voidSocket error
close() => voidSocket closed cleanly
reconnect(retries: number, interval: number) => voidReconnection attempt started
noreconnect() => voidMax retries exhausted
message(data: ArrayBuffer) => voidRaw binary message received
order_update(order: Order) => voidPostback for a user’s order

Subscription methods

subscribe()

subscribe(tokens: number[]): number[]
Sends a subscription request to the server for the given instrument tokens. Returns the same token array. Tokens must be numeric instrument identifiers obtained from getInstruments(). The default mode after subscribing is ltp.
tokens
number[]
required
Array of numeric instrument tokens to subscribe to.
const tokens = [738561, 779521, 408065];
ticker.subscribe(tokens);

unsubscribe()

unsubscribe(tokens: number[]): number[]
Sends an unsubscribe request for the given tokens. The server stops streaming ticks for those tokens. Returns the same token array.
tokens
number[]
required
Array of numeric instrument tokens to unsubscribe from.
ticker.unsubscribe([738561]);

setMode()

setMode(mode: 'ltp' | 'quote' | 'full', tokens: number[]): number[]
Sets the streaming mode for the specified tokens. Use ticker.modeLTP, ticker.modeQuote, or ticker.modeFull as the mode argument. Returns the same token array.
mode
'ltp' | 'quote' | 'full'
required
The tick mode. ltp streams only the last traded price; quote adds volume and OHLC; full adds 5-level market depth and open interest.
tokens
number[]
required
Array of instrument tokens to apply the mode to.
ticker.on('connect', () => {
  const tokens = [738561];
  ticker.subscribe(tokens);
  ticker.setMode(ticker.modeFull, tokens);  // receive depth data
});

Reconnect methods

autoReconnect()

autoReconnect(t: boolean, max_retry?: number, max_delay?: number): void
Configures the auto-reconnect behaviour at runtime. Call this before connect() to override the values you passed to the constructor, or at any point to adjust limits dynamically.
t
boolean
required
true to enable auto-reconnect, false to disable it.
max_retry
number
default:"50"
Maximum number of reconnection attempts. Capped at 300.
max_delay
number
default:"60"
Maximum back-off delay in seconds. Minimum is 5.
// Allow up to 10 retries with a 30-second max delay
ticker.autoReconnect(true, 10, 30);
ticker.connect();
Set max_retry to a small number (e.g., 5–10) for scripts that should fail fast, and to a larger number (e.g., 100+) for long-running processes where market connectivity is critical.

Build docs developers (and LLMs) love