Analytics Dashboard for ESPN Fantasy Betting
BetKeeper is a Python-based analytics tool that fetches your ESPN fantasy pick'em picks and runs simluations as if you had placed a bet on those picks with different bandkroll strategies. Includes comprehensive visualizations and insights to help you understand your hyopthetical performance and optimize your strategy.
Main dashboard showing overall statistics and bankroll strategy comparison
Performance by betting line and key insights
Strategy performance over time and weekly breakdown
Risk versus reward analysis across all strategies
- Overall Performance Metrics: Win rate, ROI, total profit and loss, and record tracking
- Weekly Breakdown: Track performance week-by-week throughout the season
- Betting Line Analysis: Performance across different odds categories (heavy favorites, favorites, slight underdogs, big underdogs)
- Streak Tracking: Monitor winning and losing streaks over time
Compare 8 different betting strategies using your actual picks:
- Flat Betting: Consistent $100 bets every time
- Fixed Percentage: 5% of current bankroll
- Conservative Percentage: 1% of current bankroll
- Kelly Criterion: Mathematically optimal bet sizing
- Martingale: Double bet after each loss
- Anti-Martingale: Double bet after each win
- Unit-Based: Adjust units based on betting line category
- Confidence-Based: ROI-weighted bet sizing
- Strategy performance over time (line charts)
- Weekly profit and loss breakdown (bar charts)
- Cumulative profit tracking
- Risk versus reward scatter plot
- Performance by betting line category
- Python 3.7 or higher
- pip package manager
- Clone the repository:
git clone https://github.com/yourusername/betkeeper.git
cd betkeeper- Install required dependencies:
pip install requests-
Obtain your ESPN credentials:
- Go to https://www.espn.com/fantasy/
- Sign in to your account
- Press F12 to open Developer Tools
- Click on the Application tab
- In the sidebar, expand Cookies and click on https://www.espn.com
- Copy the values for:
SWID(include the curly brackets)espn_s2ESPN-ONESITE.WEB-PROD.token
-
Update credentials in
betkeeper.py:
SWID = "YOUR_SWID_HERE"
ESPN_S2 = "YOUR_ESPN_S2_HERE"
ONESITE_TOKEN = "YOUR_TOKEN_HERE"Alternatively, you can leave these blank and the script will prompt you for credentials when you run it.
Run the script to fetch data and launch the dashboard:
python betkeeper.pyThis will:
- Fetch your betting data from ESPN (or use cached data if available)
- Calculate comprehensive statistics
- Export results to
stats_output.json - Launch a local web server
- Open the dashboard in your default browser at
http://localhost:8000/dashboard.html
To force a fresh fetch of data from ESPN (for example, after new weeks have completed):
python betkeeper.py --refetchIf you have already generated stats_output.json, you can view the dashboard without re-running the analysis:
python -m http.server 8000Then navigate to http://localhost:8000/dashboard.html in your browser.
betkeeper/
├── betkeeper.py # Main Python script
├── dashboard.html # Interactive dashboard frontend
├── stats_output.json # Generated statistics (created on first run)
├── member_data.json # Cached member data (created on first run)
├── all_weeks_data.json # Cached weekly data (created on first run)
├── images/ # Screenshot images for documentation
│ ├── dashboard_1.png
│ ├── dashboard_2.png
│ ├── dashboard_3.png
│ └── dashboard_4.png
└── README.md # This file
Contains all calculated statistics including:
- Overall performance metrics
- Weekly breakdown
- Performance by betting line range
- Streak statistics
- Bankroll strategy simulations
member_data.json: Your ESPN member picks dataall_weeks_data.json: All completed weeks game data
These files allow faster subsequent runs without re-fetching from ESPN.
Key metrics displayed at the top:
- Total picks made
- Win rate percentage
- Net profit or loss
- ROI (Return on Investment)
- Average win and biggest win
- Longest win streak
- Win-loss record
Visual comparison of how different betting strategies would have performed with your actual picks. Shows final bankroll, ROI, and maximum drawdown for each strategy.
Breakdown of your performance across different odds categories:
- Heavy Favorites (≤ -200)
- Favorites (-199 to -110)
- Slight Underdogs (+110 to +199)
- Big Underdogs (≥ +200)
Automated insights based on your performance:
- Recommended strategy based on best ROI
- Strategies to avoid
- Your edge (best performing betting line category)
- Win rate analysis
- Unit analysis
- Strategy Performance Over Time: Line chart showing bankroll progression for each strategy
- Weekly Performance: Bar chart of profit and loss by week
- Cumulative Profit: Running total of profit over time
- Risk vs Reward: Scatter plot comparing ROI against maximum drawdown
BetKeeper fetches data from the ESPN Gambit API endpoints:
- Member picks:
https://gambit-api.fantasy.espn.com/apis/v1/challenges/265/members/ - Weekly data:
https://gambit-api.fantasy.espn.com/apis/v1/challenges/265/
Uses cookie-based authentication with three required values:
- SWID (Session Web ID)
- espn_s2 (Session token)
- ESPN-ONESITE.WEB-PROD.token (OAuth token)
if betting_line < 0:
profit = bet_amount * (100 / abs(betting_line))
else:
profit = bet_amount * (betting_line / 100)ROI = (total_profit / total_amount_wagered) * 100kelly_fraction = ((decimal_odds - 1) * win_rate - (1 - win_rate)) / (decimal_odds - 1)
# Uses half-Kelly for safety, clamped between 0 and 0.25- Ensure you are signed into ESPN Fantasy
- Verify you copied the complete cookie values
- Make sure SWID includes the curly brackets
- Credentials may expire; try getting fresh ones
- Ensure you have made picks in ESPN Fantasy
- Run with
--refetchflag to force fresh data - Check that you are using the correct challenge ID (265 by default)
- Verify
stats_output.jsonexists in the same directory asdashboard.html - Check browser console for JavaScript errors
- Ensure the JSON file is valid and not corrupted
If port 8000 is already in use, you can specify a different port:
# Modify the PORT variable in betkeeper.py
PORT = 8001 # or any available portModify the bet_amount parameter in the analysis functions:
stats = analyze_picks(member, all_weeks, bet_amount=100)Edit the simulate_bankroll_strategies function to modify:
- Starting bankroll (default: $1,000)
- Strategy parameters (percentages, multipliers, etc.)
- Add custom strategies
The dashboard uses CSS variables for easy color customization. Edit dashboard.html:
:root {
--primary-blue: #0c457d;
--light-blue: #3498db;
--orange: #e8702a;
--cream: #faedca;
}Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Follow PEP 8 style guidelines for Python code
- Add comments for complex logic
- Update documentation for new features
- Test with various data scenarios
This project is licensed under the MIT License. See the LICENSE file for details.
This tool is for educational and analytical purposes only. It is not affiliated with or endorsed by ESPN. Use of this tool must comply with ESPN's Terms of Service. Gambling should be done responsibly and legally in accordance with local laws and regulations.
- ESPN for providing the Gambit API
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review the troubleshooting section
- Initial release
- Basic statistics and dashboard
- 8 bankroll strategies
- Weekly and line range analysis
- Interactive charts and visualizations