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.
Strategy 1: REST Polling via Gamma API
Section titled “Strategy 1: REST Polling via Gamma API”The most direct method. Query the Gamma API for events or markets, applying filters and pagination as needed.
Fetch Active Events
Section titled “Fetch Active Events”curl "https://gamma.openfish.fun/events?active=true&closed=false&order=volume_24hr&ascending=false&limit=50"Fetch a Specific Event by Slug
Section titled “Fetch a Specific Event by Slug”Extract the slug from the Openfish frontend URL:
https://openfish.fun/event/btc-100k-by-december ^ Slug: btc-100k-by-decembercurl "https://gamma.openfish.fun/events?slug=btc-100k-by-december"Fetch Markets by Tag
Section titled “Fetch Markets by Tag”# Discover available tagscurl "https://gamma.openfish.fun/tags"
# Filter events by tagcurl "https://gamma.openfish.fun/events?tag_id=100381&active=true&closed=false&limit=20"Key Query Parameters
Section titled “Key Query Parameters”| Parameter | Description |
|---|---|
active | Filter by active status (true for live tradable events) |
closed | Filter by closed status (false to exclude resolved markets) |
order | Sort field: volume_24hr, volume, liquidity, start_date, end_date |
ascending | Sort direction (true or false, default false) |
limit | Results per page |
offset | Number of results to skip for pagination |
tag_id | Filter by category tag |
slug | Look 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.
# Single request returns the event and all its marketscurl "https://gamma.openfish.fun/events/125819"Each market object nested inside an event contains:
outcomesandoutcomePricesarraystokensarray with CLOB token IDsconditionIdfor CTF operationsenableOrderBookflag indicating CLOB availability
Rust SDK Example
Section titled “Rust SDK Example”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(())}Strategy 3: WebSocket Streaming
Section titled “Strategy 3: WebSocket Streaming”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(())}Pagination
Section titled “Pagination”All list endpoints paginate with limit and offset:
# Page 1curl "https://gamma.openfish.fun/events?active=true&closed=false&limit=50&offset=0"
# Page 2curl "https://gamma.openfish.fun/events?active=true&closed=false&limit=50&offset=50"
# Page 3curl "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.
Choosing the Right Strategy
Section titled “Choosing the Right Strategy”| Strategy | Best For | Latency | Complexity |
|---|---|---|---|
| REST polling | Periodic snapshots, simple integrations | Seconds | Low |
| Gamma API metadata | Rich context, event-level views | Seconds | Low |
| WebSocket streaming | Real-time dashboards, trading bots | Milliseconds | Medium |
Best Practices
Section titled “Best Practices”- Default to
active=true&closed=falseunless you specifically need resolved or historical markets. - Prefer the events endpoint as your starting point — events bundle their markets, cutting down the number of API calls.
- For trading bots, load an initial snapshot via REST, then switch to WebSocket streaming for live updates.
- Cache Gamma API responses and refresh on a schedule rather than hitting the API on every user interaction.
Next Steps
Section titled “Next Steps”- Market Data Overview — Full endpoint listing.
- WebSocket Overview — Real-time data streaming reference.