Implementing Market Order Placement in a Mobile Exchange App
A market order executes immediately at the best available price. Users enter only quantity — no price. This simplifies the UI compared to limit orders, but introduces a different problem: slippage. User clicks "Buy" at price 42,000, but it executes at 42,150 — and that's normal, but show this upfront.
Displaying Expected Execution Price
Market price changes constantly. Display the current best price from the order book (ask for buy, bid for sell), updating via WebSocket. Alongside it, show estimated transaction cost: Amount × bestAsk. Label as "Approximate" with a slippage warning for low liquidity.
Low liquidity occurs when the order book depth can't absorb the full volume at the first level. If a user wants to buy 10 BTC but only 3 BTC are available at the best price, the actual price will be higher. Simple heuristic: walk through order book levels and calculate weighted average price (WAP) for the requested volume.
// Android — estimate market execution price from order book snapshot
fun estimateMarketPrice(asks: List<Pair<BigDecimal, BigDecimal>>, targetQty: BigDecimal): BigDecimal {
var remaining = targetQty
var totalCost = BigDecimal.ZERO
for ((price, qty) in asks) {
val fill = minOf(remaining, qty)
totalCost += fill * price
remaining -= fill
if (remaining <= BigDecimal.ZERO) break
}
return if (remaining > BigDecimal.ZERO) BigDecimal.ZERO // insufficient liquidity
else totalCost.divide(targetQty, 8, RoundingMode.HALF_UP)
}
Input Field: Amount or Sum
For market orders, exchanges often support two modes: specify base asset quantity (quoteOrderQty=false) or specify quote asset sum (quoteOrderQty in Binance). A toggle BTC/USDT above the Amount field is standard UX. In USDT mode, users enter the sum; the exchange calculates quantity.
Double Confirmation
Market orders can't be cancelled after submission. Minimum — an alert with a confirmation button. For large sums (above a threshold in settings) — require PIN or biometric re-entry.
Timeline: 2–3 days including WebSocket price updates, WAP calculation, input mode toggle, and confirmation dialog.







