Finance OS
Capital markets and asset pricing

How markets form prices

Use an order book to observe quotes, transactions, spreads and depth, and understand the price to pay for immediate transactions.

The real-world story

Intuition · Screen price is not a purchase commitment

Xiaolin saw that the last transaction price of a certain fictitious stock was 10 CNY, and planned to buy 500 shares. He thought he must only need 5,000 CNY. But the last transaction only shows that there are buyers and sellers at that price at a certain moment, and it does not promise that there will be enough quantity for him to buy in the future.

The transaction requires the other party to be willing to sell on compatible terms. Buyers and sellers express price, quantity and other conditions through orders; when the conditions for transaction meet, a new transaction record is formed. Valuation discussions help people decide what they are willing to pay, and market mechanisms determine how specific orders meet. The two are not the same thing.

The conflict

Xiao Lin wanted to close the deal immediately, but was unwilling to accept a price higher than the one quoted on the screen. Friendly reminder: speed, price and quantity may not be guaranteed at the same time. The seller is also updating the quotation, and the displayed order may be eaten by others or canceled before your order arrives.

Therefore, it is necessary to distinguish between the last traded price, the best bid price, the best sell price and the entire order book. Having only a small order listed at the best price does not mean that a large order can also be completed at this price; having a quotation does not mean that it can be realized at a low cost at all times.

Your decision

Handle a purchase order

Below is a static order book for a fictional market. It is assumed that transactions are completed step by step based on price priority, without new orders, order cancellations, hidden quantities, fees or other trading venues. You submit a market price order to buy 500 shares. How much will you buy at which prices?

buyer willing to pay priceBuyer quantityPrice the seller is willing to chargeNumber of sellers
9.9830010.00100
9.9550010.02200
9.901,00010.05500

The two sides are independent transaction queues, and the same row is not a pair of orders that have been completed. When the best buying price is lower than the best selling price, they have no price overlap.

Working out the result

The market buy order first buys 100 shares at 10.00, then buys 200 shares at 10.02, and finally buys 200 shares at 10.05. The total payment was 1,000+2,004+2,010=5,014 and the average transaction price was 10.028. The last transaction price is 10.05, which is not equal to the average price of the entire order.

The optimal bid-ask spread is 10.00−9.98=0.02, and the middle price is 9.99. The relative price difference calculated using the middle price is approximately 0.2002%. The average price of this transaction is 0.028 higher than the initial best selling price, and an additional payment of 14 is required. This is only the slippage relative to the specified benchmark, not the full transaction fee.

If it is changed to a limit buy order with a maximum willingness to pay 10.02, this question can only deal 300 shares immediately, paying 3,004, and the average price is about 10.0133; how to deal with the remaining 200 shares depends on the validity period and execution conditions. You can’t just add sellers out of thin air just to make the experiment look like it’s all done.

Building the financial model

Model·Quotation, Depth and Transaction

Bid is the quote that the buyer is willing to pay, and Ask is the quote that the seller is willing to receive; usually when we talk about the optimal Bid/Ask, they refer to the current highest buying price and the lowest selling price respectively. Spread is the difference between the two. Order Book organizes the quantities to be executed at different prices. The display depth is the visible quantity of each level and does not represent all potential supply and demand.

Market Order gives priority to immediate execution, but does not guarantee the final price; Limit Order stipulates an acceptable price or a better price, but does not guarantee execution. The buy limit price is the highest price you are willing to pay, and the sell limit price is the lowest price you are willing to receive. True tradable quantity is also affected by routing, pauses, available liquidity and trading rules.

Average transaction price = sum of each price multiplied by quantity ÷ total transaction volume. When buying 100 shares and 500 shares, even if you observe the same instant order book, there will be different average prices. This is why trade size must be stated when studying liquidity.

Professional · Who provides liquidity

Market makers participate in transactions through bid and offer quotes and may earn price differences, but they also bear the risk of inventory price changes and transactions with better-informed traders. Spread income is not a risk-free profit; when the market changes drastically, the quotation may be wider and the available quantity may be smaller.

Price discovery is a process in which trading participants reflect information and needs through quotations and transactions. There is no guarantee that every transaction is equal to the complete enterprise value. Someone who needs cash urgently can sell without changing their judgment on the long-term cash flow of the company. New information, funding constraints, and trading mechanisms may simultaneously affect observed prices.

This chapter only simulates a single static order book. The real market may have multiple venues, hidden orders, call auctions, different priority rules and minimum price units. This issue cannot be regarded as a unified rule for all markets. "Market orders are usually executed immediately" cannot be understood to mean that the full amount will be executed in any size and under any conditions.

Key terms

