Developer Hub
🔮 For applications
Guides & Tutorials
Advanced integration
Prematch
Get Games

Get Games

💡

Before you begin working with GraphQL queries, please read the Highlights and Request Optimizations articles.

Fetch games

To fetch data you should use Azuro Subgraph. The following query represents main fields required to present a game info and its markets with outcomes.

Use the startsAt field in your query to filter and display only ongoing or future games. For example, you could modify the query to only retrieve games that are scheduled to start in the future:

query Games($where: Game_filter!) {
  games(
    first: 1000
    where: $where
    subgraphError: allow
  ) {
    id
    gameId
    slug
    startsAt
    league {
      name
      slug
      country {
        name
        slug
      }
    }
    sport {
      name
      slug
    }
    participants {
      image
      name
    }
  }
}
useQuery(GAMES_QUERY, {
  variables: {
    where: {
      startsAt_gt: Math.floor(Date.now() / 1000),
      hasActiveConditions: true,
      liquidityPool: LP_ADDRESS.toLowerCase()
    },
  },
})

Try it yourself in GraphiQL (opens in a new tab)

Parameters

query Games($where: Game_filter!) {
  games(
    first: 1000
    where: $where
    subgraphError: allow
  ) {
    ...GameFields
  }

first

— Limit of returning games, default (if not set) is 100, maximum is 1000. Details

where

Game_filter allow you to filter result by any field exists in Game. Most required variables described below in "where" filters section.

subgraphError: allow

— Allows to get data even if the subgraph has indexing errors. It's better to keep this parameter with every subgraph query. Details

"where" common filters

There is most required filters to show list of active games:

useQuery(GAMES_QUERY, {
  variables: {
    where: {
      startsAt_gt: Math.floor(Date.now() / 1000),
      hasActiveConditions: true,
      liquidityPool: LP_ADDRESS.toLowerCase(),
    },
  },
})

startsAt_gt

— Filter out games which already started. It will be changed in the future, but right now we support only pre-match markets.

We recommend always using it in game lists, as requesting all games without such filters, even those that have already concluded, can impose unnecessary load on the GraphQL node and potentially lead to performance issues. In general, it's advisable to request only the data essential for your application's functionality.

ℹ️

Values of startsAt fields are calculated in seconds

hasActiveConditions: true

— Get games which have at least one active condition. This ensures that only games with available betting options are returned in the query results. Most likely you will always use this parameter.

liquidityPool: lp_address

— filter games by LP address.

Since Subgraphs contain data from different LP contracts, it's possible to have duplicated games across multiple LP contracts. In order to avoid issues related to duplicated data, it's important to identify which LP contract your application will interact with and use the corresponding address to filter the data. This ensures that only relevant data is retrieved and reduces the risk of conflicts and errors. It's recommended to carefully consider which LP contract to use based on your specific use case and business requirements. Get more information.

ℹ️

From "GraphQL" section:

When working with Subgraphs, all address values are stored in lowercase. This means that when passing variables to queries, it's important to convert the transmitted value to lowercase, or use the _contains_nocase postfix.

Sorting parameters

There are two optional parameters to sort query result:

query Games($where: Game_filter!) {
  games(
    first: 1000
    where: $where
    subgraphError: allow
    orderBy: startsAt
    orderDirection: asc
  ) {
    ...GameFields
  }

orderBy

— It may be any field from the game entity - gameId, startsAt, turnover, etc.

orderDirection

— How to sort - "A-Z" or "Z-A". Values: asc (default) or desc.

Examples

Top-10 games with the highest volume of bets

query Games($where: Game_filter!) {
  games(
    first: 10
    where: $where
    subgraphError: allow
    orderBy: turnover
    orderDirection: desc
  ) {
    ...GameFields
  }

Specific sport games

In the top of the chapter we defined slug field in some fields (sport, league, country). You can build a url structure by them, and use to filter games:

query Games($where: Game_filter!) {
  games(
    first: 1000
    where: $where
    subgraphError: allow
  ) {
    ...GameFields
  }
import { useSearchParams } from 'next/navigation'
 
const { query } = useSearchParams()
const sportSlug = query.get('sport') // e.g. "football"
 
useQuery(QUERY, {
  variables: {
    where: {
      sport_: {
        slug: sportSlug,
      },
      startsAt_gt: Math.floor(Date.now() / 1000),
      hasActiveConditions: true,
      liquidityPool: LP_ADDRESS.toLowerCase(),
    },
  },
})
ℹ️

Please pay attention, that Azuro protocol can release a new sport (e.g. esports, cricket, etc). We don't recommend to build navigation by raw usage of sports query from the subgraph. It's better to keep filter by sports which are supported in your app.