Get market depth (5-level book)
Depth is nested inside quote()'s response (chapter 25) — there's no separate depth-only endpoint in Kite Connect's REST API (WebSocket "full" mode, chapter 39, streams it continuously instead).
quote = kite.quote(["NSE:INFY"])["NSE:INFY"]
depth = quote["depth"]
print("Best bid:", depth["buy"][0])
print("Best ask:", depth["sell"][0])
{
"buy": [
{"price": 1478.80, "quantity": 75, "orders": 3},
{"price": 1478.75, "quantity": 120, "orders": 5},
# ... up to 5 levels
],
"sell": [
{"price": 1479.00, "quantity": 60, "orders": 2},
{"price": 1479.05, "quantity": 200, "orders": 4},
# ... up to 5 levels
],
}
Compute the spread and estimate market-order impact
def bid_ask_spread(depth: dict) -> float:
return depth["sell"][0]["price"] - depth["buy"][0]["price"]
def estimate_market_buy_cost(depth: dict, qty: int) -> float:
"""Walks the ask side to estimate average fill price for a market buy."""
remaining = qty
cost = 0.0
for level in depth["sell"]:
take = min(remaining, level["quantity"])
cost += take * level["price"]
remaining -= take
if remaining <= 0:
break
if remaining > 0:
raise ValueError("Order size exceeds visible depth — expect significant slippage")
return cost / qty
Why this matters before placing a market order
A wide spread or thin depth on a given level means a market order will walk through multiple price levels, filling at a worse average price than the last-traded price you saw a moment ago. Checking depth before firing a market order — especially in F&O strikes far from ATM, or small-cap equity — is the single easiest way to avoid a nasty surprise on fill price versus your backtest assumptions (chapter 86).