TerminologymeaningThis question corresponds to
Bid · Bid priceprice the buyer is willing to payOptimal 9.98
Ask · Selling priceThe price the seller is willing to chargeOptimal 10.00
Spread · SpreadBest selling price minus best buying price0.02
Order Book · Order BookPending orders arranged by rulesPrice and quantity list
Market Order·Market OrderSeek execution at available price500 stock eats multiple price points
Limit Order·Limit orderSpecify acceptable price boundaries10.02 buy order will be executed immediately 300 shares
Liquidity · LiquidityThe ability to complete transactions of a given size at an acceptable costLook at spreads, depth and pressure status simultaneously

Connecting to real market cases

Order type descriptions from Investor.gov Explain that market orders do not guarantee a price, and limit orders do not guarantee a transaction, and differentiate between stop order triggering and execution. Access date: 2026-09-23. What is quoted here is the order mechanism faced by actual investors, not the real-time order book of a certain stock.

When reading the real trading interface, first look for the order type, upper or lower price limit, quantity and validity period, and then check the rules of the brokerage and trading venue. This chapter does not require actual order placement. If "Stop Loss" is written on the interface, you also need to check which order is generated after the trigger is triggered; the stop loss trigger price does not automatically equal the final transaction price.

Data experiment

Input: the above static three-level sell order, and the buying quantity of 100, 300, 500, 900 shares. Operation: Consume the quantity according to the selling price from low to high, and record each transaction, remaining orders and unfulfilled quantity. 900 shares exceed the total visible selling volume 800, it must be clear that 100 shares cannot be traded in this table.

Output: four columns: transaction details, total payment, average transaction price, and untransacted quantity. Verification: 100 average share price 10; 300 average share price approximately 10.0133; 500 average share price 10.028; 900 share demand can only be traded 800 shares, total payment 8,029, average price 10.03625. The denominator of the average price must use the actual transaction quantity, not the unfulfilled demand quantity.

Make another limit buy order of 10.02 and compare it with the market order: you limit the price, but give up the guarantee of getting the full quantity immediately. Complete with pen and paper or a form, no account, trade API or real money required.

AI Lab

According to the static order book in this chapter, simulate the buy 500 stock market price order, as well as the buy 500 stock, limit price 10.02 order. Output each transaction and remaining quantity, and no new liquidity is allowed to be added. Explain why the last traded price differs from the average price.

You must verify by yourself: whether the source is the order book of this question and not a fictitious market; whether the time is the same snapshot; whether the calculation is consumed step by step and the quantity is conserved; whether the assumption includes new orders, order cancellations and handling fees. When AI is not used, use paper and pen to cross out the quantity step by step, and finally calculate the total amount independently.

Change the variables and run it again

Reduce the best selling price quantity from 100 to 10, keep the rest unchanged, and buy 500 shares again; then increase the third-level quotation to 10.20, and observe the two factors of depth and price. Don’t judge that transaction costs have not changed just because the best bid price has not changed.

Finally, two scenarios of fixed fee per transaction and billing based on transaction volume are added to distinguish fees, spreads and market impacts. The static book in this question does not simulate the dynamic impact of orders on future quotations, and cannot be used to estimate the full cost of real large transactions.

From traditional to future finance

Traditional finance: Traditional exchanges matched trades through floor quotes and specialist market makers, and both information and execution speed were limited by the physical venue.

Financial modernization: Electronic order books, algorithmic trading and high-frequency market making sharply reduced trading costs and narrowed spreads. Under stress, liquidity can also withdraw quickly, and prices can jump sharply within a very short time.

Future finance: Decentralized exchanges often replace the order book with automated market maker pools: the price is set by the ratio of assets in the pool and a formula, and liquidity comes from assets deposited by providers. The mechanism differs, but immediate execution still has a cost, and large trades still face slippage.

What stays the same: At the size I need, how much liquidity is there? How much am I willing to pay for immediate execution?

Questions to take with you

Is the last transaction price or the current transaction price I see? How much liquidity do I have at the volume I need, and how much am I willing to pay for immediate delivery?

Self-test

  1. What are the optimal Bid, Ask and spread for this question?
  2. What is the average transaction price for buying 500 shares at market price?
  3. Can the price limit 10.02 buy 500 shares be traded immediately?
  4. Are market orders guaranteed to be executed at the last transaction price?
  5. For the buying demand of 900 shares in this table, should the denominator of the average price be 900 or 800?
  6. Does the market maker earning the spread mean there is no risk?
Reference answers and analysis
  • Question 1: 9.98, 10.00, 0.02, the best buying and selling quotes have not yet overlapped.
  • Question 2: 10.028, payment 5,014 divided by 500 shares traded.
  • Question 3: No, only 300 shares meet the price conditions.
  • Question 4: Not guaranteed, available quotes and quantities may change at time of execution.
  • Question 5: 800, only the actual trading volume is calculated, and the unfinished 100 shares are also listed.
  • Question 6: No, it also bears the risks of inventory, price changes and information asymmetry.

On this page