STAT-API
DFS Cookbook

Rank teams for a stack

A team stack is several players from the same offense. dfs.team_stats sums every scoring category over a team's players on one slate, so you can rank offenses directly instead of adding player rows yourself. Each slate game contributes exactly two rows, and each row names its opponent.

What it is
Ranks each team on a slate by the fantasy points its players produced, with the opponent and the home or away side attached.
When to use it
Use it to pick a stack, to measure which offenses repeatedly beat their salary, or to study how an offense performs against a given defense.
What you get back
Two rows per slate game — every scoring category summed for the team, plus the team's real points, yards, and turnovers.

1.Read both sides of every game on the slate

Two rows per game, so a 13-game slate returns 26. The id is derived from the slate game and is unique across leagues, which is why paging works.

const teams = (await api.dfs.team_stats.list({ slate_id: 129036, limit: 100 })).team_stats

The complete program

Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.

import { StatApi } from '@stat-api/client'

const api = new StatApi() // reads STAT_API_KEY from the environment

// Read both sides of every game on the slate
const teams = (await api.dfs.team_stats.list({ slate_id: 129036, limit: 100 })).team_stats

// Keep the teams that played
const played = teams.filter((row) => row.fantasy_pts !== null && row.fantasy_pts !== undefined)

// Rank by fantasy points produced
const best = [...played].sort((a, b) => (b.fantasy_pts ?? 0) - (a.fantasy_pts ?? 0))

// Take the eight best offenses
const top = best.slice(0, 8)

// Print the stack board
console.log("Most productive offenses on the slate")
console.log(["team_id", "opponent_team_id", "is_home", "fantasy_pts", "pts", "total_yds", "player_count"].join('\t'))
for (const row of top) {
  console.log([String(row.team_id ?? ''), String(row.opponent_team_id ?? ''), String(row.is_home ?? ''), String(row.fantasy_pts ?? ''), String(row.pts ?? ''), String(row.total_yds ?? ''), String(row.player_count ?? '')].join('\t'))
}