Recipe 19 of 30
Slippage: what would a $X order have cost at time T?
Take the /orderbook snapshot at T and walk the asks level by level until $X is spent; the average price against the best ask is the slippage, and at most 25 levels a side come back, so a large order can run off the end.
GET /v1/polymarket/orderbook with ts answers it in one call: the recorded book of one outcome token at or before the moment T, up to 25 levels a side. A market buy for $X takes the asks in order from level 1, so walk them on your side, spending each level's price × size until $X is gone. The call's jq tail does the walk and prints the shares bought, the levels used and the average price. The full parameter list is on Order-book snapshot.
Quick answer
Fetch the book at the moment and walk its asks for $500.
# a $500 market buy of the Down token at 14:26:40 UTC on 2026-10-23: walk the asks of the book at that moment
curl -s -H "X-API-Key: $VIKE_API_KEY" \
"https://data.vike.io/v1/polymarket/orderbook?token_id=2124295006397608207923779951408795040669109096087651269807278744579659839433&ts=1792765600000" \
| jq --argjson usd 500 'map(select(.side == "ask")) | unique_by(.level) | reduce .[] as $l ({spent: 0, shares: 0, levels: 0}; if .spent >= $usd then . else ([$l.price * $l.size, $usd - .spent] | min) as $take | .spent += $take | .shares += $take / $l.price | .levels += 1 end) | . + {avg_price: (.spent / .shares), unfilled_usd: ($usd - .spent)}'Example response
Captured from the live API on 2026-10-24 at 17:21 UTC, the book's 50 rows, walked by the call's jq tail. $500 would have bought 1,069.58 Down shares across three ask levels (0.46, 0.47, 0.48) at an average of 0.4675, against 0.46 at the best ask: 1.6% of slippage. The snapshot behind it is from 14:26:39.913 UTC, 87 ms before the moment asked for (as_of_ts in the raw rows).
{
"spent": 500,
"shares": 1069.5775,
"levels": 3,
"avg_price": 0.4674743064434321,
"unfilled_usd": 0
}Variations
An order bigger than the book you can see. The 25 ask levels of this snapshot held $10,313.33. A $20,000 order spends all of it and reports the rest unfilled.
# the same walk for $20,000: unfilled_usd shows where the returned book ran out
curl -s -H "X-API-Key: $VIKE_API_KEY" \
"https://data.vike.io/v1/polymarket/orderbook?token_id=2124295006397608207923779951408795040669109096087651269807278744579659839433&ts=1792765600000" \
| jq --argjson usd 20000 'map(select(.side == "ask")) | unique_by(.level) | reduce .[] as $l ({spent: 0, shares: 0, levels: 0}; if .spent >= $usd then . else ([$l.price * $l.size, $usd - .spent] | min) as $take | .spent += $take | .shares += $take / $l.price | .levels += 1 end) | . + {avg_price: (.spent / .shares), unfilled_usd: ($usd - .spent)}'It returns 17,523.75 shares over 25 levels at an average of 0.5885, with $9,686.67 unfilled.
A sell order: walk the bids. Selling a number of shares takes the bids from level 1 down. 3,000 shares here would have sold over two levels at an average of 0.4456.
# a market sell of 3,000 Down shares at the same moment
curl -s -H "X-API-Key: $VIKE_API_KEY" \
"https://data.vike.io/v1/polymarket/orderbook?token_id=2124295006397608207923779951408795040669109096087651269807278744579659839433&ts=1792765600000" \
| jq --argjson shares 3000 'map(select(.side == "bid")) | unique_by(.level) | reduce .[] as $l ({sold: 0, usd: 0, levels: 0}; if .sold >= $shares then . else ([$l.size, $shares - .sold] | min) as $take | .sold += $take | .usd += $take * $l.price | .levels += 1 end) | . + {avg_price: (.usd / .sold), unsold_shares: ($shares - .sold)}'The same order a minute before the close. Change ts. This market's window closed at 14:30:00 UTC.
# the Down token's book at 14:29:00 UTC, one minute before the close
curl -H "X-API-Key: $VIKE_API_KEY" \
"https://data.vike.io/v1/polymarket/orderbook?token_id=2124295006397608207923779951408795040669109096087651269807278744579659839433&ts=1792765740000"Before you rely on it
25 levels, repeated rows, and a book that would have moved
At most 25 levels a side come back, so when unfilled_usd is above 0 the walk ran out of the returned book, not out
of the market. A level can appear several times in one response; unique_by(.level) keeps one before the walk.
The walk prices your order against the resting book at as_of_ts, with no fees and no reaction from other traders,
so read it as the cost against the book you could see, not a fill price you would have got.
Ask your agent
Connected to the Vike MCP server (https://vike.io/mcp) in Claude, ChatGPT or Cursor, ask it in plain words. The polymarket_orderbook tool answers with the book, at 1 credit a call. The agent does the walk.
How much would a $500 market buy of Polymarket token 2124295006397608207923779951408795040669109096087651269807278744579659839433 have cost at 14:26:40 UTC on 2026-10-23?