import requests
from datetime import datetime, timezone
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://therundown.io/api/v2"
EVENT_ID = "abc123"
AFFILIATE_IDS = ["19", "23"] # DraftKings, FanDuel
BOOKS = {"19": "DraftKings", "23": "FanDuel"}
# Fetch spread history for multiple books
response = requests.get(
f"{BASE_URL}/events/{EVENT_ID}/markets/2/history",
params={
"key": API_KEY,
"affiliate_ids": ",".join(AFFILIATE_IDS),
}
)
history = response.json()["history"]
# Group by sportsbook for charting
series = {}
for entry in history:
aff_id = str(entry["affiliate_id"])
book_name = BOOKS.get(aff_id, aff_id)
if book_name not in series:
series[book_name] = {"timestamps": [], "lines": [], "prices": []}
series[book_name]["timestamps"].append(entry["timestamp"])
series[book_name]["lines"].append(entry["line"])
series[book_name]["prices"].append(entry["price"])
# Print chart data
for book, data in series.items():
print(f"\n{book} Spread Movement:")
for ts, line, price in zip(data["timestamps"], data["lines"], data["prices"]):
print(f" {ts}: {line} ({price})")
# To use with matplotlib:
# import matplotlib.pyplot as plt
# import matplotlib.dates as mdates
#
# fig, ax = plt.subplots(figsize=(12, 6))
# for book, data in series.items():
# dates = [datetime.fromisoformat(ts.replace("Z", "+00:00")) for ts in data["timestamps"]]
# ax.step(dates, data["lines"], where="post", label=book)
# ax.set_xlabel("Time")
# ax.set_ylabel("Spread")
# ax.legend()
# ax.invert_yaxis()
# plt.title("Spread Line Movement")
# plt.show()