insideout Get Pro

05 · Data feeds and rebuilding the book

Pro

Markets, lesson 5

Data feeds and rebuilding the book

Every change goes out as a numbered message, and you rebuild the book.

You know how orders rest, match, get cancelled and get amended in a book.

Part 1. Messages, not the book

Nobody outside the exchange can see its book. What you get is a stream of short messages, one for each change, and your program builds its own copy from them. Run the feed and keep your copy right.

Your book builderLive

Each message said one small thing: an order was added, traded or cancelled. Your program applied them in order and held anything that came after a skip. Applying past the gap didn't crash anything. It quietly left shares at 100 that weren't there, and a program trading on that book would trade on a price that doesn't exist.

Market data feed and sequence number

The market data feed is the stream of messages an exchange sends for every change to its book. Each message carries a sequence number, one higher than the last. A skip means you missed something. A repeat means a copy.

Your turn

You've received every message up to 1043. The next one is 1046. How many are missing?

1044 and 1045 never arrived: 1046 − 1043 − 1 = 2. Until you get them back, your book can't be trusted.

Part 2. Ask again, or start over

Keep going with Pro

You've done the first part. Pro opens the rest of this lesson, and every other one.

Still to come
  1. Ask again, or start over
  2. What your program must remember
  3. How much detail you get
  4. A worked problem
  5. The same thing, for real

Markets overviewSpotted a mistake? Tell us.