![How to build a fantasy game with Sportmonks Football API?](jpg/fantasy-game-football-api.jpg)
![How to build a fantasy game with Sportmonks Football API?](jpg/fantasy-game-football-api.jpg)
Fantasy games are trendy among football fans. Creating a winning team or predicting the best XI is the perfect way to engage your users. To create a fantasy game, you will need player statistics and ratings, among other things. In this blog, we will dive into how you can create your own fantasy game. Let’s get started.
A popular application for our football data is football fantasy games. Fantasy games are games where participants assemble a cast of real-life characters for a virtual team. This virtual team mimics their real-life counterparts. Everything is statistic-based.
If, for instance, you have the iconic Haaland in your fantasy team, and he manages to score a hat trick during an actual match, then this increase in performance will be reflected in your virtual Haaland.
The player of a fantasy game can draft, trade, and drop players from their teams. The goal is to assemble a team that can win the championship, akin to real sports.
In this blog, we’ll show you the most essential features of a good sports fantasy game and why our Football API is perfectly suited for building a fantasy game.
{ "data": [ { "id": 2, "sport_id": 1, "country_id": 41, "name": "Champions League", "active": true, "short_code": "UEFA CL", "image_path": "https://cdn.sportmonks.com/images/soccer/leagues/2.png", "type": "league", "sub_type": "cup_international", "last_played_at": "2023-08-15 19:00:00", "category": 1, "has_jerseys": false }, { "id": 5, "sport_id": 1, "country_id": 41, "name": "Europa League", "active": true, "short_code": "UEFA EL", "image_path": "https://cdn.sportmonks.com/images/soccer/leagues/5.png", "type": "league", "sub_type": "cup_international", "last_played_at": "2023-08-10 19:00:00", "category": 1, "has_jerseys": false }, { "id": 8, "sport_id": 1, "country_id": 462, "name": "Premier League", "active": true, "short_code": "UK PL", "image_path": "https://cdn.sportmonks.com/images/soccer/leagues/8/8.png", "type": "league", "sub_type": "domestic", "last_played_at": "2023-08-14 19:00:00", "category": 1, "has_jerseys": false }, //and more
So, you’ve decided to create your own fantasy game. One of the first things you will need to do for yourself is to determine the leagues you want to include in your fantasy game.
Many existing fantasy games base their game on one big league. However, you can also choose to combine multiple leagues.
With more than 2500+ leagues to choose from, we definitely have one or multiple leagues you can base your fantasy game on. You can request all the leagues we have via our All Leagues endpoint:
https://api.sportmonks.com/v3/football/leagues?api_token=YOURTOKEN
However, please remember that the coverage is different for every league.
You want to gather as much data as possible for a fantasy game. Therefore, we suggest checking out our coverage page and only selecting leagues with minimum basic player statistics, but detailed statistics are recommended.
Of course, for all major leagues, detailed statistics are available. Now let’s dive in on which type of statistics might be interesting for your Fantasy Game.
{ "data": { "id": 8, "sport_id": 1, "country_id": 462, "name": "Premier League", "active": true, "short_code": "UK PL", "image_path": "https://cdn.sportmonks.com/images/soccer/leagues/8/8.png", "type": "league", "sub_type": "domestic", "last_played_at": "2023-08-14 19:00:00", "category": 1, "has_jerseys": false, "currentseason": { "id": 21646, "sport_id": 1, "league_id": 8, "tie_breaker_rule_id": 171, "name": "2023/2024", "finished": false, "pending": false, "is_current": true, "starting_at": "2023-08-11", "ending_at": "2024-05-19", "standings_recalculated_at": "2023-08-16 00:05:33", "games_in_current_week": true, "statistics": [ { "id": 278934, "model_id": 21646, "type_id": 34, "relation_id": 13, "value": { "count": 10, "percentage": 8.62, "team_most_corners_id": 13, "team_most_corners_name": "Everton" }, "type": "array" }, { "id": 278931, "model_id": 21646, "type_id": 43, "relation_id": null, "value": { "count": 2030, "average": 203 }, "type": "array" }, { "id": 278935, "model_id": 21646, "type_id": 44, "relation_id": null, "value": { "count": 999, "average": 99.9 }, "type": "array" }, { "id": 278930, "model_id": 21646, "type_id": 79, "relation_id": null, "value": { "count": 20, "average": 2 }, "type": "array" }, //and more!
The Season statistics endpoint gives you great insight into how ‘attractive’ the league is. It gives you information about the average goals scored per match, average cards per match, and the average player rating. Especially the average player rating is interesting because you can show your app users this rating. More about this later.
Let’s say you’ve chosen to make a fantasy game for the English Premier League (league id: 8). You now need to gather the right information. Since you want to build a live fantasy game, the active season id might be a good starting point.
As you know, you can request the active season id by enriching your request with include=currentSeason
https://api.sportmonks.com/v3/football/leagues/8?api_token=YOURTOKEN&include=currentSeason
Now that you have the season’s current id, you can request the corresponding information like season statistics, participating teams and, of course, the players.
You can request the season statistics by using the season by id endpoint with &include=statistics
https://api.sportmonks.com/v3/football/seasons/21646?api_token=YOURTOKEN&include=statistics
You might know we use types across all endpoints if you’re familiar with our API and documentation. Types are used throughout the entire API. We recommend retrieving all types from the types endpoint and storing them in your database or other data structure. Only include the type if no other option exists or when testing the API. More information can be found on our best practices page.
TIP:
To save yourself from making an extra request, you can also use the nested include currentSeason.statistics on our league by id endpoint:
https://api.sportmonks.com/v3/football/leagues/8?api_token=YOURTOKEN&include=currentSeason.statistics
Now that we have all the season statistics, we need to gather all the teams and the squads participating in this season.
{ "data": [ { "id": 78, "sport_id": 1, "country_id": 462, "venue_id": 480, "gender": "male", "name": "Brighton & Hove Albion", "short_code": "BRH", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/14/78.png", "founded": 1901, "type": "domestic", "placeholder": false, "last_played_at": "2023-08-12 14:00:00", "players": [ { "id": 741444, "transfer_id": 233009, "player_id": 54191, "team_id": 78, "position_id": 25, "detailed_position_id": 148, "start": "2023-07-26", "end": "2027-06-30", "captain": false, "jersey_number": 3, "player": { "id": 54191, "sport_id": 1, "country_id": 5, "nationality_id": 5, "city_id": null, "position_id": 25, "detailed_position_id": 148, "type_id": 25, "common_name": "I. dos Santos de Paulo", "firstname": "Igor Julio", "lastname": "dos Santos de Paulo", "name": "Igor Julio dos Santos de Paulo", "display_name": "Igor Júlio", "image_path": "https://cdn.sportmonks.com/images/soccer/players/15/54191.png", "height": 185, "weight": 85, "date_of_birth": "1998-02-07", "gender": "male" } }, //and more!
The squads are one of the most important pieces of data you need to gather to build a fantasy game. Eventually, your application users must select their own team with the players participating this season. The fastest and most efficient way to retrieve all the teams and players of one season is to use our teams by season id endpoint.
https://api.sportmonks.com/v3/football/teams/seasons/21646?api_token=YOURTOKEN
This request will return to you all the teams participating this season with their basic team information.
Now, you can also include all the players from the team in this season:
https://api.sportmonks.com/v3/football/teams/seasons/21646?api_token=YOURTOKEN&include=players
It might be good to use a nested include as well to get extra player information in the response:
https://api.sportmonks.com/v3/football/teams/seasons/21646?api_token=YOURTOKEN&include=players.player
Now you can show your users all the players participating in the season. With this information, you can give the users an overview of the active players, after which they can select their own team.
{ "id": 4298087856, "sport_id": 1, "fixture_id": 18841624, "player_id": 30062, "team_id": 8, "position_id": 26, "formation_field": "3:3", "type_id": 11, "formation_position": 8, "player_name": "Cody Gakpo", "jersey_number": 18, "details": [ { "id": 405028911, "fixture_id": 18841624, "player_id": 30062, "team_id": 8, "lineup_id": 4298087856, "type_id": 117, "data": { "value": 1 }, "type": { "id": 117, "name": "Key Passes", "code": "key-passes", "developer_name": "KEY_PASSES", "model_type": "statistic", "stat_group": "overall" } }, //and more!
Player season and match statistics are essential in fantasy games by providing crucial insights into a player’s performance. Player statistics like goals, assists, tackles, match ratings, passes, and more aid fantasy league managers in making informed decisions.
These statistics enable strategic player selection, trade, and removal, ensuring a team that closely aligns with real-life capabilities. Regular updates based on match outcomes contribute to the game’s dynamic nature, influencing team management. The statistics are helpful for your application users to select their team, but they also play a vital role in distributing a point system. More on that later in this blog.
Now you have all the teams and players; you can access the player’s statistics. Thanks to the flexibility of our football API, there are multiple ways to access player statistics.
For example, you can use the squad by team and season ID endpoint for season statistics. For match statistics, you can look at specific matches. Check out our player statistics tutorial for more information.
{ "data": { "id": 154421, "sport_id": 1, "country_id": 1578, "nationality_id": 1578, "city_id": null, "position_id": 27, "detailed_position_id": 151, "type_id": 27, "common_name": "E. Haaland", "firstname": "Erling Braut", "lastname": "Haaland", "name": "Erling Håland", "display_name": "Erling Haaland", "image_path": "https://cdn.sportmonks.com/images/soccer/players/21/154421.png", "height": 195, "weight": 87, "date_of_birth": "2000-07-21", "gender": "male", "statistics": [ { "id": 17770973, "player_id": 154421, "team_id": 9, "season_id": 19734, "has_values": true, "position_id": 27, "jersey_number": 9, "details": [ { "id": 25429349, "player_statistic_id": 17770973, "type_id": 41, "value": { "total": 23 } }, { "id": 20163794, "player_statistic_id": 17770973, "type_id": 118, "value": { "average": 7.53, "highest": 10.2, "lowest": 6.02 } }, //and more!
Now the essential part of a fantasy game: selecting the players. The user can select their own team (i.e. 11 players + 4 on the bench) based on the rules you decide for yourself. Some of the most used key principles:
Set a max of X players on the same team
Naturally, you must limit the number of players from the same club. You want to avoid users choosing the whole squad of Manchester City, as they will probably score many points with that team. The game needs to be challenging and fun at the same time. Therefore, most fantasy games have a rule of max two players from the same team. Of course, you can determine your own guidelines.
Value the players
Each player has his own value (€). You need to determine this value yourself, which you can do by using our data. For example, you can look at the player transfer history, but the better option is to look at the player rating of the previous season. E.g. the player rating and stats of Haaland (id: 154421) for the 2022/2023 Premier League season (id: 16264)
Now you know that he had a rating of 7.53 in the previous season. That’s pretty high. Therefore, he is more valuable (€) than, for instance, a player with an average rating of 5.65. Get the idea?
Determine starting budget
As discussed, some players represent a different value than other players. You must set a budget to avoid users choosing the best players possible. Within this budget, they can select their team. Players will be restricted by their budget and will have to spend it wisely on a decent team.
{ "data": { "id": 21646, "sport_id": 1, "league_id": 8, "tie_breaker_rule_id": 171, "name": "2023/2024", "finished": false, "pending": false, "is_current": true, "starting_at": "2023-08-11", "ending_at": "2024-05-19", "standings_recalculated_at": "2023-08-16 00:05:33", "games_in_current_week": true, "fixtures": [ { "id": 18841616, "sport_id": 1, "league_id": 8, "season_id": 21646, "stage_id": 77464011, "group_id": null, "aggregate_id": null, "round_id": 307065, "state_id": 5, "venue_id": 200, "name": "Burnley vs Manchester City", "starting_at": "2023-08-11 19:00:00", "result_info": "Manchester City won after full-time.", "leg": "1/1", "details": null, "length": 90, "placeholder": false, "has_odds": true, "starting_at_timestamp": 1691780400 }, //and more!
Your application users have assembled their dream team. Now it’s time for them to select their starting 11. They will need to know which teams are playing against each other to make their selection..
You can use one of our convenient schedule endpoints, or the Season by id endpoint with the fixtures include:
https://api.sportmonks.com/v3/football/seasons/21646?api_token=YOURTOKEN&include=fixtures
Now, they can determine which players will earn the most points for the upcoming playing round. But how can you assign fantasy points to the players?
Like with the player selection, you can decide what kind of fantasy point system you will apply. Some of the most used key principles are:
Points based on starting eleven
The first and most used method is assigning points to the players in the starting eleven. You can see this as a sort of starting bonus. Players who start the game will get an ‘X’ of basic points. This also encourages users to watch the injured/suspended players and the predicted line-up.
You can request the starting eleven with the lineups include on our livescores and fixtures endpoints.
Points based on minutes played
Of course, every player that starts the game deserves some starting points. But what if a player is injured or gets a red card in the first few minutes? Logically speaking, players who do not play the full match receive fewer points. You can see how many minutes a player has played in each player’s stats. You can use the lineups include for this.
Win points based on stats
Also available in the lineups include are the statistics. Players who have scored or assisted a goal earn more fantasy points than players who didn’t. It’s good to take the position of a player into consideration as well: a defender who scores or assists a goal deserves more points than a striker, don’t you think?
Lose points based on stats
A player not only earns points but is also able to lose them. What if they conceded many goals, received a yellow or even a red card? These are all things you need to take into consideration and can be found in the lineups include.
We hope this has given you some inspiration for your own fantasy game. Please do not hesitate to contact our support team with any questions.
Interested in advanced player statistics for the top-tier leagues like the English Premier League, La Liga, Bundesliga, Champions League, Ligue 1 and more? Discover our football API.
Football API