← notes

Quoting a price you are willing to be held to

Jul 22, 2018

An over-the-counter desk that provides quotes and executes trades, in Flask.

quote.py, buy.py, sell.py, and an Alembic migration named price_tables. Small app, holding the design question every OTC desk has to answer.

A quote is an offer, which means it is a promise you can be held to. The moment you hand someone a price and let them decide whether to take it, you have written them a free option: they can wait, watch the market, and execute only if it moves their way. If the quote does not expire that option is unlimited, and a client can hold a favourable quote and hit you at the worst possible moment.

So a quote record needs an expiry and has to be consumed atomically at execution. Both parts matter. Expiry bounds the option; atomic consumption stops the same quote being executed twice, which is the classic check-then-act race with money on the end of it. The transaction turning a quote into a trade must be the thing that marks it used, in one operation.

The unintuitive consequence is that the spread has to widen with quote duration. A thirty-second quote and a five-minute quote on the same size are different products, because the second is a longer option.

Buy and sell are separate paths, which is right, they are not symmetric in inventory terms.