Market Structure & Order Types
Understand how markets work, the types of orders you can place, and how your algorithms interact with other market participants.
How Markets Work
At the core of any market is a simple concept: someone wants to buy, someone wants to sell, and they meet at an agreed price. But the mechanics of how this happens are crucial for algorithm design.
The Limit Order Book
The limit order book is the central electronic system that matches buyers and sellers. On the buy (bid) side, you see offers from people willing to buy at various prices. On the sell (ask) side, you see offers from people willing to sell. The spread between the highest bid and lowest ask is called the bid-ask spread—this is the cost of trading.
Order Types: Your Tools
| Order Type | Execution | When to Use | Tradeoffs |
|---|---|---|---|
| Market | Instant execution at best available price | When speed matters more than price | May execute at worse price than expected (slippage) |
| Limit | Execute only at your specified price or better | When price matters more than speed | May not fill if price is hit only briefly |
| Stop (Stop-Loss) | Triggers when price hits level, then sends market order | Automatic risk protection | Can be gapped past (gaps in price) |
| Stop-Limit | Triggers at price, then sends limit order | More control than stop order | May miss execution completely |
Time-in-Force Rules
- GTC (Good Till Cancelled): Order stays active until filled or manually cancelled
- GTD (Good Till Date): Order stays active until a specific date
- DAY: Order only valid for today (cancelled at market close)
- IOC (Immediate or Cancel): Fill what you can now, cancel the rest
- FOK (Fill or Kill): Execute entire order immediately or cancel (no partial fills)
Market Participants
- Retail traders: Individual traders like you (small orders)
- Institutional investors: Hedge funds, mutual funds, pensions (large orders)
- Market makers: Firms that quote both bid and ask, profit from spread
- High-frequency traders (HFT): Very fast algorithms trading microsecond timescales
The Spread is Always a Cost
Every time you trade, you either pay the spread (market orders) or risk not filling (limit orders). Your algorithm's profitability must overcome this cost. Typically, expect spreads of $0.01-$0.05 per share on liquid stocks.
- Markets are driven by a continuous auction between buyers and sellers
- The bid-ask spread is the cost of instant execution
- Different order types offer different guarantees and tradeoffs
- Understanding time-in-force rules is critical for algorithm design