Every NBA model needs the same thing before the first line of modelling: a table with one row per game, the closing spread, the closing total, the moneyline and the final score. Copying that out of odds archives by hand is slow, and the lines you get are often not the close. This post pulls it from the Odds-API.io historical endpoints, for a whole season, in 11 requests, and ends with two checks that tell you whether your dataset is sane.
The code uses pandas and the official Python SDK. Everything here is a real endpoint and real parameter; nothing is mocked. The numbers at the end are from a run on 26 November 2026.
What you need
- Python 3.9+,
pip install odds-api-io pandas - A key on a paid plan with
ODDS_API_KEYset. - Bookmakers selected on your key. Below I use
DraftKings,FanDuel,BetMGM,CaesarsandBet365. Names must match/v3/bookmakersexactly. The API covers 500+ bookmakers across 37 sports, and your plan sets how many you can select. - NBA closing odds in the archive start on 9 December 2025, so 2025-26 is the first season, from mid-December through the Finals. Results go further back. The NBA historical odds page has the current counts, and the historical odds API overview covers the other leagues.
One request per 100 games
/v3/historical/closing-lines returns settled games for a sport, up to 10 leagues, a date range of up to 366 days, the markets you ask for and up to 30 bookmakers, 100 games per page. The SDK's iter_closing_lines handles the paging.
import os
import pandas as pd
from odds_api import OddsAPIClient
client = OddsAPIClient(api_key=os.environ["ODDS_API_KEY"])
BOOKS = ["DraftKings", "FanDuel", "BetMGM", "Caesars", "Bet365"]
games = list(client.iter_closing_lines(
sport="basketball",
leagues="usa-nba",
from_="2025-12-01T00:00:00Z",
to="2026-06-30T00:00:00Z",
markets=["ML", "Spread", "Totals"],
bookmakers=BOOKS,
))
print(len(games))That printed 1022 on my run: every settled game from 1 December 2025 to the last game of the 2026 Finals on 9 June, playoffs included, in 11 requests. A full season from opening night is about 1,300 games, so 14 requests. Each game comes back like this (trimmed):
{
"id": 69901234,
"home": "Denver Nuggets",
"away": "Los Angeles Lakers",
"date": "2026-01-15T02:00:00Z",
"status": "settled",
"scores": {"home": 118, "away": 109, "periods": [{"p1": {...}}, ...]},
"bookmakers": {
"DraftKings": [
{"name": "ML", "updatedAt": "2026-01-15T01:58:40Z", "odds": [{"home": "1.45", "away": "2.80"}]},
{"name": "Spread", "odds": [{"hdp": -6.5, "home": "1.91", "away": "1.91"}, {"hdp": -7.0, "home": "1.95", "away": "1.87"}]},
{"name": "Totals", "odds": [{"hdp": 229.5, "over": "1.91", "under": "1.91"}]}
]
}
}Games where none of your books had a price still appear, with an empty bookmakers object. On my run that was 62 of the 1,022 games, and the priced games start on 9 December, where the closing archive begins. Keep them; they tell you about coverage.
Picking the closing line
Books close with several spread lines (the main line and alternates). The main one is the line where the two prices are closest to each other. Prices are decimal strings, and a side a book did not offer comes back as None or "N/A" (8 of those in the whole season), so parse through one helper. For a given game and book:
def price(v):
try:
return float(v)
except (TypeError, ValueError):
return None
def main_line(odds, a, b):
priced = [o for o in odds if price(o.get(a)) and price(o.get(b)) and "hdp" in o]
if not priced:
return None
return min(priced, key=lambda o: abs(price(o[a]) - price(o[b])))
def consensus(game, market, a, b):
"""Median closing line across books, and the mean price on each side at that line."""
picks = []
for bk in BOOKS:
m = next((m for m in game["bookmakers"].get(bk, []) if m["name"] == market), None)
if m:
o = main_line(m["odds"], a, b)
if o:
picks.append((o["hdp"], price(o[a]), price(o[b])))
if not picks:
return None, None, None, 0
line = pd.Series([p[0] for p in picks]).median()
at = [p for p in picks if p[0] == line] or picks
return line, sum(p[1] for p in at) / len(at), sum(p[2] for p in at) / len(at), len(picks)Using a median across five books instead of one book avoids a lot of noise from a single late move at one shop.
The dataframe
def ml(game):
ps = []
for bk in BOOKS:
m = next((m for m in game["bookmakers"].get(bk, []) if m["name"] == "ML"), None)
if m and m["odds"]:
h, a = price(m["odds"][0].get("home")), price(m["odds"][0].get("away"))
if h and a:
ps.append((h, a))
if not ps:
return None, None
return sum(p[0] for p in ps) / len(ps), sum(p[1] for p in ps) / len(ps)
rows = []
for g in games:
sp, sp_home, sp_away, n_sp = consensus(g, "Spread", "home", "away")
tot, over, under, n_tot = consensus(g, "Totals", "over", "under")
ml_home, ml_away = ml(g)
s = g.get("scores") or {}
rows.append({
"date": g["date"][:10], "home": g["home"], "away": g["away"],
"home_pts": s.get("home"), "away_pts": s.get("away"),
"spread": sp, "spread_home_price": sp_home, "spread_away_price": sp_away,
"total": tot, "over_price": over, "under_price": under,
"ml_home": ml_home, "ml_away": ml_away, "books": n_sp,
})
df = pd.DataFrame(rows).dropna(subset=["home_pts", "spread", "total"])
df["margin"] = df["home_pts"] - df["away_pts"]
df["home_covered"] = df["margin"] + df["spread"] > 0
df["push"] = df["margin"] + df["spread"] == 0
df["went_over"] = df["home_pts"] + df["away_pts"] > df["total"]
df.to_csv("nba_2025_26_closing.csv", index=False)
print(df.shape, df["books"].describe())spread is the home team's handicap in the usual convention (a negative number means the home team is the favourite). That is why margin + spread > 0 is a home cover.
The run left 960 games with a closing spread, total and score. The books column is how many of the five books had a closing spread: three of the five through February, all five from March on. Not every book is in the archive for every game, which is another reason to take a median across books instead of trusting one shop.
Two sanity checks before you model anything
1. Favourites should cover about half the time. If the closing market is efficient, the home side covers the closing spread close to 50% of the time, pushes aside. If your number is 58%, the line you picked is not the close, or your sign convention is flipped.
played = df[~df["push"]]
print("home covers:", round(played["home_covered"].mean() * 100, 1), "%")
print("overs:", round(played["went_over"].mean() * 100, 1), "%")On the 2025-26 season (960 games from 9 December to the Finals) this gives 52.0% home covers and 49.0% overs, with 2 spread pushes and 6 total pushes. Both are within a season's worth of noise of 50%, which is what you want to see.
2. Moneyline probabilities should be calibrated. Remove the margin from the average moneyline and bucket by implied probability. The home win rate in each bucket should sit on the bucket midpoint.
df["p_home"] = (1 / df["ml_home"]) / (1 / df["ml_home"] + 1 / df["ml_away"])
df["home_won"] = df["margin"] > 0
df["bucket"] = pd.cut(df["p_home"], [0, .3, .4, .5, .6, .7, .8, 1])
print(df.groupby("bucket", observed=True)["home_won"].agg(["mean", "count"]).round(3)) mean count
bucket
(0.0, 0.3] 0.175 137
(0.3, 0.4] 0.362 116
(0.4, 0.5] 0.474 137
(0.5, 0.6] 0.538 145
(0.6, 0.7] 0.648 142
(0.7, 0.8] 0.794 131
(0.8, 1.0] 0.829 152
Every bucket lands within five points of its mean implied probability. The 0.7 to 0.8 bucket is the furthest off (79% wins against 75% implied), and with 131 games in it that is one or two games either way. If a bucket is far off and has more than 50 games in it, look at those games before trusting anything downstream.
Now you have a baseline. Any model that cannot beat p_home from the closing moneyline on out-of-sample games is not a model yet. For how to grade picks against the close with closing line value, the Python backtest post covers the same workflow for football.
Adding quarters, team totals and props
The closing-lines endpoint returns any market the books carried, so markets=["Totals 1Q", "Team Total Home", "Team Total Away"] works the same way. The basketball market list has the exact names. Player props are the Player Props market and come back with a label for the player name.
Keeping it fresh
Settled games appear in the historical endpoints once the game is graded. A nightly job that re-requests the last two days with the same parameters and upserts on id keeps the CSV current. The 366-day span limit means you need one request range per season, and the skip paging is already handled by the SDK. The current 2026-27 season is in the same endpoint from opening night; change from_ and to and the script above runs unchanged. The NBA odds page shows which bookmakers carry the league today.
Coverage per season and a sample CSV are on the NBA historical odds page. Endpoint reference: historical odds guide. If you want the same table in a spreadsheet, the Google Sheets add-on pulls closing lines with a formula.
The full script
Everything above in one file. Set ODDS_API_KEY, run it, and nba_2025_26_closing.csv lands in the working directory.
import os
import pandas as pd
from odds_api import OddsAPIClient
client = OddsAPIClient(api_key=os.environ["ODDS_API_KEY"])
BOOKS = ["DraftKings", "FanDuel", "BetMGM", "Caesars", "Bet365"]
games = list(client.iter_closing_lines(
sport="basketball",
leagues="usa-nba",
from_="2025-12-01T00:00:00Z",
to="2026-06-30T00:00:00Z",
markets=["ML", "Spread", "Totals"],
bookmakers=BOOKS,
))
print(len(games))
def price(v):
"""Prices are decimal strings; a side a book did not offer comes back as None or "N/A"."""
try:
return float(v)
except (TypeError, ValueError):
return None
def main_line(odds, a, b):
priced = [o for o in odds if price(o.get(a)) and price(o.get(b)) and "hdp" in o]
if not priced:
return None
return min(priced, key=lambda o: abs(price(o[a]) - price(o[b])))
def consensus(game, market, a, b):
"""Median closing line across books, and the mean price on each side at that line."""
picks = []
for bk in BOOKS:
m = next((m for m in game["bookmakers"].get(bk, []) if m["name"] == market), None)
if m:
o = main_line(m["odds"], a, b)
if o:
picks.append((o["hdp"], price(o[a]), price(o[b])))
if not picks:
return None, None, None, 0
line = pd.Series([p[0] for p in picks]).median()
at = [p for p in picks if p[0] == line] or picks
return line, sum(p[1] for p in at) / len(at), sum(p[2] for p in at) / len(at), len(picks)
def ml(game):
ps = []
for bk in BOOKS:
m = next((m for m in game["bookmakers"].get(bk, []) if m["name"] == "ML"), None)
if m and m["odds"]:
h, a = price(m["odds"][0].get("home")), price(m["odds"][0].get("away"))
if h and a:
ps.append((h, a))
if not ps:
return None, None
return sum(p[0] for p in ps) / len(ps), sum(p[1] for p in ps) / len(ps)
rows = []
for g in games:
sp, sp_home, sp_away, n_sp = consensus(g, "Spread", "home", "away")
tot, over, under, n_tot = consensus(g, "Totals", "over", "under")
ml_home, ml_away = ml(g)
s = g.get("scores") or {}
rows.append({
"date": g["date"][:10], "home": g["home"], "away": g["away"],
"home_pts": s.get("home"), "away_pts": s.get("away"),
"spread": sp, "spread_home_price": sp_home, "spread_away_price": sp_away,
"total": tot, "over_price": over, "under_price": under,
"ml_home": ml_home, "ml_away": ml_away, "books": n_sp,
})
raw = pd.DataFrame(rows)
df = raw.dropna(subset=["home_pts", "spread", "total"]).copy()
df["margin"] = df["home_pts"] - df["away_pts"]
df["home_covered"] = df["margin"] + df["spread"] > 0
df["push"] = df["margin"] + df["spread"] == 0
df["went_over"] = df["home_pts"] + df["away_pts"] > df["total"]
df.to_csv("nba_2025_26_closing.csv", index=False)
print(df.shape)
print(df["books"].describe())
played = df[~df["push"]]
print("home covers:", round(played["home_covered"].mean() * 100, 1), "%")
print("overs:", round(played["went_over"].mean() * 100, 1), "%")
df["p_home"] = (1 / df["ml_home"]) / (1 / df["ml_home"] + 1 / df["ml_away"])
df["home_won"] = df["margin"] > 0
df["bucket"] = pd.cut(df["p_home"], [0, .3, .4, .5, .6, .7, .8, 1])
print(df.groupby("bucket", observed=True)["home_won"].agg(["mean", "count"]).round(3))




