13 KiB
Documentation Index
Fetch the complete documentation index at: https://docs.polymarket.com/llms.txt Use this file to discover all available pages before exploring further.
Public Methods
These methods can be called without a signer or user credentials. Use these for reading market data, prices, and order books.
Client Initialization
Public methods require the client to initialize with the host URL and Polygon chain ID.
```typescript theme={null} import { ClobClient } from "@polymarket/clob-client";const client = new ClobClient(
"https://clob.polymarket.com",
137
);
// Ready to call public methods
const markets = await client.getMarkets();
```
```python theme={null}
from py_clob_client.client import ClobClient
client = ClobClient(
host="https://clob.polymarket.com",
chain_id=137
)
# Ready to call public methods
markets = await client.get_markets()
```
Health Check
getOk()
Health check endpoint to verify the CLOB service is operational.
async getOk(): Promise<any>
Markets
getMarket()
Get details for a single market by condition ID.
async getMarket(conditionId: string): Promise<Market>
interface MarketToken {
outcome: string;
price: number;
token_id: string;
winner: boolean;
}
interface Market {
accepting_order_timestamp: string | null;
accepting_orders: boolean;
active: boolean;
archived: boolean;
closed: boolean;
condition_id: string;
description: string;
enable_order_book: boolean;
end_date_iso: string;
fpmm: string;
game_start_time: string;
icon: string;
image: string;
is_50_50_outcome: boolean;
maker_base_fee: number;
market_slug: string;
minimum_order_size: number;
minimum_tick_size: number;
neg_risk: boolean;
neg_risk_market_id: string;
neg_risk_request_id: string;
notifications_enabled: boolean;
question: string;
question_id: string;
rewards: {
max_spread: number;
min_size: number;
rates: any | null;
};
seconds_delay: number;
tags: string[];
taker_base_fee: number;
tokens: MarketToken[];
}
getMarkets()
Get details for multiple markets paginated.
async getMarkets(): Promise<PaginationPayload>
interface PaginationPayload {
limit: number;
count: number;
data: Market[];
}
interface Market {
accepting_order_timestamp: string | null;
accepting_orders: boolean;
active: boolean;
archived: boolean;
closed: boolean;
condition_id: string;
description: string;
enable_order_book: boolean;
end_date_iso: string;
fpmm: string;
game_start_time: string;
icon: string;
image: string;
is_50_50_outcome: boolean;
maker_base_fee: number;
market_slug: string;
minimum_order_size: number;
minimum_tick_size: number;
neg_risk: boolean;
neg_risk_market_id: string;
neg_risk_request_id: string;
notifications_enabled: boolean;
question: string;
question_id: string;
rewards: {
max_spread: number;
min_size: number;
rates: any | null;
};
seconds_delay: number;
tags: string[];
taker_base_fee: number;
tokens: MarketToken[];
}
interface MarketToken {
outcome: string;
price: number;
token_id: string;
winner: boolean;
}
getSimplifiedMarkets()
Get simplified market data paginated for faster loading.
async getSimplifiedMarkets(): Promise<PaginationPayload>
interface PaginationPayload {
limit: number;
count: number;
data: SimplifiedMarket[];
}
interface SimplifiedMarket {
accepting_orders: boolean;
active: boolean;
archived: boolean;
closed: boolean;
condition_id: string;
rewards: {
rates: any | null;
min_size: number;
max_spread: number;
};
tokens: SimplifiedToken[];
}
interface SimplifiedToken {
outcome: string;
price: number;
token_id: string;
}
getSamplingMarkets()
async getSamplingMarkets(): Promise<PaginationPayload>
interface PaginationPayload {
limit: number;
count: number;
data: Market[];
}
interface Market {
accepting_order_timestamp: string | null;
accepting_orders: boolean;
active: boolean;
archived: boolean;
closed: boolean;
condition_id: string;
description: string;
enable_order_book: boolean;
end_date_iso: string;
fpmm: string;
game_start_time: string;
icon: string;
image: string;
is_50_50_outcome: boolean;
maker_base_fee: number;
market_slug: string;
minimum_order_size: number;
minimum_tick_size: number;
neg_risk: boolean;
neg_risk_market_id: string;
neg_risk_request_id: string;
notifications_enabled: boolean;
question: string;
question_id: string;
rewards: {
max_spread: number;
min_size: number;
rates: any | null;
};
seconds_delay: number;
tags: string[];
taker_base_fee: number;
tokens: MarketToken[];
}
interface MarketToken {
outcome: string;
price: number;
token_id: string;
winner: boolean;
}
getSamplingSimplifiedMarkets()
async getSamplingSimplifiedMarkets(): Promise<PaginationPayload>
interface PaginationPayload {
limit: number;
count: number;
data: SimplifiedMarket[];
}
interface SimplifiedMarket {
accepting_orders: boolean;
active: boolean;
archived: boolean;
closed: boolean;
condition_id: string;
rewards: {
rates: any | null;
min_size: number;
max_spread: number;
};
tokens: SimplifiedToken[];
}
interface SimplifiedToken {
outcome: string;
price: number;
token_id: string;
}
Order Books and Prices
calculateMarketPrice()
async calculateMarketPrice(
tokenID: string,
side: Side,
amount: number,
orderType: OrderType = OrderType.FOK
): Promise<number>
enum OrderType {
GTC = "GTC", // Good Till Cancelled
FOK = "FOK", // Fill or Kill
GTD = "GTD", // Good Till Date
FAK = "FAK", // Fill and Kill
}
enum Side {
BUY = "BUY",
SELL = "SELL",
}
number // calculated market price
getOrderBook()
Get the order book for a specific token ID.
async getOrderBook(tokenID: string): Promise<OrderBookSummary>
interface OrderBookSummary {
market: string;
asset_id: string;
timestamp: string;
bids: OrderSummary[];
asks: OrderSummary[];
min_order_size: string;
tick_size: string;
neg_risk: boolean;
hash: string;
}
interface OrderSummary {
price: string;
size: string;
}
getOrderBooks()
Get order books for multiple token IDs.
async getOrderBooks(params: BookParams[]): Promise<OrderBookSummary[]>
interface BookParams {
token_id: string;
side: Side; // Side.BUY or Side.SELL
}
OrderBookSummary[]
getPrice()
Get the current best price for buying or selling a token ID.
async getPrice(
tokenID: string,
side: "BUY" | "SELL"
): Promise<any>
{
price: string;
}
getPrices()
Get the current best prices for multiple token IDs.
async getPrices(params: BookParams[]): Promise<PricesResponse>
interface BookParams {
token_id: string;
side: Side; // Side.BUY or Side.SELL
}
interface TokenPrices {
BUY?: string;
SELL?: string;
}
type PricesResponse = {
[tokenId: string]: TokenPrices;
}
getMidpoint()
Get the midpoint price (average of best bid and best ask) for a token ID.
async getMidpoint(tokenID: string): Promise<any>
{
mid: string;
}
getMidpoints()
Get the midpoint prices (average of best bid and best ask) for multiple token IDs.
async getMidpoints(params: BookParams[]): Promise<any>
interface BookParams {
token_id: string;
side: Side; // Side is ignored
}
{
[tokenId: string]: string;
}
getSpread()
Get the spread (difference between best ask and best bid) for a token ID.
async getSpread(tokenID: string): Promise<SpreadResponse>
interface SpreadResponse {
spread: string;
}
getSpreads()
Get the spreads (difference between best ask and best bid) for multiple token IDs.
async getSpreads(params: BookParams[]): Promise<SpreadsResponse>
interface BookParams {
token_id: string;
side: Side;
}
type SpreadsResponse = {
[tokenId: string]: string;
}
getPricesHistory()
Get historical price data for a token.
async getPricesHistory(params: PriceHistoryFilterParams): Promise<MarketPrice[]>
interface PriceHistoryFilterParams {
market: string; // tokenID
startTs?: number;
endTs?: number;
fidelity?: number;
interval: PriceHistoryInterval;
}
enum PriceHistoryInterval {
MAX = "max",
ONE_WEEK = "1w",
ONE_DAY = "1d",
SIX_HOURS = "6h",
ONE_HOUR = "1h",
}
interface MarketPrice {
t: number; // timestamp
p: number; // price
}
Trades
getLastTradePrice()
Get the price of the most recent trade for a token.
async getLastTradePrice(tokenID: string): Promise<LastTradePrice>
interface LastTradePrice {
price: string;
side: string;
}
getLastTradesPrices()
Get the price of the most recent trade for a token.
async getLastTradesPrices(params: BookParams[]): Promise<LastTradePriceWithToken[]>
interface BookParams {
token_id: string;
side: Side;
}
interface LastTradePriceWithToken {
price: string;
side: string;
token_id: string;
}
getMarketTradesEvents
async getMarketTradesEvents(conditionID: string): Promise<MarketTradeEvent[]>
interface MarketTradeEvent {
event_type: string;
market: {
condition_id: string;
asset_id: string;
question: string;
icon: string;
slug: string;
};
user: {
address: string;
username: string;
profile_picture: string;
optimized_profile_picture: string;
pseudonym: string;
};
side: Side;
size: string;
fee_rate_bps: string;
price: string;
outcome: string;
outcome_index: number;
transaction_hash: string;
timestamp: string;
}
Market Parameters
getFeeRateBps()
Get the fee rate in basis points for a token.
async getFeeRateBps(tokenID: string): Promise<number>
number
getTickSize()
Get the tick size (minimum price increment) for a market.
async getTickSize(tokenID: string): Promise<TickSize>
type TickSize = "0.1" | "0.01" | "0.001" | "0.0001";
getNegRisk()
Check if a market uses negative risk (binary complementary tokens).
async getNegRisk(tokenID: string): Promise<boolean>
boolean
Time & Server Info
getServerTime()
Get the current server timestamp.
async getServerTime(): Promise<number>
number // Unix timestamp in seconds