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 exposes a complete order management surface: you can place every order variety (regular, AMO, CO, BO, iceberg, and auction), modify open orders, cancel or exit them, and pull the full audit trail of executions. Two margin calculation methods let you pre-check buying power before committing a trade.

placeOrder

Place a new order for an equity or derivative instrument.
const { order_id } = await kc.placeOrder('regular', {
  exchange: 'NSE',
  tradingsymbol: 'INFY',
  transaction_type: 'BUY',
  quantity: 1,
  product: 'CNC',
  order_type: 'MARKET',
});
console.log('Placed order:', order_id);
Signature: placeOrder(variety: Variety, params: PlaceOrderParams): Promise<{ order_id: string }>
variety
string
required
Order variety. One of regular, amo, bo, co, iceberg, auction.
exchange
string
required
Exchange where the instrument is listed. One of NSE, BSE, NFO, BFO, CDS, BCD, MCX.
tradingsymbol
string
required
Exchange trading symbol of the instrument (e.g., RELIANCE, INFY).
transaction_type
string
required
BUY or SELL.
quantity
number
required
Number of units to trade.
product
string
required
Margin product code. One of CNC, NRML, MIS, CO, BO.
order_type
string
required
MARKET, LIMIT, SL, or SL-M.
validity
string
Order validity: DAY, IOC, or TTL.
price
number
Limit price. Required for LIMIT and SL orders.
trigger_price
number
Trigger price. Required for SL and SL-M orders, and for CO orders.
disclosed_quantity
number
Quantity visible in the public order book (equity only).
squareoff
number
Square-off value for bracket orders (bo variety).
stoploss
number
Stop-loss value for bracket orders.
trailing_stoploss
number
Trailing stop-loss value for bracket orders.
validity_ttl
number
Validity in minutes when validity is TTL.
iceberg_legs
number
Total number of legs for an iceberg order (variety iceberg).
iceberg_quantity
number
Quantity per iceberg leg.
auction_number
number
Unique auction identifier for auction variety orders.
tag
string
Optional alphanumeric tag (max 20 chars) to identify the order.

modifyOrder

Modify an open order’s price, quantity, validity, or trigger.
const { order_id } = await kc.modifyOrder('regular', '112111182345', {
  price: 1450.5,
  quantity: 2,
  order_type: 'LIMIT',
  validity: 'DAY',
});
Signature: modifyOrder(variety: Variety, order_id: string, params): Promise<{ order_id: string }>
variety
string
required
The variety of the original order (regular, amo, bo, co, etc.).
order_id
string
required
The unique ID of the order to modify.
quantity
number
New order quantity.
price
number
New limit price.
order_type
string
New order type: MARKET, LIMIT, SL, or SL-M.
validity
string
New validity: DAY or IOC.
disclosed_quantity
number
New disclosed quantity.
trigger_price
number
New trigger price.
parent_order_id
string
Parent order ID for multi-leg orders such as CO.

cancelOrder

Cancel an open order.
const { order_id } = await kc.cancelOrder('regular', '112111182345');
Signature: cancelOrder(variety: Variety, order_id: string, params?): Promise<{ order_id: string }>
variety
string
required
Variety of the order being cancelled.
order_id
string
required
ID of the order to cancel.
parent_order_id
string
Parent order ID for multi-leg orders.

exitOrder

exitOrder is an alias for cancelOrder. Both accept the same parameters and return the same result. Use exitOrder when the intent is to exit a CO or BO leg.
await kc.exitOrder('co', '112111182345', { parent_order_id: '112111182000' });

getOrders

Retrieve all orders placed for the current trading day.
const orders = await kc.getOrders();
orders.forEach((o) => console.log(o.order_id, o.status, o.tradingsymbol));
Returns Promise<Order[]>. Key fields on each Order:
FieldTypeDescription
order_idstringUnique order ID
exchange_order_idstring | nullExchange-assigned ID (null if order didn’t reach exchange)
statusstringCOMPLETE, OPEN, CANCELLED, REJECTED, etc.
tradingsymbolstringInstrument symbol
transaction_typestringBUY or SELL
quantitynumberTotal ordered quantity
filled_quantitynumberQuantity filled so far
pending_quantitynumberRemaining quantity
average_pricenumberAverage fill price
order_timestampDateWhen the API registered the order
status_messagestring | nullHuman-readable status (e.g., rejection reason)

getOrderHistory

Retrieve the state transitions for a single order.
const history = await kc.getOrderHistory('112111182345');
history.forEach((state) => console.log(state.status, state.order_timestamp));
Returns Promise<Order[]> — an array of Order snapshots, one per state change.

getTrades

Retrieve all trades executed during the current trading day.
const trades = await kc.getTrades();
trades.forEach((t) => console.log(t.trade_id, t.average_price, t.filled));
Returns Promise<Trade[]>. Key fields on each Trade:
FieldTypeDescription
trade_idstringExchange-assigned trade ID
order_idstringAssociated order ID
tradingsymbolstringInstrument symbol
transaction_typestringBUY or SELL
average_pricenumberPrice at which the lot was filled
fillednumberFilled quantity in this trade
fill_timestampDateWhen the trade was filled at the exchange

getOrderTrades

Retrieve trades associated with a specific order. A single order can be filled across multiple tranches.
const trades = await kc.getOrderTrades('112111182345');
Returns Promise<Trade[]>.

orderMargins

Calculate the margin required for a list of orders before placing them. Pass 'compact' as the second argument to get a leaner response containing only the total margin.
import { KiteConnect, MarginOrder } from 'kiteconnect-ts';

const orders: MarginOrder[] = [
  {
    exchange: 'NSE',
    tradingsymbol: 'INFY',
    transaction_type: 'BUY',
    variety: 'regular',
    product: 'MIS',
    order_type: 'MARKET',
    quantity: 10,
  },
];

const margins = await kc.orderMargins(orders);
// margins: Margin[]
console.log(margins[0].total, margins[0].span, margins[0].exposure);
Overloads:
  • orderMargins(orders: MarginOrder[]): Promise<Margin[]>
  • orderMargins(orders: MarginOrder[], mode: 'compact'): Promise<CompactMargin[]>
Margin includes: total, span, exposure, option_premium, additional, bo, cash, var, pnl, leverage, and a detailed charges breakdown. CompactMargin contains only type, tradingsymbol, exchange, and total.

orderBasketMargins

Calculate combined margin for a basket of orders, optionally accounting for your existing positions. Three overloads are available.
const result = await kc.orderBasketMargins(orders);
console.log(result.initial.total, result.final.total);
// result.orders[i] — per-order margin
Overloads:
  • orderBasketMargins(orders): Promise<{ initial: Margin; final: Margin; orders: Margin[] }>
  • orderBasketMargins(orders, consider_positions): Promise<{ initial: Margin; final: Margin; orders: Margin[] }>
  • orderBasketMargins(orders, consider_positions, mode: 'compact'): Promise<{ initial: CompactMargin; final: CompactMargin; orders: CompactMargin[] }>
consider_positions defaults to true.

Build docs developers (and LLMs) love