Skip to main content
GET
Python (SDK)

Overview

Search runs over a single index of event contracts. The type parameter picks the level hits come back at, and the response echoes it in data.type so a client can branch on the shape it actually received.

Filters apply to contracts

This matters when type is events or base-events: an event or base event is only found through its matching contracts. One whose contracts are all filtered out — for example an event holding only DELETED contracts under the default state — is not returned at all, even if its own text matches the query. found, page, and perPage count whatever type returns, not the underlying contracts. contractsFound on each events or base-events hit is the count of every matching contract under it, and contracts holds the first contractsPerHit of them (2 by default, at most 10). To list the rest, search again with type=contracts and the hit’s eventId or baseEventId. Contracts under the venue’s Conditional category are never returned. See Conditional contracts are not served.

Ordering

sortBy picks the order: Any other value returns 400 INVALID_SORT_BY.

Ordering by open interest

With sortBy=openInterest, results are ordered by open interest, from the venue’s last daily prices file. Each type ranks by its own level: The contracts on a hit come in order of their own open interest, highest first. Ties are broken by symbol, so pages are stable. With q, relevance comes first and open interest breaks ties. The file is published once a day, after the close, so open interest is end of day, not live. A contract the file did not name has no openInterest field and comes last; 0 is a real value. A hit’s openInterest is absent when the file named none of its contracts.
Search carries no prices. To show a price for the contracts on screen, open one live price stream for their symbols: its first snapshot per contract has each outcome’s last, and contract.settlement when nothing has traded yet.

Query syntax

q searches symbols, contract questions, event names, and base-event specifications. Symbols are split on _, -, and ., so a partial query finds the full symbol:
Omit q entirely to browse the catalogue, in the sortBy order.

Parameters

Filter by category

category takes a category’s whole path, such as Elections > United States House, from List Categories. It matches that category and everything under it, so Elections also finds every House and Senate race. A bare level name such as United States matches nothing, because level names repeat under different parents. URL-encode the path, since it contains spaces and >.

Search results trail the catalogue

The index is updated from the catalogue and lags it by seconds. Treat a hit’s symbol as the key into Get Event Contracts and read anything that must be current — state, tradable — from there. Do not act on a hit’s own tradable field.

Response

This response is for type=events&sortBy=openInterest, so each hit’s contracts come most open interest first.
Every contract, whether a contracts hit or inside an event or base-event hit, carries photo: the candidate’s portrait on an election contract that has one, else null (as on the House-control outcomes above). It is the same object Get Event Contracts returns:
Show credit and license with the image, or on a credits page it links to. Photos are on staging; on production photo is null until the rollout is announced in the changelog. Every contract also carries party, frontRunner, incumbent and candidateStatus: the venue’s metadata on an election contract, else null (as on the House-control outcomes above). They are read from the index, so like the rest of the hit they trail Get Event Contracts by seconds:

Examples

Find contracts by text

Group hits by event

Rank events by open interest, with each one’s 3 most-held contracts

List the matching contracts under one event hit

Browse a single base event, tradable only

Search one category

Include deleted contracts

Errors

  • 400 — an unknown type, a parameter that failed validation (such as INVALID_CONTRACTS_PER_HIT for a negative or non-integer contractsPerHit, or INVALID_SORT_BY for a sortBy other than none or openInterest), or a category containing a backtick
  • 502 — the search index was unavailable

Query Parameters

type
enum<string>
default:contracts

Level hits come back at. contracts (default) returns matching contracts; events returns one hit per event and base-events one per base event, each with its own fields, a count of matching contracts and the first contractsPerHit of them in the sortBy order. Echoed in the response.

Available options:
contracts,
events,
base-events
q
string

Full-text query over symbols, questions, event names and base-event specifications. Symbols split on _, - and . so BPM 0822 finds BPM_0822_1750. Omit to browse, in the sortBy order.

Example:

"unemployment june"

state
string

Contract state. Omitted means ACTIVE; * matches every state, including DELETED.

Example:

"ACTIVE"

baseEventId
string

Only contracts under this base event.

Example:

"UNR"

eventId
string

Only contracts under this event.

Example:

"UNR_0822"

category
string

Only contracts in this category or any category under it. Takes a path from List Categories, URL-encoded. A bare level name such as United States matches nothing, because level names repeat under different parents.

Example:

"Elections > United States House"

tradable
boolean

Only tradable (true) or non-tradable (false) contracts.

sortBy
enum<string>
default:none

Result order. none (default): a q match first, then symbol ascending, at every level, so pages are stable. openInterest: by open interest from the venue's last daily prices file, each type by its own total, with a q match first; contracts with no open interest come last. Any other value returns 400 INVALID_SORT_BY.

Available options:
none,
openInterest
page
integer

1-based page number; 0 or omitted means 1.

Required range: x >= 0
Example:

1

perPage
integer

Hits per page, counting whatever type returns; 0 or omitted means 20, values above 100 are clamped to 100.

Required range: 0 <= x <= 100
Example:

20

contractsPerHit
integer
default:2

With type=events or type=base-events, how many of each hit's matching contracts to return in contracts, in the sortBy order. 0 or omitted means 2; values above 10 are clamped to 10. A negative or non-integer value returns 400 INVALID_CONTRACTS_PER_HIT. Ignored by type=contracts.

Required range: 0 <= x <= 10
Example:

2

Response

One page of hits; data.type says which shape they are

Standard success envelope used by all success responses. data is endpoint-specific.

success
boolean
required
Example:

true

data
object

One page of contracts.