Guides
Get bets made on specific Front(Affiliate)

Get bets made on specific Front(Affiliate)


This documentation provides step-by-step instructions on how to calculate Gross Gaming Revenue (GGR) per user for a specific affiliate using a GraphQL query. We will explain the GraphQL query and variables, introduce the GGR formula, and detail how to calculate GGR for each user based on this formula.

GraphQL Query

The GraphQL query used to retrieve the necessary data for calculating GGR per user is as follows:

query Bets {
  bets(
    where: {
      status_in: [Resolved, Canceled],
      affiliate: $affiliate
    }
    first: 1000,
    skip: $skip
  ) {
    bettor
    odds
    amount
    payout
    _isFreebet
  }
}

Explaining Variables:

  • $affiliate: The affiliate ID for which GGR is being calculated.
  • $skip: Used for pagination to skip a certain number of records when fetching data.

GGR

What is GGR?

Gross Gaming Revenue (GGR) represents the total revenue generated by a gambling operation before deducting the cost of bets won by users. In the context of this document, we calculate the GGR for a specific affiliate based on their users’ betting activity.

GGR Formula:

The formula to calculate GGR is:

GGR = totalBetAmount - totalWonAmount

Where:

  • totalBetAmount is the sum of all bet amounts placed by users.
  • totalWonAmount is the sum of all amounts won by users.

How to Calculate totalBetAmount:

To calculate the totalBetAmount, sum up the amount of each bet retrieved from the GraphQL query:

totalBetAmount = sum(bet.amount)

How to Calculate totalWonAmount:

To calculate the totalWonAmount we use two formulas depending on _isFreebet status of bet:

  • If bet._isFreebet == false :
totalWonAmount = sum(bet.payout)
  • If bet._isFreebet == true :
totalWonAmount = sum(bet.amount * (bet.odds - 1))

Calculating Affiliate's GGR

To calculate the GGR for a specific affiliate:

  • Execute the GraphQL query with the affiliate's identifier.
  • Apply the GGR formula as described above.
 
. . .
// Sum up bet amounts
const totalBetAmount = bets.reduce((e: number, {amount}) => e+Number(amount), 0);
 
// Sum up won amount based on bet status
const totalWonAmount = bets.reduce((e: number, bet) => {
    if (bet._isFreebet) {
        e += Number(bet.amount) * (Number(bet.odds) - 1)
    } else {
        e += Number(bet.payout)
    }
 
    return e
}, 0);

Calculating GGR for a Specific Period of Time

where: {
      status_in: [Resolved, Canceled],
      resolvedBlockTimestamp_gte: $since,
      resolvedBlockTimestamp_lte: $until,
      affiliate: $affiliate
}
  • $since: The start date for the date range within which bets should be considered.
  • $until: The end date for the date range within which bets should be considered.

Calculating GGR for Each User

To calculate the GGR for each user based on the above formulas, follow these steps:

  1. Execute the GraphQL query to retrieve bets for the specific affiliate ($affiliate) within the specified date range ($since to $until).
  2. Loop through the retrieved bets:
    • For each bet, identify the bettoramount , odds , _isFreebet and payout.
  3. Calculate GGR for each user:
    • Initialize an empty dictionary or data structure to store the calculated GGR for each user.
    • For each bet, determine the user who placed the bet.
    • Calculate the GGR for that user using the GGR formula:
GGR = totalBetAmount - totalWonAmount

4.  Continue this process until you have processed all the retrieved bets.

5.  The dictionary or data structure will now contain the calculated GGR for each user. You can access these GGR values for the specific affiliate and perform further analysis or reporting.By following these steps, you can successfully calculate the Gross Gaming Revenue (GGR) per user for a specific affiliate based on their betting activity within the specified date range. The provided GGR formula helps you understand how GGR is derived from the total bet and won amounts.

Code example

import {request, gql} from "graphql-request";
 
interface BetSpec {
  bettor: string;
  amount: Number;
  payout: Number;
  odds: Number;
  _isFreebet: boolean;
}
 
// Initialize an empty dictionary to store GGR per user
const ggrPerUser: { [userId: string]: number } = {};
 
// Set initial skip value to 0 for pagination
let skip = 0;
 
while (true) {
  // Execute the GraphQL query with the appropriate variables
  const graphQuery = gql`...`; // Insert the GraphQL query here
 
  // Make the request and retrieve the data
  const graphRes = await request(graphUrl, graphQuery);
 
  // Process each bet
  for (const bet of graphRes.bets as BetSpec[]) {
    const { bettor, amount, payout, odds, _isFreebet } = bet;
 
    // Calculate GGR for each bet
    if (_isFreebet) {
      const ggr = amount - amount * (odds - 1);
    } else {
      const ggr = amount - payout;
    }
 
    // Add GGR to the user's total
    if (!ggrPerUser[bettor]) {
      ggrPerUser[bettor] = 0;
    }
    ggrPerUser[bettor] += ggr;
 
    // Continue processing until all bets are retrieved
  }
 
  // Increment the skip value for pagination
  skip += 1000;
 
  // Check if there are more bets to fetch
  if (graphRes.bets.length < 1000) {
    break;
  }
}