Cricket API Tutorials

How to Build a Fantasy Cricket App Using an API

Learn how to build a fantasy cricket application with stable player data, team-selection rules, live event scoring, captain multipliers, contests, corrections and real-time leaderboards.

A fantasy cricket app combines fixtures, player data, live match events, contest rules and user selections into one scoring system. The interface may look simple, but the backend must keep player identities consistent, lock teams at the correct time, calculate points accurately, process score corrections and update leaderboards without counting the same event twice.

This guide explains a practical architecture for building a fantasy cricket application with a Cricket API. It covers fixtures, squads, player statistics, team selection, captain multipliers, live scoring, contests, leaderboards, caching, corrections, security and production testing.

Important: The endpoints, response fields and fantasy rules in this tutorial are illustrative. Replace them with the exact data, authentication, scoring rules, contest requirements and legal obligations that apply to your product.

Define the Fantasy Cricket Product First

Before building the technical system, decide what type of fantasy experience you are creating. The data and architecture will differ depending on whether the product is free-to-play, private, commercial or connected to prizes.

Product type Typical features Important consideration
Private league Friends, invited users and a simple leaderboard Lower scale but still requires accurate scoring
Season-long fantasy Persistent squads, transfers and season standings Long-term player and fixture consistency
Daily fantasy Match or round-based team selection Strict contest locks and rapid scoring
Free prediction game Player picks, points, badges and rankings Can use simpler contest and payment logic
Prize-based platform Paid contests, wallets, payouts and compliance Requires legal, financial and responsible-use controls

Core Data Required From a Cricket API

A fantasy cricket product usually needs several connected data categories. Confirm that your API plan includes the competitions and fields required by the scoring rules.

  • Upcoming fixtures and match start times
  • Competitions, rounds and seasons
  • Teams and stable team identifiers
  • Players and stable player identifiers
  • Squads and confirmed line-ups
  • Player roles such as batter, bowler, all-rounder and wicketkeeper
  • Live batting, bowling and fielding events
  • Scorecards and final match results
  • Historical player statistics
  • Corrections and finalised match data
Stable player identifiers are essential. Names can change, repeat or appear with different spelling. Do not connect fantasy points using display names alone.

Recommended Fantasy Cricket Architecture

Cricket API
   |
   +-- Fixtures and competitions
   +-- Squads and line-ups
   +-- Live match events
   +-- Scorecards and results
   +-- Player statistics
   |
   v
Fantasy application backend
   |
   +-- Player and match database
   +-- Scoring engine
   +-- Contest service
   +-- User-team service
   +-- Leaderboard service
   +-- Cache and event log
   |
   v
Website and mobile applications

The browser or mobile app should communicate with your own backend. The backend protects API credentials, enforces contest locks, stores user teams and calculates authoritative fantasy points.

Step 1: Import Competitions and Fixtures

Fixture import flow

1. Request supported competitions
2. Select the competitions used by the fantasy product
3. Request upcoming fixtures
4. Store match, team, venue and start-time identifiers
5. Convert times to a standard server timezone
6. Schedule future squad and line-up refreshes
7. Mark postponed, cancelled and completed fixtures correctly

Suggested Match Record

{
  "match_id": "match_84219",
  "competition_id": "competition_91",
  "season_id": "season_2026",
  "format": "T20",
  "team_a_id": "team_18",
  "team_b_id": "team_29",
  "starts_at": "2026-08-10T14:00:00Z",
  "status": "scheduled",
  "fantasy_lock_at": "2026-08-10T14:00:00Z"
}

Step 2: Import Squads and Players

Create one local player record for each stable provider player identifier. Store display information separately from identity.

Player field Purpose
Provider player ID Stable connection to API statistics and match events
Display name Name shown to users
Team ID Current squad relationship
Role Batter, bowler, all-rounder or wicketkeeper
Credits or salary Budget value controlled by the fantasy platform
Availability Available, doubtful, unavailable or confirmed
Last updated Freshness of squad information

Do not delete a player simply because the player leaves a squad. Historical fantasy teams and completed contests still need the original record.

Step 3: Define Team Selection Rules

  • Select 11 players
  • Use a defined maximum credit budget
  • Select players from both participating teams
  • Set minimum and maximum numbers by player role
  • Limit the number of players from one real team
  • Select one captain and one vice-captain
  • Prevent changes after the contest lock time
{
  "valid": false,
  "errors": [
    "Select exactly 11 players",
    "Maximum 7 players are allowed from one team",
    "A captain must be selected"
  ]
}

Frontend validation improves usability, but the backend must remain authoritative. A user can bypass browser checks or send a modified request.

