Betfair Daily Matches is a modular Python application that connects to the Betfair Exchange API to:
- Fetch and display today’s sports markets (Football, Tennis, Cricket, Rugby)
- Query markets for a custom date range
- Filter by market type (e.g., Match Odds, Over/Under)
- Restrict to specific countries
- Show live (in-play) markets
- Search for matches by team/player name
- List today’s competitions per sport
It features:
- An interactive CLI (
main.py) with menu-driven options - A clean package (
betfair_app/) encapsulating config, client, utilities, query logic, and sport modules - Pytest-based test suite under
tests/ - Easy extensibility: add new sports or market filters by creating new modules
Follow the sections below to set up, run, and extend the application.
betfair_daily_matches/
├── main.py
├── requirements.txt
├── README.md
├── betfair_app/
│ ├── __init__.py
│ ├── config.py
│ ├── client.py
│ ├── utils.py
│ ├── query.py
│ └── sports/
│ ├── football.py
│ ├── tennis.py
│ ├── cricket.py
│ └── rugby.py
└── tests/
├── __init__.py
├── test_config.py
├── test_query.py
├── test_sports_football.py
├── test_sports_tennis.py
└── test_utils.py
In the project root (betfair_daily_matches/), run:
python3 -m venv venvActivate the environment:
source venv/bin/activateUpgrade pip and install required packages:
pip install --upgrade pip
pip install -r requirements.txtConfigure your Betfair credentials and SSL certificate directory. Add the following lines to your shell profile (~/.bashrc, ~/.profile, etc.):
export BF_USERNAME="your.betfair.username"
export BF_PASSWORD="yourBetfairPassword"
export BF_APP_KEY="YourAppKeyHere"
export BF_CERT_DIR="/path/to/your/certificates"Reload your shell:
source ~/.bashrcEnsure your certificate directory contains both .crt and .key files and that the key file has secure permissions:
ls $BF_CERT_DIR
chmod 600 $BF_CERT_DIR/*.keyLaunch the interactive command-line interface:
python main.pyYou will see a menu with options:
- All matches today (all sports)
- Football matches today
- Tennis matches today
- Cricket matches today
- Rugby matches today
- Custom date range
- View competitions today
- Search matches by team/player name
- Exit
Enter the number for the desired action and follow the prompts.
When finished, choose Exit from the menu or press Ctrl+C. Then deactivate the virtual environment:
deactivateA test suite using pytest is included under tests/ — 10 tests across 5 files.
| File | Tests | What it covers |
|---|---|---|
test_config.py |
2 | Missing env vars raise ValueError; all vars present returns True |
test_query.py |
2 | list_matches_today with a dummy client; invalid sport raises ValueError |
test_sports_football.py |
1 | get_football_event_type_id() returns "1" |
test_sports_tennis.py |
1 | get_tennis_event_type_id() returns "2" |
test_utils.py |
4 | Date range ISO format, custom offset, valid/invalid time formatting |
# Run all 10 tests (quiet)
pytest --maxfail=1 --disable-warnings -q
# Verbose output
pytest -v
# Run a single test file
pytest tests/test_utils.py -v
# Run a single test by name
pytest tests/test_config.py::test_missing_env -vEnsure all tests pass before deploying or extending the application.
This completes the setup and usage instructions for the Betfair Daily Matches application.