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.

KiteConnect is the primary class in kiteconnect-ts. It wraps every Kite Connect v3 HTTP endpoint as a typed, promise-returning method, so you can build trading applications in TypeScript without hand-crafting HTTP calls or parsing raw JSON. You initialize a single instance per API key and reuse it across your application.

Constructor

Instantiate KiteConnect with your API key. All other parameters are optional.
import { KiteConnect } from 'kiteconnect-ts';

const kc = new KiteConnect({
  api_key: 'YOUR_API_KEY',
});
api_key
string
required
The API key issued to you by Zerodha.
access_token
string
The session token obtained after a successful login flow. Persist this in a database or session store and pass it here on subsequent requests. Defaults to null.
root
string
default:"https://api.kite.trade"
Root URL for all API calls. Override only when you need to point at a non-production endpoint.
debug
boolean
default:"false"
When true, the client logs every request and response to the console.
timeout
number
default:"7000"
Milliseconds to wait for a response before the request is rejected with a network error.

Quick start

import { KiteConnect } from 'kiteconnect-ts';

const kc = new KiteConnect({ api_key: 'YOUR_API_KEY' });

// Exchange request_token (from login redirect) for an access_token
const session = await kc.generateSession('REQUEST_TOKEN', 'YOUR_API_SECRET');
console.log('Access token:', session.access_token);

// On subsequent runs, set the stored token directly
kc.setAccessToken('STORED_ACCESS_TOKEN');

// All API methods return promises
const orders = await kc.getOrders();
console.log(orders);
The access token expires at 6 AM every trading day as required by SEBI regulation. You must re-authenticate daily and store the new token.

Session helpers

MethodDescription
setAccessToken(token)Set the active access token after it has been retrieved.
setSessionExpiryHook(cb)Register a callback invoked when the API returns a TokenException.
getLoginURL()Build the redirect URL that initiates the browser-based login flow.
generateSession(request_token, api_secret)Exchange a request_token for an access_token.
invalidateAccessToken(access_token?)Invalidate the current or specified access token.
renewAccessToken(refresh_token, api_secret)Renew using a refresh token (available to select platforms).

Explore by topic

Orders

Place, modify, cancel, and inspect equity and derivatives orders. Fetch margin requirements before you trade.

Portfolio

Read holdings and positions, convert product types, and access auction instruments.

Market data

Fetch live quotes, OHLC, LTP, historical candles, and the full instruments master.

Mutual funds

Place and cancel MF orders, create and manage SIPs, and browse MF holdings and instruments.

GTT

Create price-triggered orders that persist until the condition is met or the GTT expires.

All methods

Authentication & session

  • getLoginURL()
  • generateSession(request_token, api_secret)
  • setAccessToken(access_token)
  • setSessionExpiryHook(cb)
  • invalidateAccessToken(access_token?)
  • renewAccessToken(refresh_token, api_secret)

User

  • getProfile()
  • getMargins(segment?)

Orders

  • placeOrder(variety, params)
  • modifyOrder(variety, order_id, params)
  • cancelOrder(variety, order_id, params?)
  • exitOrder(variety, order_id, params?)
  • getOrders()
  • getOrderHistory(order_id)
  • getTrades()
  • getOrderTrades(order_id)
  • orderMargins(orders, mode?)
  • orderBasketMargins(orders, consider_positions?, mode?)

Portfolio

  • getHoldings()
  • getAuctionInstruments()
  • getPositions()
  • convertPosition(params)

Market data

  • getInstruments(exchange?)
  • getQuote(instruments)
  • getOHLC(instruments)
  • getLTP(instruments)
  • getHistoricalData(instrument_token, interval, from_date, to_date, continuous?, oi?)

Mutual funds

  • getMFOrders(order_id?)
  • placeMFOrder(params)
  • cancelMFOrder(order_id)
  • getMFSIPS(sip_id?)
  • placeMFSIP(params)
  • modifyMFSIP(sip_id, params)
  • cancelMFSIP(sip_id)
  • getMFHoldings()
  • getMFInstruments()

GTT (Good-Till-Triggered)

  • getGTTs()
  • getGTT(trigger_id)
  • placeGTT(params)
  • modifyGTT(trigger_id, params)
  • deleteGTT(trigger_id)

Utilities

  • validatePostback(postback_data, api_secret)

Build docs developers (and LLMs) love