Examples
Examples you can run
Five short programs on real FanDuel data, each one a working starting point. Set your key in the environment and run them as they are; each makes a handful of requests.
FanDuel API is an independent data service operated by FF API Inc. It is not affiliated with, endorsed by or sponsored by FanDuel.
What is here
- A one-screen odds board: Every NBA points prop with its line, both prices and the fair over, sorted by start time. The base of any odds screen.
- Alert when a prop moves: Follows the change feed and prints every line move on a list of players. Swap print for Slack, email or a webhook of your own.
- Closing line value for your own bets: Give it the prop and the price you took; it reads the prop's history and tells you how the price you took compares with where it closed.
- Lowest-hold markets on a slate: Ranks game markets from the cheapest to bet into, using the hold every market already carries.
- DFS salary against the prop line: Joins today's FanDuel DFS salaries to the points line for the same players, so you can see points per thousand dollars the market expects.
A one-screen odds board
Every NBA points prop with its line, both prices and the fair over, sorted by start time. The base of any odds screen.
import os, time, requests
API = "https://fanduelapi.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['FANDUEL_API_KEY']}"}
get = lambda path, **q: requests.get(f"{API}/{path}", params=q, headers=H, timeout=15).json()
for p in get("props", league="NBA", stat="points", limit=200)["data"]:
o, u = p["over_american"], p["under_american"]
print(f"{p['starts_at'][11:16]} {p['player']:<24} {p['line']:>5} {o:+d} / {u:+d}" if o and u else p["player"])Alert when a prop moves
Follows the change feed and prints every line move on a list of players. Swap print for Slack, email or a webhook of your own.
import os, time, requests
API = "https://fanduelapi.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['FANDUEL_API_KEY']}"}
get = lambda path, **q: requests.get(f"{API}/{path}", params=q, headers=H, timeout=15).json()
WATCH = {"Nikola Jokic", "Luka Doncic"}
cursor = "0"
while True:
page = get("changes", since=cursor, limit=500)
for c in page["data"]:
if c["kind"] == "line_move" and c["player"] in WATCH:
print(c["player"], c["stat"], c["previous"]["line"], "->", c["current"]["line"], c["at"])
cursor = page["meta"]["next_cursor"]
time.sleep(15)Closing line value for your own bets
Give it the prop and the price you took; it reads the prop's history and tells you how the price you took compares with where it closed.
import os, time, requests
API = "https://fanduelapi.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['FANDUEL_API_KEY']}"}
get = lambda path, **q: requests.get(f"{API}/{path}", params=q, headers=H, timeout=15).json()
def implied(a): return 100 / (a + 100) if a > 0 else -a / (-a + 100)
def clv(prop_id, taken_american):
h = get(f"props/{prop_id}/history")["data"]["history"]
close = [x for x in h if x["over_american"] is not None][-1]
return round(implied(close["over_american"]) - implied(taken_american), 4) # positive: you beat the close
print(clv("<prop id>", -110))Lowest-hold markets on a slate
Ranks game markets from the cheapest to bet into, using the hold every market already carries.
import os, time, requests
API = "https://fanduelapi.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['FANDUEL_API_KEY']}"}
get = lambda path, **q: requests.get(f"{API}/{path}", params=q, headers=H, timeout=15).json()
markets = get("markets", league="NBA", limit=200)["data"]
for m in sorted((m for m in markets if m["hold"] is not None), key=lambda m: m["hold"])[:10]:
print(f"{m['hold']:.2%} {m['event_name']:<36} {m['name']}")DFS salary against the prop line
Joins today's FanDuel DFS salaries to the points line for the same players, so you can see points per thousand dollars the market expects.
import os, time, requests
API = "https://fanduelapi.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['FANDUEL_API_KEY']}"}
get = lambda path, **q: requests.get(f"{API}/{path}", params=q, headers=H, timeout=15).json()
slate = get("dfs/slates", sport="NBA", started="false")["data"][0]
salaries = {p["name"]: p["salary"] for p in get(f"dfs/slates/{slate['id']}/players", limit=500)["data"]}
for p in get("props", league="NBA", stat="points", limit=200)["data"]:
if p["player"] in salaries and p["line"]:
print(f"{p['player']:<24} {salaries[p['player']]:>6} {p['line']:>5} {1000 * p['line'] / salaries[p['player']]:.2f} pts per $1k")Next
The same calls in JavaScript are in the JavaScript guide; field names for every endpoint are in the docs.
Related
Make your first call in a few minutes
Sign up, create a key in the dashboard, and send it as a Bearer token. The free plan needs no card and reads the same data five minutes behind.
Get a free API key