Skip to content

Fetching Markets

Openfish offers multiple ways to retrieve market data, each suited to different integration patterns. All list endpoints support pagination through limit and offset parameters.

The most direct method. Query the Gamma API for events or markets, applying filters and pagination as needed.

Terminal window
curl "https://gamma.openfish.fun/events?active=true&closed=false&order=volume_24hr&ascending=false&limit=50"

Extract the slug from the Openfish frontend URL:

https://openfish.fun/event/btc-100k-by-december
^
Slug: btc-100k-by-december
Terminal window
curl "https://gamma.openfish.fun/events?slug=btc-100k-by-december"
Terminal window
# Discover available tags
curl "https://gamma.openfish.fun/tags"
# Filter events by tag
curl "https://gamma.openfish.fun/events?tag_id=100381&active=true&closed=false&limit=20"
ParameterDescription
activeFilter by active status (true for live tradable events)
closedFilter by closed status (false to exclude resolved markets)
orderSort field: volume_24hr, volume, liquidity, start_date, end_date
ascendingSort direction (true or false, default false)
limitResults per page
offsetNumber of results to skip for pagination
tag_idFilter by category tag
slugLook up by URL slug

Strategy 2: Gamma API Metadata for Rich Context

Section titled “Strategy 2: Gamma API Metadata for Rich Context”

The Gamma API returns full event objects that embed their market arrays. This removes the need for separate market lookups and gives you metadata like descriptions, tags, resolution sources, and token IDs in a single response.

Terminal window
# Single request returns the event and all its markets
curl "https://gamma.openfish.fun/events/125819"

Each market object nested inside an event contains:

  • outcomes and outcomePrices arrays
  • tokens array with CLOB token IDs
  • conditionId for CTF operations
  • enableOrderBook flag indicating CLOB availability
use openfish_client_sdk::GammaClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let gamma = GammaClient::new("https://gamma.openfish.fun");
// Fetch event with all nested markets
let event = gamma.event_by_id("125819").await?;
println!("Event: {}", event.title);
for market in &event.markets {
println!(" Market: {}", market.question);
println!(" Condition ID: {}", market.condition_id);
println!(" Prices: {:?}", market.outcome_prices);
println!(" Order book enabled: {}", market.enable_order_book);
}
Ok(())
}

For integrations that demand real-time data, connect to the market WebSocket. It delivers live order book updates, trade events, and new-market notifications with no polling involved.

use openfish_client_sdk::ws::MarketSocket;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut ws = MarketSocket::connect("wss://api.openfish.fun/ws/market").await?;
// Subscribe to specific token IDs
ws.subscribe(&[
"71321045679252212594626385532706912750332728571942532289631379312455583992563",
]).await?;
// Or subscribe to new_market events to discover markets as they are created
ws.enable_custom_features().await?;
while let Some(event) = ws.next().await {
match event {
MarketEvent::Book { bids, asks, .. } => {
println!("Book update: {} bids, {} asks", bids.len(), asks.len());
}
MarketEvent::NewMarket { question, .. } => {
println!("New market: {question}");
}
_ => {}
}
}
Ok(())
}

All list endpoints paginate with limit and offset:

Terminal window
# Page 1
curl "https://gamma.openfish.fun/events?active=true&closed=false&limit=50&offset=0"
# Page 2
curl "https://gamma.openfish.fun/events?active=true&closed=false&limit=50&offset=50"
# Page 3
curl "https://gamma.openfish.fun/events?active=true&closed=false&limit=50&offset=100"

Keep incrementing offset by limit until the response returns fewer items than limit.

StrategyBest ForLatencyComplexity
REST pollingPeriodic snapshots, simple integrationsSecondsLow
Gamma API metadataRich context, event-level viewsSecondsLow
WebSocket streamingReal-time dashboards, trading botsMillisecondsMedium
  1. Default to active=true&closed=false unless you specifically need resolved or historical markets.
  2. Prefer the events endpoint as your starting point — events bundle their markets, cutting down the number of API calls.
  3. For trading bots, load an initial snapshot via REST, then switch to WebSocket streaming for live updates.
  4. Cache Gamma API responses and refresh on a schedule rather than hitting the API on every user interaction.