Queue an async 202 SIM job and poll until completion
For large workloads or non-blocking orchestrators, send `Prefer: respond-async` via `simLineupsStart` to receive an immediate HTTP `202` handle, then poll `simJob` until completion.
- What it is
- Queues a contest SIM run with `simLineupsStart` (`Prefer: respond-async` returning HTTP 202 + `job_id`), then polls `simJob` until `ready` is true.
- When to use it
- Use this for large-draw or high-lineup-count SIM jobs inside web workers, job queues, or clients that avoid holding long HTTP requests open.
- What you get back
- Initial 202 `job_id` and status followed by the completed SIM portfolio EV, ROI%, and top ranked lineups.
1.Submit async SIM job (Prefer: respond-async)
Call `simLineupsStart` on NFL slate `1126128` (`contest_id: 91632452`) to receive an immediate HTTP 202 `SimJobStatusResponse`.
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": 3,
"sim_game_runs": 200,
"sim_seed": 42
}const job = await api.dfs.slates.simLineupsStart(1126128, { contest_id: 91632452, lineup_count: 3, sim_game_runs: 200, sim_seed: 42 })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
// Submit async SIM job (Prefer: respond-async)
const job = await api.dfs.slates.simLineupsStart(1126128, { contest_id: 91632452, lineup_count: 3, sim_game_runs: 200, sim_seed: 42 })
// Poll job handle until ready
let completedPoll = await api.dfs.slates.simJob(1126128, job.job_id)
for (let i = 0; i < 60 && !completedPoll.ready; i++) {
await new Promise((r) => setTimeout(r, 1000))
completedPoll = await api.dfs.slates.simJob(1126128, job.job_id)
}
if (!completedPoll.ready || !completedPoll.result) throw new Error('SIM job did not complete in time')
const completed = completedPoll.result
// Print initial job status and completed SIM lineups
console.log(`Job ${job.job_id} | initial_status=${job.status}`)
console.log(`Completed slate=${completed.slate.id} lineups=${completed.portfolio.lineup_count} ev=${completed.portfolio.payout.ev_dollars.toFixed(2)} roi_pct=${completed.portfolio.payout.roi_pct.toFixed(2)}`)
for (const l of completed.lineups.slice(0, 3)) {
console.log(`AsyncLineup #${l.rank} | salary=${l.salary} proj=${l.projected_points.toFixed(2)} ev=${l.payout.ev_dollars.toFixed(2)} roi_pct=${l.payout.roi_pct.toFixed(2)}`)
}Verified output across all 4 SDKs
TypeScript, Python, Go, and Java execute cleanly and print byte-identical output:
Job simjob_<job_id> | initial_status=queued
Completed slate=1126128 lineups=3 ev=52.02 roi_pct=-13.29
AsyncLineup #1 | salary=49800 proj=155.95 ev=24.42 roi_pct=22.12
AsyncLineup #2 | salary=49600 proj=141.64 ev=8.30 roi_pct=-58.50
AsyncLineup #3 | salary=49800 proj=152.16 ev=19.30 roi_pct=-3.50