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.

All types described here are exported directly from kiteconnect-ts and derived from the source without modification. Import them alongside the class:
import {
  KiteTicker,
  Tick,
  TickFull,
  TickerEvent,
  TickerEvents,
  KiteTickerParams,
} from 'kiteconnect-ts';

Tick packet types

The WebSocket server sends binary packets in one of five formats depending on the mode and whether the instrument is an index or a tradable instrument. Each format maps to a distinct TypeScript interface. All five are united in the Tick discriminated union type.

TickLtp

The smallest possible packet — 8 bytes. Produced when mode is set to ltp for any instrument.
interface TickLtp {
  tradable: boolean;
  mode: 'ltp';
  instrument_token: number;
  last_price: number;
}
tradable
boolean
false for indices, true for all tradable instruments.
mode
'ltp'
Discriminant literal — always 'ltp' for this type.
instrument_token
number
Numeric instrument token.
last_price
number
Last traded price.

TickIndexQuote

Produced for index instruments in quote mode (28 bytes). Extends TickLtp with OHLC and change data.
interface TickIndexQuote extends Omit<TickLtp, 'mode'> {
  mode: 'quote';
  ohlc: { high: number; low: number; open: number; close: number };
  change: number;
}
mode
'quote'
Discriminant literal — always 'quote' for this type.
instrument_token
number
Numeric instrument token.
last_price
number
Last traded price.
ohlc
object
change
number
Percentage change from previous close.

TickIndexFull

Produced for index instruments in full mode (32 bytes). Extends TickIndexQuote with an exchange timestamp.
interface TickIndexFull extends Omit<TickIndexQuote, 'mode'> {
  mode: 'full';
  timestamp: Date;
}
mode
'full'
Discriminant literal — always 'full' for this type.
timestamp
Date
Exchange timestamp of the tick.

TickQuote

Produced for tradable (non-index) instruments in quote mode (44 bytes). Extends TickLtp with volume, OHLC, and depth-adjacent totals.
interface TickQuote extends Omit<TickLtp, 'mode'> {
  mode: 'quote';
  last_traded_quantity: number;
  average_traded_price: number;
  volume_traded: number;
  total_buy_quantity: number;
  total_sell_quantity: number;
  ohlc: { open: number; high: number; low: number; close: number };
  change: number;
}
mode
'quote'
Discriminant literal.
last_traded_quantity
number
Quantity in the last trade.
average_traded_price
number
Volume-weighted average price.
volume_traded
number
Total volume traded today.
total_buy_quantity
number
Total pending buy quantity in the order book.
total_sell_quantity
number
Total pending sell quantity in the order book.
ohlc
object
change
number
Percentage change from previous close.

TickFull

The largest packet — 184 bytes. Produced for tradable instruments in full mode. Extends TickQuote with timestamps, open interest, and 5-level market depth.
interface TickFull extends Omit<TickQuote, 'mode'> {
  mode: 'full';
  last_trade_time: Date;
  exchange_timestamp: Date;
  oi: number;
  oi_day_high: number;
  oi_day_low: number;
  depth: {
    buy:  { quantity: number; price: number; orders: number }[];
    sell: { quantity: number; price: number; orders: number }[];
  };
}
mode
'full'
Discriminant literal.
last_trade_time
Date
Timestamp of the last trade.
exchange_timestamp
Date
Exchange packet timestamp.
oi
number
Open interest (F&O instruments).
oi_day_high
number
Day’s highest open interest.
oi_day_low
number
Day’s lowest open interest.
depth
object
5-level order book. Contains ten entries total — five buy (bid) levels and five sell (ask) levels.

Tick (discriminated union)

type Tick =
  | TickLtp
  | TickIndexQuote
  | TickIndexFull
  | TickQuote
  | TickFull;
Tick is the discriminated union of all five packet types. The discriminant is mode. TypeScript narrows the type inside each branch so you only access fields that are actually present in the packet.

Type narrowing example

import { Tick, TickFull } from 'kiteconnect-ts';

