Part 2 of 8 · 2 min read
Scope and numbers
Small in users, strict in time.
Think of an auction house where every bid and offer must be matched fairly and instantly, in the order received, with a perfect record of what happened.
Questions and the answers assumed here (from the book's sample talk).
- Which securities? Stocks only, not options or futures.
- Which orders? Place a new order and cancel an order. Only limit orders (a buy or sell with a fixed price).
- Hours? Normal trading hours only.
- Scale? Tens of thousands of users trading at once, at least 100 symbols, and billions of orders a day.
- Risk checks? Simple ones, such as a user may trade at most 1 million shares of one stock in a day.
- Funds? An order must be covered by the user's wallet, and the money is held while the order waits.
Non-functional requirements.
- Availability at least 99.99 per cent. That allows 8.64 seconds of downtime a day (86,400 × 0.0001).
- Fault tolerance with fast recovery.
- Latency at the millisecond level or better, watching the 99th percentile. The measure runs from an order entering to its fill returning.
- Security: accounts with identity checks, and protection against attacks on public pages.
Numbers (from the book).
- Trading time: 6.5 hours a day (9:30 to 16:00).
- Orders: 1 billion a day. 1,000,000,000 / (6.5 × 3,600) is about 43,000 a second.
- Peak: 5 times, about 215,000 a second, since the open and close are busiest.
Words about the market.
- Broker: the firm that gives retail clients an app and sends orders to the exchange.
- Order book: all open buy and sell orders of one symbol, sorted by price.
- Bid and ask: the highest price a buyer offers, and the lowest price a seller asks. The gap is the spread.
- Market order: executes at once at the best price. A limit order waits for its price.
- L1, L2, L3: market data detail. L1 is the best bid and ask. L2 adds the quantity at each price level. L3 adds each order in the queue at each level.
- Candlestick: a summary of one time interval by its first, last, highest and lowest price.
- FIX: a common message format for trading, created in 1991.
Order book
An order book lists the open buy and sell orders for one symbol, grouped by price, with the oldest orders first at each price.
Example: sell 500 at 100.10 and sell 300 at 100.11, and buy 400 at 100.09. The best ask is 100.10 and the best bid is 100.09.
Check yourself: 1. How is the 43,000 figure worked out? 2. What does 99.99 per cent allow each day? 3. What is the spread?