Step 4: Create Versioned Fantasy Scoring Rules

Scoring rules should be stored as versioned configuration rather than scattered through templates or controllers. This allows future changes without altering completed contests.

Event Illustrative points Notes
Run scored +1 One point per run
Boundary bonus +1 Additional bonus for a four
Six bonus +2 Additional bonus for a six
Wicket +25 Rules may exclude certain dismissal types
Catch +8 Fielding event
Stumping +12 Wicketkeeper event
Captain multiplier Applied after base points
Vice-captain multiplier 1.5× Applied after base points
{
  "scoring_version": "t20_v1",
  "batting": {
    "run": 1,
    "four_bonus": 1,
    "six_bonus": 2,
    "half_century_bonus": 8,
    "century_bonus": 16
  },
  "bowling": {
    "wicket": 25,
    "three_wicket_bonus": 4,
    "five_wicket_bonus": 8,
    "maiden_over": 12
  },
  "fielding": {
    "catch": 8,
    "stumping": 12
  },
  "multipliers": {
    "captain": 2,
    "vice_captain": 1.5
  }
}

Step 5: Lock User Teams Correctly

  1. Store the authoritative match start time in UTC
  2. Define the contest lock time
  3. Show the local lock time to the user
  4. Validate every team update against server time
  5. Reject edits after the lock
  6. Create an immutable snapshot of the submitted team
Team snapshot

contest_entry_id
user_id
match_id
locked_at
scoring_version
selected_player_ids
captain_player_id
vice_captain_player_id
total_credits
validation_result

Step 6: Process Confirmed Line-Ups

  • Refresh squad and line-up data before the match
  • Display a visible confirmed-playing indicator
  • Do not silently replace a user’s player
  • Define substitute or auto-swap rules before contest entry
  • Record the line-up data available when the team locked

When confirmed line-ups are unavailable, be transparent rather than presenting an assumption as official.

Step 7: Build the Live Scoring Engine

Live scoring flow

1. Receive or request a new match event
2. Validate the match and event identifiers
3. Check whether the event was already processed
4. Map the event to one or more player IDs
5. Calculate base fantasy points
6. Store the event-level point transaction
7. Recalculate affected user entries
8. Apply captain and vice-captain multipliers
9. Update contest leaderboards
10. Broadcast the new ranking to connected users

Use Event-Level Point Transactions

{
  "fantasy_event_id": "fantasy_event_771",
  "match_id": "match_84219",
  "source_event_id": "event_991827",
  "player_id": "player_301",
  "event_type": "boundary_four",
  "base_points": 5,
  "scoring_version": "t20_v1",
  "processed_at": "2026-08-10T15:41:02Z"
}

This event ledger makes corrections, audits and leaderboard explanations much easier.

Step 8: Prevent Duplicate Scoring

  • Store the provider’s unique event identifier
  • Use a database uniqueness rule where possible
  • Process the point transaction and event record atomically
  • Track match-specific sequence numbers when available
  • Reconcile against the final scorecard after the match
Duplicate protection

Before processing:
- Does source_event_id already exist?

If yes:
- Stop without changing player points

If no:
- Calculate points
- Save the source event
- Save point transactions
- Commit all changes together

Step 9: Handle Score Corrections

  1. Identify the original source event
  2. Reverse its fantasy point transactions
  3. Store the correction reason and timestamp
  4. Apply the corrected event
  5. Recalculate affected user entries
  6. Update the leaderboard
  7. Reconcile again after the final scorecard
Avoid editing the original point record without history. Reversal and replacement transactions preserve an auditable trail.

Step 10: Calculate Captain and Vice-Captain Points

Example

Player base points: 52

Normal selection:
52 × 1 = 52

Vice-captain:
52 × 1.5 = 78

Captain:
52 × 2 = 104

Apply multipliers at the user-entry level because the same player can be a captain for one user and a normal selection for another.

Step 11: Build Contest Leaderboards

  • Base points for every player in the match
  • Total points for every contest entry
  • Current rank
  • Previous rank
  • Last scoring update time
  • Finalisation status
Leaderboard record

contest_id
entry_id
user_id
total_points
current_rank
previous_rank
last_updated_at
is_final

Define tie rules before contest entry. Possible approaches include equal rank, earlier entry time or another published criterion.

Step 12: Add Player Research and Statistics

  • Recent matches
  • Average fantasy points
  • Batting and bowling form
  • Match-format performance
  • Venue performance
  • Opposition history
  • Selection percentage
  • Confirmed line-up status
Historical performance does not guarantee future fantasy points. Show the sample size and relevant format or competition.

Step 13: Use Caching Without Breaking Accuracy

