This is an incredibly powerful tool that can automate lineup building, allowing you to enter thousands of lineups in any DK contest in the time it takes you to grab a coffee. Works for NFL, NBA, WNBA and MLB on either DraftKings or FanDuel.
This project allows you to create an unlimited amount of optimized DraftKings lineups based on any projection source of your choice. You can use this repo as a command line application, or import functionality as needed to build your own scripts to construct thousands of DraftKings lineups each week and upload them in seconds using their CSV upload tool. Examples of how to do the latter are provided in the examples
directory.
Special thanks to swanson, who authored this repo, which mine is heavily based off of.
Pre-reqs:
- Python 3
pip install -r requirements.txt
To run, download your desired week's salaries on DraftKings, and then run:
bash scripts/prepare_nfl_contest_data.sh
Note that this script will error out if the CSV from DraftKings is not in ~/Downloads
.
To run the optimizer, you must provide a projection CSV with playername
and points
fields. Run the optimizer with your projection file:
python optimize.py -mp 100 -projection_file "./data/my_projections.csv"
Switching to FanDuel is simple - just change the salaries_file
and game
flags.
python optimize.py -mp 100 -game fanduel -projection_file "./data/my_projections.csv" -salaries_file "./data/fanduel_salaries.csv"
Note that the default file location for the projection file is ./data/current-projections.csv
, so if you have the file in the default location with the correct name, there's no need to pass the projection_file
flag. The same is true with ./data/current-salaries.csv
and salaries_file
.
Force a QB/WR or QB/TE combination from a particular team:
python optimize.py -mp 100 python optimize.py -mp 500 -force_combo y -locked "Russell Wilson"
Limit same team representation except for QB / skill player combos. Example:
python optimize.py -mp 100 -limit y
Run the optimizer multiple times and continually eliminate pre-optimized players from the lineup. For instance, to run three different iterations and generate three different sets of players:
python optimize.py -i 3
At any time, you can get a list of all possible options via:
python optimize.py --help
DraftKings allows uploading up to 500 lineups using a single CSV file. You can learn more about DraftKings' support for lineup uploads here. This tool supports generating an uploadable CSV file containing the generated optimized lineups.
To use this feature:
- Download the weekly salaries CSV from DraftKings (containing player name, DK-estimated points, salary, etc).
- Run
bash scripts/prepare_<nba/nfl>_contest_data.sh
. - Download the CSV upload template and get the file location (probably something like
~/Downloads/DKSalaries.csv
). Note - this file has the same name as the weekly salaries CSV when downloaded from DraftKings, which can be confusing. - Run
python optimize.py -pids <upload_tpl_location>
. Remember to specify league, constraints, number of iterations to run, etc. - Upload the newly generated file to DraftKings from
data/current-upload.csv
.
One nice workflow is to run the optimizer with the -keep_pids
flag after you create your CSV; this option will put future optimizations in the same CSV file.
python optimize.py -l NBA
python optimize.py -l WNBA
python optimize.py -l MLB