Developer Hub
🔮 For applications
Guides & Tutorials
Advanced integration
Live betting
Get Bets History

Get Bets History

Bet Info

To get information about the user-placed live bets, you can use the following GraphQL query:

query LiveBets(
  $first: Int, 
  $skip: Int, 
  $where: LiveBet_filter, 
  $orderBy: LiveBet_orderBy
) {
  liveBets(
    first: $first, 
    skip: $skip, 
    orderBy: $orderBy, 
    orderDirection: desc,
    where: $where, 
    subgraphError: allow
  ) {
    ...LiveBet
  }
}
 
fragment LiveBet on LiveBet {
  id
  betId
  status
  amount
  odds
  createdAt
  potentialPayout
  payout
  result
  selections {
    odds
    result
    outcome {
      id
      outcomeId
      condition {
        id
        conditionId
        status
        gameId
      }
    }
  }
  isRedeemed
  isRedeemable
  txHash
  core {
    address
    liquidityPool {
      address
      tokenSymbol
    }
  }
}
 
useQuery(QUERY, {
  variables: {
    where: {
      actor_starts_with_nocase: userWalletAddress,
    },
  },
})

Each liveBets item represents the result of a transaction. To preserve consistency, there is a selections field in the data that contains an array of data about each bet.

⚠️

Live bets lack specific game information due to the storage of live games exclusively within the LiveDataFeed subgraph, providing access solely to the gameId.

selections {
    odds
    result
    outcome {
      id
      outcomeId
      condition {
        id
        conditionId
        status
        gameId
      }
    }
  }

To get game data, you'll need to make a request to the LiveDataFeed subgraph, utilizing the gameId.

query Game($gameId: BigInt) {
  games(
    where: { gameId: $gameId }
  )
    sport {
      name
    }
    league {
      name
      country {
        name
      }
    }
    participants {
      name
      image
    }
    startsAt
  }
}

Bet Status

The status field value is of type enum and has three states: Accepted, Canceled, and Resolved. Until the outcome the bet was made on is resolved, the status of the bet will be Accepted. During the Accepted status of a bet, it can be regarded as in progress - Live.

const isLive = bet.status === BetStatus.Accepted

It's important to check if bet status is Accepted to handle the situation when game is finished and the results are resolved.

Bet Result

The result field value is of type enum and has three states: Won, Lost.

const isWon = bet.result === BetResult.Won
const isLost = bet.result === BetResult.Lost

Note that until the outcome is resolved result will be null.

Market and Selection Names

import { getMarketName, getSelectionName } from '@azuro-org/dictionaries'
 
const marketName = getMarketName({ outcomeId })
const selectionName = getSelectionName({ outcomeId })

Read more about dictionaries here.

Pagination

There can be a lot of bets from one user and there can be a problem with fetching all of them at once.

⚠️

From "GraphQL" section:

TheGraph has a limit of returning a maximum of 1000 elements per request, with a default of 100 elements. Keep this limit in mind when building your queries. Read how to paginate (opens in a new tab).

query BetsHistory($first: Int!, $skip: Int!) {
  liveBets(first: $first, skip: $skip, subgraphError: allow) {
    ...LiveBet
  }
}
const PAGE_SIZE = 100
 
const [ page, setPage ] = useState(1)
 
useQuery(QUERY, {
  variables: {
    skip: (page - 1) * PAGE_SIZE,
    first: PAGE_SIZE,
  },
})