Cricwix
← Back to blog
Tutorial·10 min read·June 16, 2026

Building a Fantasy Cricket App with Real-Time Data

Learn how to architect a fantasy cricket scoring engine using live ball-by-ball data, player points calculation, and leaderboard updates from the Cricwix API.

By Cricwix Team

Fantasy cricket is a data problem wrapped in a sports product. The scoring engine needs player stats in real time, the points table must update on every ball, and the leaderboard has to handle thousands of simultaneous users without falling over. This guide covers the architecture.

The Core Data Requirements

A fantasy cricket app needs three types of data from its API:

  • Pre-match: squad announcements, player form, pitch report
  • In-match: ball-by-ball events (runs, wickets, extras, boundaries)
  • Post-match: final scorecards, player of the match, statistics

Fetching Pre-Match Data

Before a match starts, you need the playing XI to lock user team selections. Use the Cricwix /fixtures endpoint with status=upcoming and filter by match ID:

javascript
// Fetch squad for a specific match
const squad = await fetch(
  `https://api.cricwix.com/ext/v1/players?match_id=${matchId}`,
  { headers: { 'x-api-key': API_KEY } }
).then(r => r.json());

Building the Points Engine

Fantasy points are calculated from raw statistics. A typical T20 scoring system looks like this:

  • Run scored: +1 point each
  • Boundary (4): +1 bonus point
  • Six: +2 bonus points
  • Wicket taken: +25 points
  • Maiden over: +12 points
  • Catch: +8 points
  • Duck (batting): -2 points
typescript
function calculatePoints(playerStats: PlayerStats): number {
  let points = 0;
  points += playerStats.runs;
  points += playerStats.fours * 1;
  points += playerStats.sixes * 2;
  points += playerStats.wickets * 25;
  points += playerStats.catches * 8;
  points += playerStats.maidens * 12;
  if (playerStats.runs === 0 && playerStats.ballsFaced > 0) points -= 2;
  return points;
}

Real-Time Score Updates

Poll the /scores endpoint every 10-15 seconds during a live match. Cricwix returns a structured ball-by-ball object you can diff against your previous state to detect new events:

typescript
async function pollLiveScore(matchId: string) {
  const { data } = await fetch(
    `https://api.cricwix.com/ext/v1/scores?match_id=${matchId}`,
    { headers: { 'x-api-key': API_KEY } }
  ).then(r => r.json());

  // Detect new events by comparing ball count
  if (data.balls_bowled > lastBallCount) {
    await updatePlayerPoints(data.latest_ball);
    await broadcastLeaderboard();
    lastBallCount = data.balls_bowled;
  }
}

Scaling the Leaderboard

With thousands of users, recalculating every fantasy team on every ball is expensive. Use a sorted set in Redis to maintain rankings — update only the affected players, then re-sort:

typescript
// After a wicket falls, update only teams with the bowler
await redis.zincrby('leaderboard:match_123', wicketPoints, teamId);
const topTeams = await redis.zrevrange('leaderboard:match_123', 0, 99, 'WITHSCORES');

Handling Match Interruptions

Rain breaks, DLS method, and match abandonment are realities in cricket. The Cricwix API includes a match_status field that signals these states. Build your engine to pause point accrual and communicate clearly to users when a match is interrupted.

💡

Always lock team selections 30 minutes before the official toss, not just at match start. Playing XI changes happen after the toss and catching them early prevents disputes.

Putting It Together

Fantasy cricket is hard to build well. The data layer — live scores, player statistics, squad updates — is where most teams spend their time. Cricwix handles that layer so you can focus on the product: the team selection UX, the leaderboard experience, the contest mechanics that keep users coming back.

// ready to build?

Start free today

100 free API calls per day. No credit card required.

Get your API key →