Place a CNC market BUY order
The simplest possible live order: buy equity for delivery, at whatever price the market gives you right now.
order_id = kite.place_order(
variety="regular",
exchange="NSE",
tradingsymbol="INFY",
transaction_type="BUY",
quantity=1,
product="CNC",
order_type="MARKET",
validity="DAY",
)
print("Order placed:", order_id)
Before running this against real money
- Check funds first (chapter 12) — a market order can fill at a price higher than the last-seen LTP if the market has moved or the spread is wide; don't size to exactly your available cash.
- Check the order book (chapter 18) a few seconds after placing, to confirm
status: COMPLETErather than assuming success from theorder_idresponse. - Start with
quantity=1on a liquid large-cap when testing this for the first time — the point is to verify the plumbing works, not to take a real position size.
def safe_market_buy(kite, exchange: str, symbol: str, qty: int) -> str:
available = kite.margins(segment="equity")["available"]["cash"]
ltp = kite.ltp([f"{exchange}:{symbol}"])[f"{exchange}:{symbol}"]["last_price"]
if ltp * qty * 1.02 > available: # 2% buffer for price movement
raise RuntimeError("Insufficient margin with safety buffer")
return kite.place_order(
variety="regular", exchange=exchange, tradingsymbol=symbol,
transaction_type="BUY", quantity=qty, product="CNC",
order_type="MARKET", validity="DAY",
)
Why MARKET orders are risky on anything illiquid
A market order has no price limit — it fills at whatever the exchange matches it against, walking through the order book (chapter 26) until fully filled. On a thinly-traded stock this can mean a materially worse average price than the LTP you saw a second ago. Reserve market orders for liquid instruments where you're confident the spread is tight; use limit orders (chapter 46) otherwise.