Markets
The ctx.markets module provides read-only access to market data. No authentication required.
import { ContextClient } from "@contextwtf/sdk"
const ctx = new ContextClient()
List markets
Search and filter markets:
const { markets, cursor } = await ctx.markets.list({
query: "bitcoin",
status: "active",
sortBy: "trending",
limit: 10,
})
for (const market of markets) {
console.log(market.question)
}
Parameters
| Param | Type | Description |
|---|
query | string | Search by question text |
status | "active" | "pending" | "resolved" | "closed" | Filter by market status |
sortBy | "new" | "volume" | "trending" | "ending" | "chance" | Sort order |
sort | "asc" | "desc" | Sort direction |
limit | number | Results per page (max 50) |
cursor | string | Pagination cursor |
category | string | Filter by category |
creator | string | Filter by creator address |
visibility | "visible" | "hidden" | "all" | Filter by market visibility |
resolutionStatus | string | Filter by resolution status ("none", "pending", "resolved") |
createdAfter | string | Filter markets created after this timestamp |
Use the cursor from the response to fetch the next page:
let cursor: string | undefined
do {
const res = await ctx.markets.list({ sortBy: "new", limit: 50, cursor })
for (const market of res.markets) {
console.log(market.question)
}
cursor = res.cursor ?? undefined
} while (cursor)
Get a market
Fetch a single market by ID or slug:
const market = await ctx.markets.get("0x1234...")
console.log(market.question)
console.log(market.status) // "active" | "pending" | "resolved" | "closed"
console.log(market.metadata.slug)
Quotes
Get current bid/ask/last prices:
const quotes = await ctx.markets.quotes("0x1234...")
console.log(`Yes: ${quotes.yes.bid}¢ bid / ${quotes.yes.ask}¢ ask`)
console.log(`No: ${quotes.no.bid}¢ bid / ${quotes.no.ask}¢ ask`)
console.log(`Spread: ${quotes.spread}¢`)
Prices are in cents (0-100).
Orderbook
Get the bid/ask ladder:
const book = await ctx.markets.orderbook("0x1234...", { depth: 10 })
console.log("Best bid:", book.bids[0]?.price, "¢")
console.log("Best ask:", book.asks[0]?.price, "¢")
for (const level of book.bids) {
console.log(` ${level.price}¢ — ${level.size} contracts`)
}
Parameters
| Param | Type | Description |
|---|
depth | number | Number of price levels (default: 20) |
outcomeIndex | number | Filter by outcome (0 = No, 1 = Yes) |
Simulate a trade
Preview expected execution before placing a real order:
const sim = await ctx.markets.simulate("0x1234...", {
side: "yes",
amount: 100,
amountType: "usd",
})
console.log(`Would buy ${sim.estimatedContracts} contracts`)
console.log(`Average price: ${sim.estimatedAvgPrice}¢`)
console.log(`Slippage: ${sim.estimatedSlippage.toFixed(2)}%`)
Parameters
| Param | Type | Description |
|---|
side | "yes" | "no" | Which outcome to buy |
amount | number | Trade amount |
amountType | "usd" | "contracts" | Whether amount is in USD or contracts (default: "usd") |
Price history
Fetch historical price data:
const history = await ctx.markets.priceHistory("0x1234...", {
timeframe: "1w",
})
for (const point of history.prices) {
const date = new Date(point.time * 1000)
console.log(`${date.toISOString()}: ${point.price}¢`)
}
Timeframes
| Value | Period |
|---|
"1h" | Last hour |
"6h" | Last 6 hours |
"1d" | Last day |
"1w" | Last week |
"1M" | Last month |
"all" | All time |
Oracle
Get AI oracle resolution status:
const { oracle } = await ctx.markets.oracle("0x1234...")
if (oracle) {
console.log("Confidence:", oracle.confidenceLevel)
console.log("Summary:", oracle.summary.shortSummary)
console.log("Sources monitored:", oracle.sourcesMonitored.join(", "))
} else {
console.log("Oracle data not yet available")
}
The oracle field can be null for markets that haven’t been assessed yet. Always check before accessing properties.
Oracle quotes
Get probability estimates from the oracle:
const { quotes } = await ctx.markets.oracleQuotes("0x1234...")
for (const quote of quotes) {
console.log(`Probability: ${quote.probability}%`)
console.log(`Confidence: ${quote.confidence}`)
console.log(`Reasoning: ${quote.reasoning}`)
}
Request a new oracle analysis:
const result = await ctx.markets.requestOracleQuote("0x1234...")
console.log("Quote requested:", result.id)
Activity
Get the event feed for a market:
const { activity } = await ctx.markets.activity("0x1234...", {
types: "trade",
limit: 50,
})
for (const event of activity) {
console.log(`${event.timestamp}: ${event.type}`)
}
Global activity
Get activity across all markets:
const { activity } = await ctx.markets.globalActivity({ limit: 20 })
Parameters
| Param | Type | Description |
|---|
cursor | string | Pagination cursor |
limit | number | Results per page |
types | string | Filter by event type (e.g. "trade") |
startTime | string | Filter events after this time |
endTime | string | Filter events before this time |