Late-swap a DraftKings Contest Entries CSV with live actual points
Send a DraftKings or FanDuel Contest Entries CSV via `entries_csv` paired with `live_actual_points` and `locked_game_ids`. Entries clearing `min_projection_gain` swap unlocked seats cleanly while emitting a ready-to-reupload `patched_upload_csv`.
- What it is
- Evaluates 2 DraftKings Contest Entries CSV rows on slate `1126128`, locks game `43545` with finalized `live_actual_points`, holds entry `1001`, swaps entry `1002` (+15.33 pts), and prints the patched upload CSV.
- When to use it
- Use this when automating full contest-file late swaps directly from exported DraftKings/FanDuel Contest Entries CSV files mid-slate.
- What you get back
- Swapped vs held portfolio totals, per-entry gain metrics, and the 1:1 `patched_upload_csv` preserving Entry ID, Contest Name, Contest ID, and Fee.
1.Run CSV late swap with live actual points and gain threshold
Pass a 2-entry DraftKings CSV preserving Entry IDs `1001` and `1002`, freeze game `43545` with live points, and require at least `+0.5` projection gain.
POST request (requires your API key in STAT_API_KEY). Run the SDK program on the right or the curl snippet below.
{
"entries_csv": "Entry ID,Contest Name,Contest ID,Entry Fee,QB,RB,RB,WR,WR,WR,TE,FLEX,DST\n1001,NFL Classic,55501,$20,44850801,44850924,44850868,44851106,44851102,44851304,44851490,44850860,44851708\n1002,NFL Classic,55501,$20,44850801,44850924,44850868,44851164,44851102,44851304,44851490,44850860,44851708\n",
"as_of": "2025-01-01T00:00:00Z",
"locked_game_ids": [
43545
],
"live_actual_points": {
"44186568": 19.8,
"44186595": 24.4
},
"min_projection_gain": 0.5,
"response_format": "json"
}const csvSwapRes = await api.dfs.slates.optimizerLineups(1126128, { entries_csv: "Entry ID,Contest Name,Contest ID,Entry Fee,QB,RB,RB,WR,WR,WR,TE,FLEX,DST\n1001,NFL Classic,55501,$20,44850801,44850924,44850868,44851106,44851102,44851304,44851490,44850860,44851708\n1002,NFL Classic,55501,$20,44850801,44850924,44850868,44851164,44851102,44851304,44851490,44850860,44851708\n", as_of: "2025-01-01T00:00:00Z", locked_game_ids: [43545], live_actual_points: { "44186568": 19.8, "44186595": 24.4 }, min_projection_gain: 0.5 })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
// Run CSV late swap with live actual points and gain threshold
const csvSwapRes = await api.dfs.slates.optimizerLineups(1126128, { entries_csv: "Entry ID,Contest Name,Contest ID,Entry Fee,QB,RB,RB,WR,WR,WR,TE,FLEX,DST\n1001,NFL Classic,55501,$20,44850801,44850924,44850868,44851106,44851102,44851304,44851490,44850860,44851708\n1002,NFL Classic,55501,$20,44850801,44850924,44850868,44851164,44851102,44851304,44851490,44850860,44851708\n", as_of: "2025-01-01T00:00:00Z", locked_game_ids: [43545], live_actual_points: { "44186568": 19.8, "44186595": 24.4 }, min_projection_gain: 0.5 })
// Print swap decisions and patched upload CSV
const _nz = (v: number) => (Math.abs(v) < 0.005 ? 0 : v)
const swappedCnt = csvSwapRes.portfolio.swapped_count ?? 0
const heldCnt = csvSwapRes.portfolio.held_count ?? 0
const totalGain = _nz(csvSwapRes.portfolio.total_projection_gain ?? 0)
console.log(`Slate ${csvSwapRes.slate.id} | entries=${csvSwapRes.lineups.length} swapped=${swappedCnt} held=${heldCnt} total_gain=${totalGain.toFixed(2)}`)
for (const l of csvSwapRes.lineups) {
const holdPts = l.hold_projected_points ?? l.projected_points
const gainPts = _nz(l.projection_gain ?? 0)
console.log(`Entry ${l.entry_id ?? 'entry'} | action=${l.action ?? ''} salary=${l.salary} hold=${holdPts.toFixed(2)} proj=${l.projected_points.toFixed(2)} gain=${gainPts.toFixed(2)} locked_slots=${(l.locked_slots ?? []).length}`)
}
const patchedLines = (csvSwapRes.patched_upload_csv ?? '').split('\n').map((s) => s.replace(/\r$/, '')).filter((s) => s.length > 0)
console.log(`PatchedCSV lines=${patchedLines.length}`)
for (const line of patchedLines.slice(0, 5)) console.log(line)Verified output across all 4 SDKs
TypeScript, Python, Go, and Java execute cleanly and print byte-identical output:
Slate 1126128 | entries=2 swapped=1 held=1 total_gain=15.33
Entry 1001 | action=held salary=49900 hold=160.67 proj=160.67 gain=0.00 locked_slots=3
Entry 1002 | action=swapped salary=49900 hold=145.34 proj=160.67 gain=15.33 locked_slots=3
PatchedCSV lines=3
Entry ID,Contest Name,Contest ID,Entry Fee,QB,RB,RB,WR,WR,WR,TE,FLEX,DST
1001,NFL Classic,55501,$20,44850801,44850924,44850868,44851106,44851102,44851304,44851490,44850860,44851708
1002,NFL Classic,55501,$20,44850801,44850860,44850868,44851106,44851102,44851304,44851490,44850924,44851708