6 · The book Draft

Market making and the decision loop

4 min read

On this page

6.7 What the strategy does with the book

The book exists for one reader: the strategy, the code that decides what orders the desk should have at the venue. The strategy of the capstone, the project that closes the book, is a market maker, and this section explains as much of one as the capstone needs: what it is paid for, the loop that turns a changed top into orders, and which thread does what. In shape none of it is particular to trading. It is a control loop like a thermostat’s: read a measurement, work out where the output should be, and act only when that differs from where the output is.

What a market maker does

A market maker is a trader who posts a bid and an ask at the same time, a little below and a little above the mid, the halfway point between the best bid and the best ask, and earns the spread, the difference between its two prices, when both are filled. Each of the two is a resting order: a limit order that did not match when it arrived, so it sits in the venue’s book at its price until someone trades against it. The pair, a price and a size on each side, is the market maker’s quote, and the word is used for either half as well. If the desk bids 500 lots at 6,812,344 and asks 6,812,349 for 500 lots, and a seller trades against the bid and then a buyer against the ask, the desk has bought 0.5 BTC at $68,123.44 and sold it at $68,123.49: 5 ticks, $0.05 a BTC, $0.025 on the pair.

The spread is pay for two risks. The first is the price moving against a resting order: the picked-off fill, in which the desk’s bid is taken by a seller who knows the price has fallen. One such fill of 54 ticks on 0.5 BTC loses $0.27, the spread from more than ten such pairs. The second is inventory: the position the desk holds, lots bought minus lots sold, positive when it has bought more than it has sold (long) and negative when it has sold more (short). A market maker does not choose what it buys; it buys what sellers bring. When the price is falling, sellers keep trading against its bid, and it ends up long of something nobody else wants, losing value while it holds it.

So the quote is placed around the mid, and skewed. Skew is a shift of both quotes in the direction that reduces the position, growing with the position. When the desk is long, both move down: the ask comes nearer the mid, so the next buyer is more likely to take it, and the bid moves further away, so the next seller is less likely to add to the position. When the desk is short, both move up. A mid, a half-spread either side of it, and a skew from inventory: that is the whole strategy the capstone needs.

The loop

The loop’s output is a cancel-replace, one message that asks the venue to cancel a resting order and place a new one in its place, usually at a new price. The venue processes it as two actions: the old order leaves the book, then the new one enters, and the gap between them, however short, is time with no quote on that side. The new order also joins the back of the queue at its price, as any new order does under price-time priority, where among orders at one price the earliest trades first. So the loop sends one only for a side whose desired order differs from the one resting:

From a trusted book event to a quote decision

From a trusted book event to a quote decision. Select the diagram to open it at full size.

Only a changed top drives the loop. The quote depends on the mid and the inventory, and the mid depends only on the best bid and best ask, so a deep level changing does not move it. The top-changed flag that apply returns is the only gate the loop needs, and most updates stop there. Two other events enter at the recompute step: a fill, which changes the inventory, and the copy leaving Live, the state in which its top can be trusted, for which the desired quote is no quote at all and both sides are cancelled.