ticker.on('ticks', (ticks: Tick[]) => {
  for (const tick of ticks) {
    if (tick.mode === 'full') {
      // tick is TickFull here — depth is available
      console.log('Best bid:', tick.depth.buy[0]?.price);
      console.log('Best ask:', tick.depth.sell[0]?.price);
      console.log('OI:', tick.oi);
    } else if (tick.mode === 'quote') {
      // tick is TickIndexQuote | TickQuote
      console.log('Volume:', (tick as any).volume_traded ?? 'index');
    } else {
      // tick is TickLtp
      console.log('LTP:', tick.last_price);
    }
  }
});
TickIndexQuote and TickQuote share the same mode: 'quote' discriminant but have different shapes. Distinguish them using the tradable field — indices always have tradable: false.

Event types

TickerEvent

type TickerEvent = keyof TickerEvents;
// 'connect' | 'ticks' | 'disconnect' | 'error' | 'close'
// | 'reconnect' | 'noreconnect' | 'message' | 'order_update'
A string union of all valid event names you can pass to ticker.on().

TickerEvents

type TickerEvents = {
  connect:       () => void | Promise<void>;
  ticks:         (ticks: any[]) => void | Promise<void>;
  disconnect:    (error: Error) => void | Promise<void>;
  error:         (error: Error) => void | Promise<void>;
  close:         () => void | Promise<void>;
  reconnect:     (retries: number, interval: number) => void | Promise<void>;
  noreconnect:   () => void | Promise<void>;
  order_update:  (order: Order) => void | Promise<void>;
  message:       (data: ArrayBuffer) => void | Promise<void>;
};
A mapped type where each key is a TickerEvent name and the value is the exact callback signature the on() method expects. TypeScript enforces the correct callback signature at the call site.
EventCallbackDescription
connect() => voidFired when WebSocket opens
ticks(ticks: any[]) => voidFired when tick packets are received
disconnect(error: Error) => voidFired when connection drops
error(error: Error) => voidFired on socket errors
close() => voidFired on clean socket close
reconnect(retries, interval) => voidFired on each reconnect attempt
noreconnect() => voidFired when max retries is exhausted
order_update(order: Order) => voidFired when a user order postback arrives
message(data: ArrayBuffer) => voidFired for every raw binary frame
import { TickerEvents } from 'kiteconnect-ts';

// Use the mapped type to define typed callbacks
const onTicks: TickerEvents['ticks'] = (ticks) => {
  console.log(`Received ${ticks.length} ticks`);
};

const onReconnect: TickerEvents['reconnect'] = (retries, interval) => {
  console.log(`Attempt ${retries}, next in ${interval}s`);
};

ticker.on('ticks', onTicks);
ticker.on('reconnect', onReconnect);

OrderUpdatePostback

interface OrderUpdatePostback extends Order {}
The shape of the data delivered to order_update callbacks. It is identical to the Order interface from kiteconnect-ts — see the KiteConnect type reference for all fields.
ticker.on('order_update', (order) => {
  // order has all fields of the Order interface
  console.log(order.order_id, order.status, order.filled_quantity);
});

Param types

KiteTickerParams

Constructor parameters for KiteTicker. See the KiteTickerParams reference for full details.
api_key
string
required
API key issued by Zerodha.
access_token
string
required
Access token from the login flow.
reconnect
boolean
Enable auto-reconnect. Default: true.
max_retry
number
Maximum reconnection attempts. Default: 50, maximum: 300.
max_delay
number
Maximum back-off delay in seconds. Default: 60, minimum: 5.
root
string
WebSocket server URL. Default: "wss://ws.kite.trade/".

Complete usage example

import { KiteTicker, Tick } from 'kiteconnect-ts';

const ticker = new KiteTicker({
  api_key: process.env.KITE_API_KEY!,
  access_token: process.env.KITE_ACCESS_TOKEN!,
});

ticker.connect();

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

ticker.on('ticks', (ticks: Tick[]) => {
  for (const tick of ticks) {
    if (tick.mode === 'full') {
      // tick is TickFull here, depth is available
      console.log(tick.depth.buy);
    }
  }
});

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

ticker.on('order_update', (order) => {
  if (order.status === 'COMPLETE') {
    console.log(`Order ${order.order_id} filled at ${order.average_price}`);
  }
});

Build docs developers (and LLMs) love