Sports Data Fetcher is a command-line tool that retrieves historical odds time series data for sports events from the Polymarket API.
The tool allows you to filter events by a custom keyword to be searched in the slug (for example, "nba-", "nfl-", etc.), specify a time window around each event (by providing the number of days before and after the event date), and save the resulting data as CSV files in an organized folder structure.
-
Keyword-based Filtering: Search for events by specifying a keyword that appears in the market slug.
-
Time Window Selection: Define the number of days before and after each event to include in the data window.
-
Flexible Data Retrieval: Retrieve data for a full month, a full year, or a custom date range.
-
CSV Export: Save each event’s historical odds data as CSV files.
-
polymarket_fetcher.py: Implements the low-level API fetching logic.
-
sports_fetcher.py: Implements the SportsFetcher class that provides high-level methods for filtering and retrieving event data.
-
fetch_data.py: Provides a command-line interface for fetching and saving the sports events data.
To install these requirements, run:
pip install -r requirements.txt
Command-Line Options
--keyword: (Required) The keyword to filter market slugs (e.g., "nba-", "nfl-", "soccer-").
--days-before: Number of days before the event to include in the data window (default: 0.5).
--days-after: Number of days after the event to include in the data window (default: 1.5).
--fidelity: Data granularity (default: 2 for 2‑minute intervals).
--mode: Data retrieval mode. Choose one of:
month — Fetch data for a full month (requires --month).
year — Fetch data for a full year.
range — Fetch data for a custom date range (requires --start-date and --end-date).
--year: Year for data retrieval (default: 2024).
--month: Month for data retrieval (required if mode is month).
--start-date: Start date for a custom range (ISO format, e.g., "2024-12-01T00:00:00Z").
--end-date: End date for a custom range (ISO format, e.g., "2024-12-31T23:59:59Z").
--output: Output folder to save CSV files (default: games_data).
USAGE:
python3 fetch_data.py --keyword "nba-" --mode month --year 2024 --month 12 --output SportsData
python3 fetch_data.py --keyword "nfl-" --mode year --year 2024 --output SportsData
python3 fetch_data.py --keyword "nba-" --mode range --start-date "2024-06-01T00:00:00Z" --end-date "2024-06-30T23:59:59Z" --output SportsData