STAT-API
← DFS Cookbook

Re-select SIM portfolios in <50ms via cached pool_id

Every SIM build caches its simulated draw matrix under `sim.versions.pool_id`. Passing `pool_id` back to `/sim/lineups` re-selects portfolios and computes the EV vs. diversity Pareto frontier in milliseconds without re-simulating games.

What it is
Executes an initial contest SIM on slate `1126128`, captures `sim.versions.pool_id`, and re-selects lineups instantaneously with `diversity_weight: 0.35` and `include_diversity_frontier: true`.
When to use it
Use this when sweeping exposure limits, unique-player rules, or diversity trade-offs interactively without re-running costly game simulations.
What you get back
Total vs active pool size, baseline vs reselected portfolio EV and diversity, and all Pareto frontier points.

1.Build baseline SIM candidate pool

Simulate slate `1126128` (`contest_id: 91632452`) once with `diversity_weight: 0.15` to populate the cached simulation matrix and emit `sim.versions.pool_id`.

POST request (requires your API key in STAT_API_KEY). Run the SDK program on the right or the curl snippet below.

{
  "contest_id": 91632452,
  "lineup_count": 5,
  "sim_game_runs": 200,
  "sim_seed": 42,
  "diversity_weight": 0.15,
  "max_player_exposure_pct": 60,
  "response_format": "json"
}
const baselinePool = await api.dfs.slates.simLineups(1126128, { contest_id: 91632452, lineup_count: 5, sim_game_runs: 200, sim_seed: 42, diversity_weight: 0.15, max_player_exposure_pct: 60 }, { wait: true })

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

// Build baseline SIM candidate pool
const baselinePool = await api.dfs.slates.simLineups(1126128, { contest_id: 91632452, lineup_count: 5, sim_game_runs: 200, sim_seed: 42, diversity_weight: 0.15, max_player_exposure_pct: 60 }, { wait: true })

// Re-select portfolio from cached pool_id + Pareto frontier
const reselectedPoolId = baselinePool.sim.versions.pool_id
if (!reselectedPoolId) throw new Error('missing sim.versions.pool_id')
const reselected = await api.dfs.slates.simSelectPool(1126128, { pool_id: reselectedPoolId, lineup_count: 5, diversity_weight: 0.35, min_unique_players: 2, max_player_exposure_pct: 60, include_diversity_frontier: true })

// Print baseline vs reselected comparison and frontier
const frontier = reselected.frontier ?? []
console.log(`Pool total_pool=${reselected.diagnostics.total_pool_lineups} active=${reselected.diagnostics.active_pool_lineups}`)
console.log(`Baseline lineups=${baselinePool.portfolio.lineup_count} ev=${baselinePool.portfolio.payout.ev_dollars.toFixed(2)} diversity=${baselinePool.portfolio.diversity.composite_diversity_score.toFixed(2)}`)
console.log(`Reselected lineups=${reselected.portfolio.lineup_count} ev=${reselected.portfolio.payout.ev_dollars.toFixed(2)} diversity=${reselected.portfolio.diversity.composite_diversity_score.toFixed(2)} frontier=${frontier.length}`)
for (const fp of frontier.slice(0, 4)) {
  console.log(`Frontier weight=${fp.diversity_weight.toFixed(2)} | ev=${fp.ev_dollars.toFixed(2)} roi_pct=${fp.roi_pct.toFixed(2)} diversity=${fp.composite_diversity_score.toFixed(2)}`)
}

Verified output across all 4 SDKs

TypeScript, Python, Go, and Java execute cleanly and print byte-identical output:

Pool total_pool=3489 active=3489
Baseline lineups=5 ev=10056.36 diversity=0.70
Reselected lineups=5 ev=229.32 diversity=0.68 frontier=4
Frontier weight=0.00 | ev=199.33 roi_pct=99.33 diversity=0.65
Frontier weight=0.25 | ev=229.32 roi_pct=129.32 diversity=0.68
Frontier weight=0.50 | ev=229.32 roi_pct=129.32 diversity=0.68
Frontier weight=0.75 | ev=224.42 roi_pct=124.42 diversity=0.70