Understanding Bitcoin Market Depth (by alaric)
A central part of the Bitcoin economy has been the formation of foreign currency exchange markets, where you can trade your bitcoins for US dollars, Euros, pounds Sterling, or many other currencies.
These things are important, because:
- They let people transfer their money from the fiat economy into the Bitcoin economy, allowing it to grow.
- They let people transfer their money out again, making Bitcoin a safer store of value; you're not stuck with it when you want to buy something that can't be bought with bitcoins.
- They let us measure the "current value" of a bitcoin (to some approximation), thus making it easier to price things in bitcoins
- They provide endless pretty graphs and statistics to look at.
However, one particular aspect of "the markets" that is commonly not understood is what is known as "market depth", so I'm going to give a quick introduction to how the markets work to lay the foundations, then dive into what the market depth is all about.
Markets aren't shops where you buy and sell bitcoins. Instead, they are systems that let people trade bitcoins between each other, without having to find and negotiate with each other individually.
Market orders
If I have some pounds and I want to buy bitcoins, or vice versa, I can go to a market and place an order stating my intention. It will either be something like "I have 10 bitcoins and I want to sell them for no less then £150 each" or "I have 10 pounds and I want to buy bitcoins for no more than £150 each". In order to place an order, I must have first put enough money (of the kind I'm getting rid of) into my account on the exchange; that means they can instantly transfer the money to the person I trade with when the trade happens, and makes sure I can't place orders without having the money to actually perform the offered trade.
When the order reaches the market, it tries to match the order with current "open orders" already on the market. If somebody is offering to sell BTC for £X each or more, and I'm offering to buy BTC for £Y each or less, and Y > X, then the market will perform the transaction by raising my BTC balance and lowering my £ balance - and vice versa for the person I'm trading with.
Rates of exchange
Exactly what rate we do business at must be somewhere between X and Y pounds per GBP (inclusive), as those are the terms of the offers we have placed, and is up to the policies of the exchange. And to complicate matters further, there may be more than one open order offering to sell bitcoins for pounds at exactly the same rate; whether my order satisfies the oldest order first, or the smallest, or the largest, or is satisfied from both of them in some ratio, is also down to the exchange policy. I don't need to worry or care about it, as I don't know who I'm trading with.
There is a difference, therefore, between two kinds of limit on the order. If I have £100 in my account, I might (with silly rates of exchange to make the maths clearer here!) offer to buy 10BTC for up to £10 each. The market might be able to get me them for £9 each, in which case I'd end up with 10BTC and £10 in my account.
But if I offer to buy £100 worth of BTC for up to £10 each, and it gets me them for £9 each, I will end up with 11.11111111111BTC and £0.
So, one or more existing "open orders" might be used to fulfill my order. If there's enough open orders to fill it, then the order all happens in one go, and my currency transfer is complete; I now have some money in my exchange account, which I can transfer out (with Bitcoin transfers to my own addresses, or through a bank transfer of pounds sterling).
But what if my order isn't entirely matched by what's on the exchange? What if I offer to buy £100 worth of bitcoins for up to £150 each, and there's only 0.1BTC available at that price in open orders?
Well, then my order - or the remains of it, if it's already been partially fulfilled - becomes an "open order" and I must sit and wait until a new order comes along to filfull it.
Every market has what's known as the "order book" of currently open orders, constantly changing as new orders come in, satisfy existing open orders, and then leave new open orders in turn. If you took a snapshot of the order book at a point in time, you'd see a bunch of offers to sell bitcoins for various prices or more, and a bunch of offers to buy bitcoins for various prices or less.
And those prices wouldn't overlap, or else the corresponding orders would have satisfied each other and not been left as open orders.
So there's always a lowest price you can instantly buy a bitcoin for on the exchange, and a highest price you can sell one for. And between those two prices is a gap, known as "the spread".
So when we want to say "What is the value of a bitcoin?", we can give a few answers from any given exchange. We can list the best sell price - the best price in pounds or dollars or whatever you could get. Or you can list the best buy price - what it would cost you to buy bitcoins. Or we can take the average of the two, the midpoint of the spread. Or we can take the rate at which the last actual trade on the exchange, caused by part of all of an incoming order satisfying part or all of an open order, happened. However, that price vibrates up and down as people buy and sell bitcoins - it will be close to one side of the spread or the other, depending on whether the last trade was a buy or a sell.
Market depth
However, just because the "best buy price" is £150 per BTC, that doesn't mean you can buy N bitcoins for N*£150. There best buy price might be because there's an open order to sell 0.1BTC for £150, and the next best open order might be 10BTC for £151. If I wanted to buy 1BTC, I'd be able to pay £150 for the 0.1BTC, then have to buy 0.9BTC more at £151 each. I'd pay £150.9 for 1BTC, in effect, and by using up that "0.1BTC for £150" order, I'd actually move the best buy price up to £151 so that nobody else would get the £150 price offered any more.
Therefore, the best buy/sell prices aren't always very useful indicators; the price you will pay depends on how much you're buying, and vice versa if you're selling. You need to take into account how far you will push the prices when you make your order, and that is what's known as "market depth".
Market depth charts
If you look at an online bitcoin exchange price chart such as http://bitcoinity.org/markets/mtgox/GBP, you will see two charts: the top one shows how some measure of the current price varies with time, which is all very interesting, but as we've shown there is no definite measure of "current price".
The bottom chart is where the fun is. Ignore the bars and thin lines for now, and just look at the two thick lines - one red, one green.
Or look at the bottom-most chart on http://www.bitcoincharts.com/markets/mtgoxGBP.html, where the orange line is showing the same thing as the green line on bitcoinity, and the blue line corresponds to bitcoinity's red line. Don't be alarmed if they look nothing like each other at first glance - check the horizontal scale!
The horizontal axis on a market depth chart is a price, in units of the external currency per bitcoin. The vertical axis is in bitcoins, and shows the total number of bitcoins for sale at that price or above (on the right hand side of the chart, which is the red line on bitcoinity or the blue line on bitcoincharts); or the total number of bitcoins wanted by buyers at that price or below (on the left hand side of the chart, the green line on bitcoinity or the orange line on bitcoincharts).
You can clearly see the spread, which is the little flat part of the chart between where the two lines hit zero, which are the best buy and sell prices, respectively.
Now, if you want to buy 1000BTC, you can trace how far up the right hand line your order will take you. Draw a line across the chart from 1000BTC on the vertical axis, and where it hits the right-hand line, then the price on the horizontal axis is where you'll take the price up to; for your order, that's the "worst price". Some of your bitcoins will be bought at the best price, some at the worst price, and some inbetween, so your actual price will be a weighted average of them all.
Generally, the chart looks like a valley, with two lines sloping up either side, sometimes a nice gradual slope (when there's lots of small open orders at slightly differing prices) and sometimes with cliffs (when there's a big order open at that price, or lots of little open orders at the same price all adding up).
The cliffs, which are conventionally called "walls", are interesting. At the time of writing, the bitcoin price is rising, and there is much talk of things like "breaking down the wall at £150". That means there's a big order (or a heap of small orders) all selling BTC at £150 each, causing a big cliff in the market depth chart. As the price rises towards £150 by eating up small open orders, we get closer to the wall until people start buying BTC for £150 each. But because there's a lot of BTC for sale at that price, the price sticks there for a while, as all those BTC have to be sold before it can rise. If people come to the market to sell BTC quickly during that period, they will have to place a selling order at a lower price than £150 for it to get snapped up, so the price trend chart shows the line hitting £150 and sitting there apart from little dips beneath as bitcoins for cheaper than £150 appear and are snapped up, but it sits at £150 until the wall is "eaten" and the price can continue rising.
Volatility
Walls are good for stabilising the market; they keep the price steady for a while. If everyone agreed what the real value of a bitcoin was and it wasn't changing, then we'd have two huge walls (one for buying and one for selling), with a small spread between them, and the price would remain steady; if anyone had BTC for sale, they'd either sell them at the price which has open buy orders to get them sold instantly, or sell them at the current best open sell order price in order to create an open order that just adds to the "wall" and ensures they get their chance to sell when somebody comes along trying to buy bitcoins instantly. There would only be two prices on the order book, with the spread between them being whatever profit margin market traders waiting to service the orders of people wanting instant transactions would like to make.
But in practice it'll never be that perfectly neat and tidy! We will always have different traders offering different prices as they haggle for business, and each will have different amounts of BTC to offer.
On the other hand, when the market depth chart has long shallow slopes, starting at zero from the spread outwards, the bitcoin price is volatile; it doesn't take much buying or selling to use up the small open orders at the very tip of the two slopes.
It can also be interesting to compare the relative slopes. If there's lots of big walls on the right hand side, but the left hand side is a shallow slope, then it will take a lot of buying to raise the price, but a comparatively small amount of BTC being put out for immediate sale would push the price down.
But don't read too much into it
The market depth chart visualises the current state of the market's open order book.
However, there's no reason the big traders need to leave their open orders on the exchange. A trader who places a big open order at some price knows they are creating a wall in the depth chart - and knows that people will see it, and react to it, and thereby make buying or selling decisions based upon it.
This means that canny traders might place open orders for trades they never plan to make (and will whisk them away if they seem in danger of being satisfied), or hold back on placing orders for trades they DO want to make until the very moment that best buy/sell price touches the price they want to buy or sell at, thereby avoiding the visibility of a huge wall. They can even split their order into lots of small ones and feed them into the exchange as the previous order is satisfied, thereby keeping selling or buying without ever creating a visible wall. Nonetheless, their orders will still pin the price at the point they choose until they run out of money to trade or decide to stop, just like a real wall - except that it wasn't there for people to see.
Why might a trader do this? I don't know. The strategies and motivations of traders are complicated, and may include things such as wanting to manipulate prices on one market in order to cause a panic and make people sell their bitcoins for them to buy cheaply, or to make the bitcoin price volatile in order to discourage people from using it as a currency for purchasing goods, or vice versa. A trader might put lots of money into an exchange to create two huge buy and sell walls to foster the illusion of a very stable price, only to cancel the orders as soon as people start taking advantage of them.
The scope for manipulation is tremendous, so don't read too much into the market depth chart - particularly in the regions further from the current best prices! The only open orders that really matter are those that get satisfied by new orders, and those are the ones near the spread. Anybody wanting to buy a million bitcoins would be crazy to place a single buy order for them, hoovering up all the bitcoins on the order book and pushing the price up to the massive amounts charged by some of the more hopeful orders out there; they would do better to feed in a series of small buy orders, then wait for new sell orders to appear in the gap they create before buying more, and thus get a better price (unless they really ARE in a hurry).
Markets are fascinating
The way the market works is quite interesting. Lots of people (or artificial intelligences; much trading is handled by so-called "bots") gather together to haggle, mediated and streamlined by the exchange interface itself. Somehow, all of their differing ideas on the value of a bitcoin are merged together into a consensus, and bitcoins get bought and sold at the best price for everybody involved.
I'm quite interested in the use of market models to handle resource management in software systems - the idea that functions performed by a computer might require resources such as memory and CPU time that the processes performing them need to "pay for" with a budget. The price of these resources could fluctuate based on demand, as the operating system tries to rent out memory space and CPU time at the best price it can get. When the resources were constrained, the available budgets would act as priorities, as processes whose budgets could no longer afford their usual rate of consumption would have to make themselves run more efficiently by degrading the service they perform somehow ("background" processes might just use as much as they can afford, whatever that is, and be happy with it), or stop until they can afford to run again. Given how efficiently markets can work, a correctly designed market in computer resources might offer more efficient, easy to manage, and resilient to demand surges, management of them than the traditional priority-and-quota models in use today. But that's a topic for another blog post...