Order-book imbalance
Imbalance compares the shares waiting to buy with the shares waiting to sell near the top of the book. Near +1 the book is bid-heavy, near −1 it is ask-heavy, and 0 means balanced.
01The formula
- the imbalance over the top N price levels, between −1 and +1
- shares resting at the i-th best bid level
- shares resting at the i-th best ask level
- how many levels on each side you count
02See it move
03Where it is used
- Market makerSkews quotes away from the heavy side, pulling back a bid that sits in front of a large ask queue.
- Quant researcherUses imbalance at several depths as a feature to predict the next mid-price move over the next seconds.
- Execution traderDelays a passive buy order when the book is strongly ask-heavy, because the price is more likely to fall first.
04Why traders use it
Queue sizes are free, public information about who is waiting where. Imbalance is the simplest way to turn the shape of the book into a short-term signal.
05Worked example
Counting the top 3 levels, there are 4,700 shares bid and 2,800 offered, an imbalance of 0.253. The best level alone gives 0.613: the deeper levels dilute it.
06How it is built
- Add up the bid sizes over the top levels, and the ask sizes the same way.
- Take the difference and divide by the total, so the result lies between and .
- With this is the same imbalance that sets the microprice.
- Larger is steadier but slower to react; small reacts fast but is easy to fake with orders that are cancelled.
07The common mistake
Trusting the displayed size. Deep levels are often cancelled before the price gets there, and hidden or iceberg orders do not show at all, so imbalance over many levels can be mostly noise.
08In Python and LaTeX
import numpy as np bids = np.array([2500, 900, 1300, 1100, 1700]) asks = np.array([600, 1400, 800, 1600, 1200]) N = 3 I = (bids[:N].sum() - asks[:N].sum()) / (bids[:N].sum() + asks[:N].sum()) print(round(I, 3))
I_N = \frac{\sum_{i=1}^{N} V^b_i - \sum_{i=1}^{N} V^a_i}{\sum_{i=1}^{N} V^b_i + \sum_{i=1}^{N} V^a_i}09Where it fits
Rather not code the maths yourself? Describe your trading idea and let AI build the bot.
Build a bot with AgenKitThe worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.