Fetch historical price data for a token over various time intervals:
import { PriceHistoryInterval } from "@polymarket/clob-client";const history = await client.getPricesHistory({ market: "TOKEN_ID", // Note: this param is named "market" but takes a token ID interval: PriceHistoryInterval.ONE_DAY, fidelity: 60, // Data points every 60 minutes});// Each entry: { t: timestamp, p: price }history.forEach((point) => { console.log(`${new Date(point.t * 1000).toISOString()}: ${point.p}`);});
Interval
Description
1h
Last hour
6h
Last 6 hours
1d
Last day
1w
Last week
1m
Last month
max
All available data
interval is relative to the current time. Use startTs / endTs for
absolute time ranges. They are mutually exclusive — don’t combine them.
Calculate the effective price you’d pay for a market order of a given size, accounting for orderbook depth:
import { Side, OrderType } from "@polymarket/clob-client";// What price would I pay to buy $500 worth?const price = await client.calculateMarketPrice( "TOKEN_ID", Side.BUY, 500, // dollar amount OrderType.FOK,);console.log("Estimated fill price:", price);
This walks the orderbook to estimate slippage. Useful for sizing market orders before submitting them.
For live orderbook data, use the WebSocket API instead of polling. The market channel streams orderbook changes, price updates, and trade events in real time.
price_changes[] with price, size, side, best_bid, best_ask
last_trade_price
Trade executed
price, side, size, fee_rate_bps
tick_size_change
Price hits >0.96 or < 0.04
old_tick_size, new_tick_size
best_bid_ask
Top-of-book changes
best_bid, best_ask, spread
new_market
Market created
question, assets_ids, outcomes
market_resolved
Market resolved
winning_asset_id, winning_outcome
best_bid_ask, new_market, and market_resolved require
custom_feature_enabled: true in your subscription message.
The tick_size_change event is critical for trading bots. If the tick size
changes and you continue using the old tick size, your orders will be
rejected.