Skip to content

Guides

How do I backtest NFL closing lines in Python?

Every regular-season game with its score and the closing spread, total and moneylines on the same row, so a cover or over rate is one line of pandas.

Code verified October 10, 2026. One call to get_games, 5 credits.

The call

result is home score minus away score. spread_line is positive when the home team was favored.

import requests
import pandas as pd

API_KEY = "YOUR_API_KEY"

resp = requests.post(
    "https://mcp.endzoneapi.com/v1/get_games",
    headers={"x-api-key": API_KEY},
    json={
        "season": 2025,
        "game_type": "REG",
        "limit": 300,
    },
    timeout=60,
)
resp.raise_for_status()
data = resp.json()["data"]

games = pd.DataFrame(data["games"])
games = games[games["status"] == "FINAL"].copy()
games["home_cover"] = games["result"] > games["spread_line"]
games["push"] = games["result"] == games["spread_line"]
games["over"] = games["total"] > games["total_line"]
print(len(games), "games")
print("home covered:", round(games["home_cover"].mean(), 3))
print("over:", round(games["over"].mean(), 3))
favorite_home = games["spread_line"] > 0
print("home favorites covered:", round(games.loc[favorite_home, "home_cover"].mean(), 3))

Replace YOUR_API_KEY with a key from your dashboard. Python needs requests and pandas (pip install requests pandas). JavaScript runs on Node 18 or newer, or in the browser.

What comes back

The data object of the response, trimmed to the first rows. Every field is real output from the run above.

{
  "games": [
    {
      "game_id": "2025_18_BAL_PIT",
      "week": 18,
      "away_team": "BAL",
      "home_team": "PIT",
      "away_score": 24,
      "home_score": 26,
      "result": 2,
      "total": 50,
      "spread_line": -4.5,
      "total_line": 41.5,
      "away_moneyline": -225,
      "home_moneyline": 185
    },
    {
      "game_id": "2025_18_NYJ_BUF",
      "week": 18,
      "away_team": "NYJ",
      "home_team": "BUF",
      "away_score": 8,
      "home_score": 35,
      "result": 27,
      "total": 43,
      "spread_line": 12.5,
      "total_line": 39.5,
      "away_moneyline": 550,
      "home_moneyline": -800
    },
    "...270 more"
  ],
  "count": 272
}

What to do next

  • get_odds (10 credits). Each sportsbook's opening and closing line for one game, instead of the single closing line on the game row.
  • get_alt_lines (10 credits). The full ladder of alternate spreads and totals, if your rule needs a price at another number.

More guides

Start with 500 free credits

No card. REST or MCP.