Data Suggested cache approach
Competitions and teams Longer cache with periodic refresh
Upcoming fixtures Moderate cache with status monitoring
Squads Refresh more often near match time
Confirmed line-ups Short cache before the lock
Live player points Event-driven or very short cache
Completed leaderboards Long cache after finalisation

Step 14: Design the User Flow

1. User chooses an upcoming match
2. App shows available players and credits
3. User selects a valid team
4. User assigns captain and vice-captain
5. Backend validates and saves the draft
6. User joins a contest
7. Entry locks at the published time
8. Live events generate fantasy points
9. Leaderboard updates during the match
10. Final scorecard triggers reconciliation
11. Contest is marked final

Fantasy Cricket Database Structure

Table or collection Purpose
competitions Competition and season records
matches Fixtures, status and lock time
teams Real cricket teams
players Stable player identities and roles
match_squads Player availability for a fixture
contests Contest rules, capacity and scoring version
contest_entries User participation and locked team snapshot
entry_players Selected players and multiplier roles
fantasy_events Event-level point transactions
player_match_points Current base fantasy total by player
leaderboards Entry totals and rankings

Security Requirements

  • Keep Cricket API credentials on the server
  • Require authenticated user sessions
  • Validate ownership before changing a fantasy team
  • Use server time for contest locks
  • Rate-limit team updates and contest joins
  • Record important user and scoring actions
  • Protect administrative scoring controls
  • Do not trust totals submitted by the browser

Payments, Prizes and Compliance

A free fantasy game is different from a prize-based or paid-entry product. Regulatory requirements vary by jurisdiction.

  • Confirm whether the product is legally permitted
  • Obtain qualified legal guidance
  • Apply age and geographic restrictions where required
  • Use compliant payment and identity-verification systems
  • Publish contest, cancellation and prize rules
  • Provide responsible-play controls where relevant
  • Protect financial and personal information
Technical access to cricket data does not authorise a company to operate paid fantasy contests or gambling-related services.

Testing Checklist

  • A user cannot select more than the permitted players
  • Role limits and credit budgets are enforced
  • A user cannot edit a team after lock time
  • Confirmed line-ups update correctly
  • Captain and vice-captain multipliers are correct
  • Duplicate match events do not duplicate fantasy points
  • Corrections reverse and replace previous points
  • Leaderboards update after every valid event
  • Equal-score tie rules work as published
  • Postponed and abandoned matches follow contest rules
  • Final scorecards reconcile the live point totals
  • Finalised contests cannot change without an audited correction

Common Fantasy Cricket Development Mistakes

Matching Players by Name

Always use stable player identifiers. Names are not reliable primary keys.

Calculating Points Only From the Current Scorecard

Store event-level point transactions so you can explain, reverse and audit changes.

Allowing the Browser to Decide the Lock Time

Use authoritative server time and reject late modifications on the backend.

Applying New Rules to Old Contests

Version the scoring configuration and preserve the version used when the contest was created.

Ignoring Corrections

Reconcile live scoring against final official match data before finalising a leaderboard.

Showing Unconfirmed Players as Playing

Distinguish squad inclusion from confirmed line-up selection.

Fantasy Cricket App FAQs

Which Cricket API data is required for a fantasy app?

You typically need fixtures, teams, players, squads, confirmed line-ups, live match events, scorecards, final results and historical statistics.

Can I calculate fantasy points from ball-by-ball data?

Yes, provided the feed contains the required batting, bowling and fielding events. Use unique event IDs and reconcile against the final scorecard.

How should captain points be calculated?

Calculate the player’s base fantasy points once, then apply the published captain or vice-captain multiplier at the user-entry level.

When should fantasy teams lock?

Use the published contest rule, usually at or before the official match start. Enforce the lock with server time, not the user’s device time.

What happens when a score is corrected?

Reverse the original point transactions, apply the corrected event, update affected entries and preserve an audit trail.

Can I build a fantasy cricket app in WordPress?

WordPress can support content, accounts and a custom application interface, but real-time scoring and contest logic should be implemented in a secure custom plugin or separate backend service rather than page content.

Can I offer paid fantasy contests?

Only after confirming that the product, jurisdiction, payments, age controls, licensing and contest structure comply with applicable law and platform rules.

Build Your Fantasy Cricket Data Pipeline

Start with stable fixtures and player IDs, define versioned scoring rules, lock user teams securely and process every live event exactly once. Reconcile all fantasy points against the final scorecard before completing a contest.

Build Cricket Products With Reliable API Data

Access live scores, fixtures, ball-by-ball updates, statistics, odds, predictions and historical cricket data through one developer-friendly API.

Get API Access
Written By

James

Chat on WhatsApp