A stock exchange is a complex beast, but much of it can be reduced to a single data structure: the Order Book. A Bitcoin exchange uses the same data structure when trading currency pairs of USD, BTC, or ETH. This article will show you how to:
- Design an order book that can handle limit orders and market orders
- Install automated sanity checks that run on every write to the order book, preventing hacks and implementation bugs
- Build an HTTP API that people can use to interact with the order book
We won’t work with actual bitcoins or wallets, since they add a lot of complexity and risk without making the article any more interesting. Instead, we’ll assume the “billing code” has already been written and focus only on the order book portion of the exchange.
币安是全球领先的数字货币交易平台，提供比特币、以太坊、BNB 以及 USDT 交易。