Collecting Sports Data Using Node and Sportsradar

2 minute read

To kickoff generalizing MFD, I’ll start with the data ingestion piece. As I mentioned in my MFD intro, I want to make MFD more sport-agnostic while maintaining the existing dashboard layout, but at the individual player/team level. To do this, I’ll need a new sports data provider. Yahoo is great when it comes to fantasy sports data, but only a few sports are a fantasy sport on Yahoo.

To gather data across multiple different sports with a single source provider, I decided to go with Sportradar. Sportradar is partnered with many of the top professional leagues around the world, so it seemed fitting to start here. They also provide a trial tier that allows for you to access their API free of charge with certain API limitations in place (1 request/second, 1000 requests/month), and it is a single endpoint for all sports.

As I started to dive deeper into the API (which is well documented I may add), I realized I’ll need to use some sort of wrapper for easier interaction. It wasn’t that it was overly difficult to use the API, but there were no provided SDKs for interacting with this data. With Typescript being my latest coding flavor of the month, and being unable to find one that was updated recently or generic enough for what I am planning to do, I decided to write one myself. For anyone interested in getting this data using Python, there is solid package already created that does just that, which was helpful as I made the node package.

SportradarNode is a simple node package I threw together to interact with the Sportradar API. The package currently supports retreiving NBA (+ draft), NFL (+ draft), and NCAAMB data, with soccer next up on the list. This package is very much still a work in progress, and is the first package I’ve developed + published, but I plan to continue iterating on it during this MFD journey. You can find the package on the npm registry, and below is an example usage:

import * as sra from 'sportradar-node';

const nfl = new sra.Nfl({ apiKey: '' });

const { data } = await nfl.getPostgameStandings('2021', sra.NflSeasonType.REG);

var playoffTeams = [];

const conferences = data.conferences as [any];
conferences.forEach(conf => {
    const divisions = conf.divisions as [any];
    divisions.forEach(div => {
        const teams = div.teams as [any];
        teams.forEach(team => {
            if (team.rank.clinched != 'eliminated') {
                playoffTeams.push(team.name);
            }
        });
    });
});

console.log(playoffTeams);