Before any code, you need a correct mental model of what a market is. Strip away the jargon and a modern electronic exchange is one thing: a limit order book — a continuously updated list of everyone’s resting orders, matched by a simple, fair set of rules. Almost everything in this course (building a book in Lesson 3, matching in Lesson 4, strategies in Lesson 11, costs in Lesson 12) is an elaboration of ideas in this one lesson. Get the order book clear in your head and the rest follows.
A note I’ll repeat because it matters: this is educational material about how systems work, not financial advice. Understanding markets is engineering knowledge; deciding to trade real money is a serious personal decision with real risk of loss.
The Limit Order Book
At any instant, for any instrument (a stock, a future, an option), there’s a book of resting orders: people willing to buy at various prices (bids) and people willing to sell at various prices (asks, or offers). The book sorts them by price.
Three ideas to take from the picture:
- Best bid and best ask. The highest price a buyer will pay (best bid) and the lowest price a seller will accept (best ask) are the two that matter most — they’re the current “touch” of the market. In the diagram, the best bid is 101.75 and the best ask is 102.00.
- The spread. The gap between best bid and best ask (here ₹0.25) is the spread. It’s a real cost: if you buy at the ask and immediately sell at the bid, you lose the spread. Liquid instruments have tight spreads; illiquid ones have wide spreads, which is why liquidity matters so much (Lesson 12).
- Depth. Beyond the best prices, there’s quantity resting at each level (the bar lengths). The total available near the touch is the market’s depth — it tells you how much you can trade before you push the price (which is where slippage comes from, Lesson 12). Seeing this depth is what Level 2 / Level 3 market data gives you (Lesson 3).
The book is alive: every new order, cancellation, and trade changes it, many times per second. Your trading system’s first job is to maintain an accurate picture of this book from the exchange’s data feed (Lesson 3), and to understand that when you trade, you’re interacting with this book — adding to it, or removing from it.
Order Types You’ll Actually Use
You act on the book by sending orders. There are many exotic types, but three families cover almost everything:
- Market order — “fill me now, at whatever price.” It crosses the spread and takes liquidity from the book immediately. You’re guaranteed to trade (if there’s liquidity) but not at a guaranteed price — on a thin or fast-moving book you can get a worse price than you saw (slippage). Market orders remove liquidity.
- Limit order — “fill me at this price or better, otherwise wait.” A buy limit at 101.75 will only trade at 101.75 or lower. It may rest in the book unfilled (you’re now providing liquidity, and might earn the spread), or it may never fill if the market moves away. Limit orders give you price control at the cost of fill certainty.
- Stop orders (stop-loss / stop-limit) — “stay dormant until the price hits a trigger, then become a market or limit order.” These are mostly for risk control — getting out if the market moves against you (Lesson 8’s risk, Lesson 12’s discipline).
The market-vs-limit choice is a genuine trade-off you’ll make constantly: market orders pay the spread for certainty; limit orders try to earn the spread but risk not filling. Market makers (Lesson 2, Lesson 11) live on the limit side, quoting both bids and asks and earning the spread; momentum strategies often cross with market orders to get in now. Which you use is a strategy decision with a direct cost consequence.
A few more terms you’ll meet: IOC (immediate-or-cancel — fill what you can right now, cancel the rest), order validity (day orders vs good-till-cancelled), and lot sizes / tick sizes (instruments trade in minimum quantity increments and minimum price increments — a tick is the smallest price move). Your broker adapter (Lesson 9) has to respect all of these.
The Indian Market, for an Algo Engineer
Now the specifics of where you’ll plug in. The structure matters because it determines what’s possible for you and what the rules allow.
The essentials:
- Exchanges: NSE and BSE. The National Stock Exchange and Bombay Stock Exchange run the order books for equities, derivatives (futures & options, “F&O”), and currency. The NSE in particular is one of the world’s most active derivatives venues.
- The segments you’ll use. Most retail algo activity is in cash/equity intraday and especially F&O — index and stock options. India’s options market, with its heavy weekly expiries on indices, is enormous and shapes a lot of retail strategy (it’s why we spend a whole section on options selling in Lesson 11).
- Access tiers — and this is crucial for the latency theme. As a retail trader you connect through a broker’s API (REST for orders, WebSocket for data) over the public internet — that’s a milliseconds game. Professional firms rent colocation: a physical rack inside the exchange’s datacentre, a few metres from the matching engine — that’s a microseconds game (Lessons 6–7). Knowing which game you’re in keeps you honest about what strategies are even viable for you.
SEBI’s rules for retail algos
This part is non-negotiable and changes over time, so treat the specifics as “check before you act” rather than gospel. Retail algorithmic trading in India is regulated by SEBI, and the framework has been tightening: broadly, algos used by retail traders need to go through broker-approved channels, orders placed via API are tagged/identified, and there are registration thresholds above which faster or more automated strategies face more oversight. The intent is to keep automated retail trading transparent and controlled.
The practical takeaway for you as a builder: before you deploy anything that places live orders, read your broker’s current algo policy and SEBI’s latest circular. The rules evolve, brokers implement them differently, and “I didn’t know” is not a defence. Build your system so that going live is a deliberate, compliant step — not something you back into.
What This Means for Your System
Three design consequences flow directly from the structure above, and they’ll echo through the course:
- You trade through a broker, not the exchange. Your orders and data go via your broker’s API, so their rate limits, latency, uptime and quirks are your constraints. This is exactly why Lesson 9 builds a clean broker-adapter layer.
- You’re in the milliseconds game, so don’t design for microseconds. Retail latency over the internet means you should pick strategies whose edge doesn’t depend on winning a speed race you can’t win (Lessons 6–7). Compete on edge and discipline, not nanoseconds.
- Options and their structure matter a lot in India. The depth of the index-options market and the weekly-expiry rhythm make options strategies (Lesson 11) central to Indian retail algo trading — so we treat them seriously, including the risks of selling them.
Pitfalls to Avoid
- Confusing market and limit orders. Market orders pay the spread and can slip; limit orders may not fill. Know which cost you’re accepting.
- Ignoring the spread and depth. The spread is a real, recurring cost, and thin depth means your own order moves the price (slippage, Lesson 12).
- Designing for microsecond latency as a retail trader. You’re in the milliseconds game; picking strategies that need to win the speed race is a losing plan.
- Forgetting you trade through a broker. Their limits, latency and downtime are your constraints — design for them (Lesson 9).
- Deploying a live algo without checking SEBI/broker rules. Retail algos are regulated and the rules change. Confirm compliance before placing live orders.
- Treating “understanding markets” as “ready to trade”. This is engineering knowledge; trading real money is a separate, risky decision. Not financial advice.
Quick Recap
- A market is a limit order book: bids below, asks above, the spread between the best of each, with depth (quantity) at each price level.
- Orders match by price-time priority (best price first, then earliest). Market orders take liquidity and pay the spread; limit orders provide liquidity and may earn it but risk not filling; stops trigger at a level.
- In India you trade NSE/BSE through a broker’s API (milliseconds), while pros colocate (microseconds); F&O, especially index options with weekly expiries, dominates retail.
- SEBI regulates retail algos — approved channels, order tagging, thresholds — and the rules evolve; check before going live.
- This is educational, not financial advice.
Next lesson: who else is in this market with you — HFT firms, market makers, prop desks, and fellow retail algos — and the honest truth about where a trading edge actually comes from.