Skip to content

Fetch Draft Kings data and optimize lineups

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

gacolitti/draft.kings

Repository files navigation

draft.kings

experimental

Overview

draft.kings makes it easy to pull data from DraftKings and optimize your lineups. You can get current contests, fetch draftable players for each contest, and list contest participants and their points for each contest. There are also functions to facilitate lineup optimization using DraftKings player projections or your own player point predictions. If you use DraftKings and know R, this package is for you.

The functions contained in this package wrap any endpoints I was able to find by inspecting the Draft Kings website. The DraftKings public API is undocumented. If you find an endpoint not included in the package, please open an issue.

Installation

You can install the development version of draft.kings from GitHub with:

# install.packages("devtools")
devtools::install_github("gacolitti/draft.kings")
library(draft.kings)

Contests

List all contests in the Draft Kings lobby

dk_get_lobby_contests() |> dplyr::glimpse()
#> Rows: 989
#> Columns: 51
#> $ uc                          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ ec                          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ maximum_entries_per_user    <dbl> 150, 22, 150, 4, 1, 20, 150, 150, 52, 1, 1…
#> $ frequent_player_points      <dbl> 25, 4444, 15, 333, 121, 3333, 15, 3, 20, 3…
#> $ s                           <dbl> 13, 13, 2, 2, 2, 2, 9, 9, 4, 4, 13, 13, 13…
#> $ name                        <chr> "PGA $2.75M Fantasy Golf Millionaire [$1M …
#> $ entries                     <dbl> 747, 9, 2328, 35, 27, 70, 3663, 5792, 1224…
#> $ maximum_entries             <dbl> 129411, 750, 7843, 136, 183, 667, 31372, 4…
#> $ entry_fee                   <dbl> 25, 4444, 15, 333, 121, 3333, 15, 3, 20, 3…
#> $ total_payouts               <dbl> 2750000, 3000000, 100000, 41000, 20000, 20…
#> $ tickets                     <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ start_time_string           <chr> "Thu 6:00AM", "Thu 6:00AM", "Thu 7:15PM", …
#> $ contest_start_time          <dttm> 2024-07-18 10:00:00, 2024-07-18 10:00:00,…
#> $ contest_key                 <dbl> 162653658, 162653657, 162826869, 162826866…
#> $ tmpl                        <dbl> 954955, 954879, 332779, 362394, 370785, 95…
#> $ pt                          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ so                          <dbl> -99999999, -99999998, -99999997, -99999996…
#> $ fwt                         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ is_owner                    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ start_time_type             <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ draft_group_id              <dbl> 108599, 108599, 108784, 108784, 108784, 10…
#> $ ulc                         <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ contest_status              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ game_type                   <chr> "Classic", "Classic", "Classic", "Classic"…
#> $ ssd                         <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ dgpo                        <dbl> 5750000.0, 5750000.0, 729874.6, 729874.6, …
#> $ cso                         <dbl> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, …
#> $ ir                          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ rl                          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ rlc                         <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ rll                         <dbl> 99999, 99999, 99999, 99999, 99999, 99999, …
#> $ sa                          <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, …
#> $ free_with_crowns            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ crown_amount                <dbl> 13750, 2444200, 8250, 183150, 66550, 18331…
#> $ is_bonus_finalized          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ is_snake_draft              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, …
#> $ attr_is_guaranteed          <chr> "true", "true", "true", "true", "true", "t…
#> $ attr_lobby_class            <chr> "icon-millionaire", "icon-millionaire", NA…
#> $ attr_is_starred             <chr> "true", "true", "true", "true", "true", "t…
#> $ pd_cash                     <chr> "$2,750,000", "$3,000,000", "$100,000", "$…
#> $ pd_contest_seat             <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_tournament_of_champ <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_qualifier           <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ pd_live_final_seat          <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_winner_take_all     <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_league                 <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_hide_branded_logo      <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_double_up           <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_fiftyfifty          <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_headliner           <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ attr_is_nighttime           <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…

Get info about a particular contest

dk_get_contest_info(contest_key = 133645678) |> dplyr::glimpse()
#> Rows: 1
#> Columns: 33
#> $ contest_summary                   <chr> "This 215-player contest features $5…
#> $ payout_description                <chr> "$5,000"
#> $ is_cash_prize_only                <lgl> TRUE
#> $ scoring_style_id                  <dbl> 1
#> $ contest_state_detail              <chr> "Completed"
#> $ includes_past_season_collectibles <lgl> FALSE
#> $ sport                             <chr> "NFL"
#> $ is_guaranteed                     <lgl> TRUE
#> $ is_private                        <lgl> FALSE
#> $ is_resizable                      <lgl> FALSE
#> $ was_resized                       <lgl> FALSE
#> $ fpp_award                         <dbl> 27
#> $ sort_order                        <dbl> -1001
#> $ contest_start_time                <chr> "2022-10-10T00:20:00.0000000Z"
#> $ game_type_id                      <dbl> 96
#> $ ticket_only_entry                 <lgl> FALSE
#> $ game_set_key                      <chr> "9D8220F812DBABB10C5D296746983AAC"
#> $ contest_key                       <chr> "133645678"
#> $ name                              <chr> "NFL Showdown $5K Super Booster [Top…
#> $ draft_group_id                    <dbl> 75284
#> $ play_type_id                      <dbl> 161969
#> $ entries                           <dbl> 215
#> $ maximum_entries                   <dbl> 215
#> $ maximum_entries_per_user          <dbl> 6
#> $ entry_fee                         <dbl> 27
#> $ crown_amount                      <dbl> 14850
#> $ total_payouts                     <dbl> 5000
#> $ contest_state                     <chr> "Completed"
#> $ payout_descriptions_cash          <chr> "$5,000.00"
#> $ attributes_is_guranteed           <chr> "true"
#> $ attributes_is_starred             <chr> "true"
#> $ attributes_multiplier             <chr> "true"
#> $ attributes_allow_pregeneration    <chr> "true"

Note: A contest key is the sequence of digits that correspond to a specific contest. This can be found by examining the URL of a contest page. For example: https://www.draftkings.com/draft/contest/133645678#. Here the contest ID is 133645678.

Draft Groups

List all the draft groups in the Draft Kings lobby

# You can pass in sport or leave it NULL to fetch all sports
dk_get_lobby_draft_groups(sport = NULL) |> dplyr::glimpse()
#> Rows: 50
#> Columns: 17
#> $ draft_group_id            <dbl> 105573, 108211, 108489, 108615, 108616, 1086…
#> $ contest_type_id           <dbl> 145, 145, 159, 158, 159, 159, 159, 158, 28, …
#> $ start_date                <chr> "2024-09-06T00:20:00.0000000Z", "2024-09-06T…
#> $ start_date_est            <chr> "2024-09-05T20:20:00.0000000", "2024-09-05T2…
#> $ sort_order                <dbl> 1, 3, 7, 8, 9, 10, 11, 24, 3, 999, 999, 999,…
#> $ draft_group_tag           <chr> "Featured", "", "", "Featured", "", "", "Fea…
#> $ game_type_id              <dbl> 145, 145, 159, 158, 159, 159, 159, 158, 2, 1…
#> $ game_type                 <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ sport_sort_order          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 4,…
#> $ sport                     <chr> "NFL", "NFL", "NFL", "NFL", "NFL", "NFL", "N…
#> $ game_count                <dbl> 16, 16, 1, 3, 1, 1, 1, 3, 2, 1, 1, 10, 9, 12…
#> $ contest_start_time_suffix <chr> " (Tournament)", " (Week 1-4 Tournament)", "…
#> $ contest_start_time_type   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0,…
#> $ games                     <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ draft_group_series_id     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ game_set_key              <chr> "28569DBC23E659B7E8CAD5AB34C86727", "28569DB…
#> $ allowugc                  <lgl> FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, …

Get draft group

dk_get_draft_group(draft_group_id = 75284) |> dplyr::glimpse()
#> Rows: 106
#> Columns: 24
#> $ draftable_id           <dbl> 24633208, 24633209, 24633210, 24633211, 2463321…
#> $ first_name             <chr> "Lamar", "Ja'Marr", "Joe", "Mark", "Joe", "Tee"…
#> $ last_name              <chr> "Jackson", "Chase", "Burrow", "Andrews", "Mixon…
#> $ display_name           <chr> "Lamar Jackson", "Ja'Marr Chase", "Joe Burrow",…
#> $ short_name             <chr> "L. Jackson", "J. Chase", "J. Burrow", "M. Andr…
#> $ player_id              <dbl> 877745, 1109979, 878785, 820699, 820727, 978579…
#> $ player_dk_id           <dbl> 17173, 557826, 485441, 16963, 13893, 468715, 17…
#> $ position               <chr> "QB", "WR", "QB", "TE", "RB", "WR", "QB", "WR",…
#> $ roster_slot_id         <dbl> 511, 511, 511, 511, 511, 511, 512, 512, 512, 51…
#> $ salary                 <dbl> 18300, 16500, 15900, 14400, 13200, 12300, 12200…
#> $ status                 <chr> "None", "None", "None", "None", "None", "None",…
#> $ is_swappable           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE…
#> $ is_disabled            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE…
#> $ news_status            <chr> "Recent", "Recent", "Recent", "Recent", "Recent…
#> $ player_image50         <chr> "https://dkn.gs/sports/images/nfl/players/50/17…
#> $ player_image160        <chr> "https://dkn.gs/sports/images/nfl/players/160/1…
#> $ alt_player_image50     <chr> "", "", "", "", "", "", "", "", "", "", "", "",…
#> $ alt_player_image160    <chr> "", "", "", "", "", "", "", "", "", "", "", "",…
#> $ team_id                <dbl> 366, 327, 327, 366, 327, 327, 366, 327, 327, 36…
#> $ team_abbreviation      <chr> "BAL", "CIN", "CIN", "BAL", "CIN", "CIN", "BAL"…
#> $ player_game_hash       <chr> "877745-5819761", "1109979-5819761", "878785-58…
#> $ competition_id         <dbl> 5819761, 5819761, 5819761, 5819761, 5819761, 58…
#> $ competition_name       <chr> "CIN @ BAL", "CIN @ BAL", "CIN @ BAL", "CIN @ B…
#> $ competition_start_time <chr> "2022-10-10T00:20:00.0000000Z", "2022-10-10T00:…

# If you don't know the draft group ID, you can pass in the contest key 
# and the draft group ID will be retrieved automatically for you.
# dk_get_draft_group(contest_key = 133645678)

Note: A draft group is the list of players associated with a fantasy sports contest.

Get draft group info

dk_get_draft_group_info(draft_group_id = 75284) |> dplyr::glimpse()
#> List of 3
#>  $ info   : tibble [1 × 12] (S3: tbl_df/tbl/data.frame)
#>   ..$ draft_group_id   : int 75284
#>   ..$ sport_id         : int 1
#>   ..$ start_time_suffix: chr " (CIN vs BAL)"
#>   ..$ start_time_type  : chr "Normal"
#>   ..$ min_start_time   : chr "2022-10-10T00:20:00.0000000Z"
#>   ..$ max_start_time   : chr "2022-10-10T00:20:00.0000000Z"
#>   ..$ draft_group_state: chr "Historical"
#>   ..$ allow_ugc        : logi TRUE
#>   ..$ game_type_id     : int 96
#>   ..$ contest_type_id  : int 96
#>   ..$ sport            : chr "NFL"
#>   ..$ game_type        : chr "SalaryCap"
#>  $ games  : tibble [1 × 16] (S3: tbl_df/tbl/data.frame)
#>   ..$ game_id                            : int 5819761
#>   ..$ away_team_id                       : int 327
#>   ..$ home_team_id                       : int 366
#>   ..$ start_date                         : chr "2022-10-10T00:20:00.0000000Z"
#>   ..$ location                           : chr "M&T Bank Stadium"
#>   ..$ time_remaining_status              : chr "Final"
#>   ..$ sport                              : chr "NFL"
#>   ..$ status                             : chr "Final"
#>   ..$ description                        : chr "CIN @ BAL"
#>   ..$ league                             : chr "NFL"
#>   ..$ competition_status                 : chr "ScoresOfficial"
#>   ..$ competition_status_detail          : chr ""
#>   ..$ sport_specific_data_time_remaining : chr "Final"
#>   ..$ sport_specific_data_home_team_score: chr "19"
#>   ..$ sport_specific_data_away_team_score: chr "17"
#>   ..$ sport_specific_data_quarter        : chr "4"
#>  $ leagues: tibble [1 × 3] (S3: tbl_df/tbl/data.frame)
#>   ..$ league_id          : int 1
#>   ..$ league_name        : chr "National Football League"
#>   ..$ league_abbreviation: chr "NFL"

Get more draft group info

dk_get_draft_group_info2(draft_group_id = 75284) |> dplyr::glimpse()
#> List of 6
#>  $ draft_groups          : tibble [1 × 21] (S3: tbl_df/tbl/data.frame)
#>   ..$ draft_group_id        : int 75284
#>   ..$ contest_type_id       : int 96
#>   ..$ sport_id              : int 1
#>   ..$ start_time_suffix     : chr " (CIN vs BAL)"
#>   ..$ start_time_type       : chr "Normal"
#>   ..$ min_start_time        : chr "2022-10-10T00:20:00.0000000Z"
#>   ..$ max_start_time        : chr "2022-10-10T00:20:00.0000000Z"
#>   ..$ draft_group_state     : chr "Historical"
#>   ..$ sort_order            : int 39
#>   ..$ allow_ugc             : logi TRUE
#>   ..$ league_id             : int 1
#>   ..$ league_name           : chr "National Football League"
#>   ..$ league_abbreviation   : chr "NFL"
#>   ..$ game_type_id          : int 96
#>   ..$ game_set_key          : chr "9D8220F812DBABB10C5D296746983AAC"
#>   ..$ all_tags1             : chr "Featured"
#>   ..$ competition_ids       : chr "5819761"
#>   ..$ scoring_style_id      : int 1
#>   ..$ allow_lineup_creation : logi TRUE
#>   ..$ is_late_draft_eligible: logi FALSE
#>   ..$ last_draft_time_utc   : chr "2022-10-10T00:20:00.0000000Z"
#>  $ game_types            : tibble [1 × 5] (S3: tbl_df/tbl/data.frame)
#>   ..$ game_types_game_type_id: int 96
#>   ..$ game_types_name        : chr "Showdown Captain Mode"
#>   ..$ game_types_description : chr "Create your team from 1 game, while staying under the $50,000 salary cap"
#>   ..$ game_types_tag         : chr ""
#>   ..$ game_types_sport_id    : int 1
#>  $ game_styles           : tibble [1 × 7] (S3: tbl_df/tbl/data.frame)
#>   ..$ game_styles_game_style_id: int 48
#>   ..$ game_styles_name         : chr "Showdown Captain Mode"
#>   ..$ game_styles_description  : chr "Create your team from 1 game, while staying under the $50,000 salary cap"
#>   ..$ game_styles_draft_type   : chr "SalaryCap"
#>   ..$ game_styles_sport_id     : int 1
#>   ..$ game_styles_sort_order   : int 2
#>   ..$ game_styles_tag          : chr ""
#>  $ sports                : tibble [1 × 8] (S3: tbl_df/tbl/data.frame)
#>   ..$ sportId                : int 1
#>   ..$ name                   : chr "NFL"
#>   ..$ fullName               : chr "Football"
#>   ..$ sortOrder              : int 3
#>   ..$ competitionTerm        : chr "Game"
#>   ..$ competitionTermPlural  : chr "Games"
#>   ..$ regionalDisplayName    : chr "NFL"
#>   ..$ regionalDisplayFullName: chr "Football"
#>  $ competitions          : tibble [1 × 22] (S3: tbl_df/tbl/data.frame)
#>   ..$ competition_id            : int 5819761
#>   ..$ sport                     : chr "NFL"
#>   ..$ sport_id                  : int 1
#>   ..$ home_team_team_id         : int 366
#>   ..$ home_team_team_name       : chr "Ravens"
#>   ..$ home_team_abbreviation    : chr "BAL"
#>   ..$ home_team_city            : chr "Baltimore"
#>   ..$ away_team_team_id         : int 327
#>   ..$ away_team_team_name       : chr "Bengals"
#>   ..$ away_team_abbreviation    : chr "CIN"
#>   ..$ away_team_city            : chr "Cincinnati"
#>   ..$ start_time                : chr "2022-10-10T00:20:00.0000000Z"
#>   ..$ name                      : chr "CIN @ BAL"
#>   ..$ venue                     : chr "M&T Bank Stadium"
#>   ..$ weather_icon              : chr "clear-night"
#>   ..$ weather_is_dome           : logi FALSE
#>   ..$ starting_lineups_available: logi FALSE
#>   ..$ depth_charts_available    : logi TRUE
#>   ..$ competition_state         : chr "ScoresOfficial"
#>   ..$ competition_state_detail  : chr ""
#>   ..$ competition_started_early : logi FALSE
#>   ..$ min_start_time            : chr "2022-10-10T00:20:00.0000000Z"
#>  $ competition_attributes: tibble [5 × 3] (S3: tbl_df/tbl/data.frame)
#>   ..$ competition_id: int [1:5] 5819761 5819761 5819761 5819761 5819761
#>   ..$ typeId        : int [1:5] 8 9 22 27 32
#>   ..$ value         : chr [1:5] "4" "Final" "5" "False" ...

Get list of players for a draft group

dk_get_player_list(draft_group_id = 75284) |> dplyr::glimpse()
#> Rows: 53
#> Columns: 32
#> $ player_id                 <dbl> 877745, 1109979, 878785, 820699, 820727, 978…
#> $ did                       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ pcode                     <dbl> 31002, 33393, 32671, 31056, 30161, 32703, 32…
#> $ competition_id            <dbl> 5819761, 5819761, 5819761, 5819761, 5819761,…
#> $ first_name                <chr> "Lamar", "Ja'Marr", "Joe", "Mark", "Joe", "T…
#> $ last_name                 <chr> "Jackson", "Chase", "Burrow", "Andrews", "Mi…
#> $ first_name_duplicate      <chr> "Lamar", "Ja'Marr", "Joe", "Mark", "Joe", "T…
#> $ last_name_duplicate       <chr> "Jackson", "Chase", "Burrow", "Andrews", "Mi…
#> $ jersey_number             <dbl> 8, 1, 9, 89, 28, 5, 27, 7, 83, 10, 17, 13, 6…
#> $ position                  <chr> "QB", "WR", "QB", "TE", "RB", "WR", "RB", "W…
#> $ competition_start_time    <dbl> 1.665361e+12, 1.665361e+12, 1.665361e+12, 1.…
#> $ team_id                   <dbl> 366, 327, 327, 366, 327, 327, 366, 366, 327,…
#> $ home_team_id              <dbl> 366, 366, 366, 366, 366, 366, 366, 366, 366,…
#> $ away_team_id              <dbl> 327, 327, 327, 327, 327, 327, 327, 327, 327,…
#> $ home_team_abbreviation    <chr> "BAL", "BAL", "BAL", "BAL", "BAL", "BAL", "B…
#> $ away_team_abbreviation    <chr> "CIN", "CIN", "CIN", "CIN", "CIN", "CIN", "C…
#> $ position_id               <dbl> 1, 3, 1, 4, 2, 3, 2, 3, 3, 1, 1, 1, 1, 3, 2,…
#> $ roster_slot_id            <dbl> 512, 512, 512, 512, 512, 512, 512, 512, 512,…
#> $ slo                       <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ is_disabled               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
#> $ salary                    <dbl> 12200, 11000, 10600, 9600, 8800, 8200, 7000,…
#> $ points_per_game           <chr> "23.1", "17.4", "16.3", "12.6", "15.9", "12.…
#> $ own_rate                  <dbl> 20, 9, 3, 30, 13, 9, 13, 20, 9, 3, 3, 3, 3, …
#> $ is_swappable              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
#> $ in_play_contest           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
#> $ pp                        <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ injury_status             <chr> "", "", "Q", "", "", "", "Q", "", "", "", ""…
#> $ news_code                 <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ large_image_url           <chr> "https://dkn.gs/sports/images/nfl/players/0/…
#> $ alternate_large_image_url <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ small_image_url           <chr> "https://dkn.gs/sports/images/nfl/players/50…
#> $ alternate_small_image_url <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …

Get list of teams for a draft group

dk_get_team_list(draft_group_id = 75284) |> dplyr::glimpse()
#> Rows: 1
#> Columns: 9
#> $ home_team_abbreviation <chr> "BAL"
#> $ home_team_id           <dbl> 366
#> $ away_team_abbreviation <chr> "CIN"
#> $ away_team_id           <dbl> 327
#> $ competition_start_time <dttm> 2022-10-09 20:20:00
#> $ dh                     <dbl> 0
#> $ s                      <dbl> 1
#> $ game_status            <chr> "Final"
#> $ game_status_code       <dbl> 4

Get player fantasy points earned

# Data starts on October 18th, 2022 for NBA
# `timeframe` represents the week of the season for NFL
dk_get_player_fp(sport = "nfl", season = 2023, timeframe = 10) |> dplyr::glimpse()
#> Rows: 286
#> Columns: 25
#> $ player_id                  <dbl> 557210, 1062020, 591816, 607864, 1127106, 9…
#> $ player_dk_id               <dbl> 19006, 485450, 18078, 13498, 560800, 19265,…
#> $ first_name                 <chr> "Keenan", "CeeDee", "Dak", "Brandin", "Amon…
#> $ last_name                  <chr> "Allen", "Lamb", "Prescott", "Cooks", "St. …
#> $ team_id                    <dbl> 357, 331, 331, 331, 334, 347, 357, 363, 362…
#> $ position                   <chr> "WR", "WR", "QB", "WR", "WR", "TE", "QB", "…
#> $ salary                     <dbl> 8800, 8500, 6700, 4200, 8300, 5000, 7700, 5…
#> $ fantasy_points             <dbl> 43.50, 42.50, 41.86, 35.30, 33.50, 33.40, 3…
#> $ value_icon                 <chr> "fire", "fire", "fire", "fire", "fire", "fi…
#> $ competition_id             <dbl> 5939220, 5939250, 5939250, 5939250, 5939220…
#> $ points                     <dbl> 43.50, 42.50, 41.86, 35.30, 33.50, 33.40, 3…
#> $ sport                      <chr> "nfl", "nfl", "nfl", "nfl", "nfl", "nfl", "…
#> $ game_status                <chr> "liveOrFinal", "liveOrFinal", "liveOrFinal"…
#> $ competition_start_time     <dttm> 2023-11-12 21:05:00, 2023-11-12 21:25:00, …
#> $ week_number                <dbl> 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,…
#> $ image_url                  <chr> "https://dkn.gs/sports/images/nfl/players/1…
#> $ team_city                  <chr> "Los Angeles", "Dallas", "Dallas", "Dallas"…
#> $ team_name                  <chr> "Chargers", "Cowboys", "Cowboys", "Cowboys"…
#> $ team_abbreviation          <chr> "LAC", "DAL", "DAL", "DAL", "DET", "MIN", "…
#> $ opposing_team_city         <chr> "Detroit", "New York", "New York", "New Yor…
#> $ opposing_team_name         <chr> "Lions", "Giants", "Giants", "Giants", "Cha…
#> $ opposing_team_abbreviation <chr> "DET", "NYG", "NYG", "NYG", "LAC", "NO", "D…
#> $ fantasy_stats_num_games    <dbl> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3…
#> $ fantasy_points_per_game    <dbl> 24.7000, 39.5333, 35.0933, 17.0667, 26.5000…
#> $ player_state               <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…

Get competitions associated to a draft group

dk_get_competitions(draft_group_id = 75284) |> dplyr::glimpse()
#> Rows: 1
#> Columns: 27
#> $ competition_id                    <int> 5819761
#> $ sport                             <chr> "NFL"
#> $ start_time                        <chr> "2022-10-10T00:20:00.0000000Z"
#> $ competition_state                 <chr> "ScoresOfficial"
#> $ competition_state_detail          <lgl> NA
#> $ time_remaining_status             <chr> "Final"
#> $ home_team_team_id                 <int> 366
#> $ home_team_team_name               <chr> "Ravens"
#> $ home_team_team_abbreviation       <chr> "BAL"
#> $ home_team_team_city               <chr> "Baltimore"
#> $ home_team_primary_color           <chr> "#241773"
#> $ home_team_secondary_color         <chr> "#000000"
#> $ home_team_tertiary_color          <chr> "#9e7c0c"
#> $ home_team_team_logo_url           <chr> "https://dkn.gs/sports/images/nfl/te…
#> $ home_team_dark_mode_team_logo_url <chr> ""
#> $ away_team_team_id                 <int> 327
#> $ away_team_team_name               <chr> "Bengals"
#> $ away_team_team_abbreviation       <chr> "CIN"
#> $ away_team_team_city               <chr> "Cincinnati"
#> $ away_team_primary_color           <chr> "#fb4f14"
#> $ away_team_secondary_color         <chr> "#000000"
#> $ away_team_team_logo_url           <chr> "https://dkn.gs/sports/images/nfl/te…
#> $ away_team_dark_mode_team_logo_url <chr> ""
#> $ time_remaining                    <chr> "Final"
#> $ home_team_score                   <chr> "19"
#> $ away_team_score                   <chr> "17"
#> $ quarter                           <chr> "4"

Leaderboard

Get player leaderboard information for a particular contest

A leaderboard contains a list of entries in a contest, fantasy points for each entry, associated users for each entry, rank, and winnings.

dk_get_leaderboard(contest_key = 133645678) |> dplyr::glimpse()
#> Rows: 215
#> Columns: 20
#> $ draft_group_id          <int> 75284, 75284, 75284, 75284, 75284, 75284, 7528…
#> $ contest_key             <chr> "133645678", "133645678", "133645678", "133645…
#> $ entry_key               <chr> "3412356478", "3416201807", "3416313295", "341…
#> $ lineup_id               <int> -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1…
#> $ user_name               <chr> "GenoMike21", "carlitosway9", "KidRaider3", "c…
#> $ user_key                <chr> "642864", "1334845", "5752908", "8636059", "86…
#> $ user_entry_count        <int> 1, 1, 1, 1, 6, 1, 2, 2, 1, 1, 3, 3, 3, 1, 2, 1…
#> $ user_entry_index        <int> 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1…
#> $ time_remaining          <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ time_remaining_unit     <chr> "PMR", "PMR", "PMR", "PMR", "PMR", "PMR", "PMR…
#> $ max_time_remaining      <int> 360, 360, 360, 360, 360, 360, 360, 360, 360, 3…
#> $ time_remaining_opponent <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ rank                    <int> 1, 1, 1, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 14,…
#> $ fantasy_points          <dbl> 101.41, 101.41, 101.41, 97.64, 96.32, 96.21, 9…
#> $ fantasy_points_opponent <dbl> 101.41, 101.41, 101.41, 101.41, 101.41, 101.41…
#> $ user_name_opponent      <chr> "carlitosway9", "GenoMike21", "GenoMike21", "G…
#> $ number_tickets_won      <int> 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, NA, NA, NA, …
#> $ tickets_value           <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ winning_value           <int> 1000, 1000, 1000, 1000, 1000, 0, 0, 0, 0, 0, 0…
#> $ winnings                <list> [1000, "Cash"], [1000, "Cash"], [1000, "Cash"…

Note: Some functions such as dk_get_leaderboard() require passing the session cookies to the function as a JSON file.

Get entries for a contest

Fetch details for entries in a contest, including the drafted roster for each entry, stats for each player in an entry roster, and the fantasy points associated to each stat.

dk_get_entries(draft_group_id = 80584, entry_keys = c(3618408508, 3618897002))
#> # A tibble: 76 × 29
#>    contest_key entry_key  user_key draft_group_id lineup_id first_name last_name
#>    <chr>       <chr>      <chr>             <int>     <int> <chr>      <chr>    
#>  1 140039397   3618408508 11222656          80584        -1 Cole       Beasley  
#>  2 140039397   3618408508 11222656          80584        -1 Cole       Beasley  
#>  3 140039397   3618408508 11222656          80584        -1 Cole       Beasley  
#>  4 140039397   3618408508 11222656          80584        -1 Cole       Beasley  
#>  5 140039397   3618408508 11222656          80584        -1 Cole       Beasley  
#>  6 140039397   3618408508 11222656          80584        -1 Gabe       Davis    
#>  7 140039397   3618408508 11222656          80584        -1 Gabe       Davis    
#>  8 140039397   3618408508 11222656          80584        -1 Gabe       Davis    
#>  9 140039397   3618408508 11222656          80584        -1 Gabe       Davis    
#> 10 140039397   3618408508 11222656          80584        -1 Gabe       Davis    
#> # ℹ 66 more rows
#> # ℹ 22 more variables: short_name <chr>, display_name <chr>,
#> #   roster_position_id <int>, roster_position <chr>,
#> #   roster_position_sort_order <int>, e_tag <chr>, percent_drafted <dbl>,
#> #   draftable_id <int>, score <dbl>, stats_description <chr>,
#> #   time_remaining_unit <chr>, time_remaining <int>, max_time_remaining <int>,
#> #   percent_drafted_cp <chr>, player_deep_link <chr>, …

Note: An entry key is a numeric (or character) key that corresponds to a specific entry in a specific contest. See output from dk_get_leaderboard().

Optimization

draft.kings contains a set of functions to perform lineup optimization. By default, optimization uses Draft Kings player point projections, but you can pass in your own player point projections. Only NFL and NBA contest types are supported currently.

Prepare schematic

To perform optimization you must first prepare a schematic. A schematic contains all the necessary information to perform optimization including the contest type, set of players, rules, and expected player points.

schematic <- dk_prepare_schematic(draft_group_id = 80584)
dplyr::glimpse(schematic)
#> List of 3
#>  $ draft_group   : tibble [106 × 27] (S3: tbl_df/tbl/data.frame)
#>   ..$ draftable_id          : num [1:106] 26368922 26368923 26368924 26368925 26368926 ...
#>   ..$ first_name            : chr [1:106] "Josh" "Tyreek" "Stefon" "Tua" ...
#>   ..$ last_name             : chr [1:106] "Allen" "Hill" "Diggs" "Tagovailoa" ...
#>   ..$ display_name          : chr [1:106] "Josh Allen" "Tyreek Hill" "Stefon Diggs" "Tua Tagovailoa" ...
#>   ..$ short_name            : chr [1:106] "J. Allen" "T. Hill" "S. Diggs" "T. Tagovailoa" ...
#>   ..$ player_id             : num [1:106] 868199 823156 694041 973947 592195 ...
#>   ..$ player_dk_id          : num [1:106] 11370 11477 17102 468529 18260 ...
#>   ..$ position              : chr [1:106] "QB" "WR" "WR" "QB" ...
#>   ..$ roster_slot_id        : num [1:106] 511 511 511 511 511 511 511 512 511 511 ...
#>   ..$ salary                : num [1:106] 18600 16500 15900 15600 14100 13500 13200 12400 12000 11700 ...
#>   ..$ status                : chr [1:106] "None" "None" "None" "None" ...
#>   ..$ is_swappable          : logi [1:106] FALSE FALSE FALSE FALSE FALSE FALSE ...
#>   ..$ is_disabled           : logi [1:106] FALSE FALSE FALSE FALSE FALSE FALSE ...
#>   ..$ news_status           : chr [1:106] "Recent" "Recent" "Recent" "Recent" ...
#>   ..$ player_image50        : chr [1:106] "https://dkn.gs/sports/images/nfl/players/50/11370.png" "https://dkn.gs/sports/images/nfl/players/50/11477.png" "https://dkn.gs/sports/images/nfl/players/50/17102.png" "https://dkn.gs/sports/images/nfl/players/50/468529.png" ...
#>   ..$ player_image160       : chr [1:106] "https://dkn.gs/sports/images/nfl/players/160/11370.png" "https://dkn.gs/sports/images/nfl/players/160/11477.png" "https://dkn.gs/sports/images/nfl/players/160/17102.png" "https://dkn.gs/sports/images/nfl/players/160/468529.png" ...
#>   ..$ alt_player_image50    : chr [1:106] "" "" "" "" ...
#>   ..$ alt_player_image160   : chr [1:106] "" "" "" "" ...
#>   ..$ team_id               : num [1:106] 324 345 324 345 345 345 345 324 345 345 ...
#>   ..$ team_abbreviation     : chr [1:106] "BUF" "MIA" "BUF" "MIA" ...
#>   ..$ player_game_hash      : chr [1:106] "868199-5819869" "823156-5819869" "694041-5819869" "973947-5819869" ...
#>   ..$ competition_id        : num [1:106] 5819869 5819869 5819869 5819869 5819869 ...
#>   ..$ competition_name      : chr [1:106] "MIA @ BUF" "MIA @ BUF" "MIA @ BUF" "MIA @ BUF" ...
#>   ..$ competition_start_time: chr [1:106] "2023-01-15T18:00:00.0000000Z" "2023-01-15T18:00:00.0000000Z" "2023-01-15T18:00:00.0000000Z" "2023-01-15T18:00:00.0000000Z" ...
#>   ..$ exp_fp                : num [1:106] 39 36.9 24.3 26.5 -0.3 ...
#>   ..$ is_captain            : logi [1:106] TRUE TRUE TRUE TRUE TRUE TRUE ...
#>   ..$ row_number            : int [1:106] 1 2 3 4 5 6 7 8 9 10 ...
#>  $ rules         : tibble [1 × 26] (S3: tbl_df/tbl/data.frame)
#>   ..$ game_type_id                  : int 96
#>   ..$ game_type_name                : chr "Showdown Captain Mode"
#>   ..$ game_type_description         : chr "Create your team from 1 game, while staying under the $50,000 salary cap"
#>   ..$ lineup_configuration_id       : int 81
#>   ..$ unique_players                : logi TRUE
#>   ..$ allow_late_swap               : logi FALSE
#>   ..$ error_status                  : logi NA
#>   ..$ rules_url                     : chr "/help/rules/1/96"
#>   ..$ draft_type                    : chr "SalaryCap"
#>   ..$ allowed_competition_attributes: logi NA
#>   ..$ scoring_divider               : logi NA
#>   ..$ use_optimal_lineups           : logi FALSE
#>   ..$ supports_players_tab          : logi FALSE
#>   ..$ show_bye_week_info            : logi FALSE
#>   ..$ original_draft_type           : logi NA
#>   ..$ is_season_long                : logi FALSE
#>   ..$ team_position_limits          : logi NA
#>   ..$ salary_cap_is_enabled         : logi TRUE
#>   ..$ salary_cap_min_value          : int 0
#>   ..$ salary_cap_max_value          : int 50000
#>   ..$ game_count_is_enabled         : logi FALSE
#>   ..$ game_count_min_value          : logi NA
#>   ..$ game_count_max_value          : logi NA
#>   ..$ team_count_is_enabled         : logi TRUE
#>   ..$ team_count_min_value          : int 2
#>   ..$ team_count_max_value          : logi NA
#>  $ draft_group_id: num 80584
#>  - attr(*, "class")= chr [1:2] "showdown_captain_mode" "list"

Perform optimization

Pass the schematic object to the optimization function:

optimal_lineup <- dk_optimize_lineup(schematic)

Extract solution

Finally, extract the solution from the solved model object:

dk_extract_solution(optimal_lineup) |> dplyr::glimpse()
#> List of 4
#>  $ optimal_lineup:'data.frame':  6 obs. of  26 variables:
#>   ..$ draftable_id          : num [1:6] 26368922 26368976 26368982 26368990 26368996 ...
#>   ..$ first_name            : chr [1:6] "Josh" "Tyreek" "Raheem" "James" ...
#>   ..$ last_name             : chr [1:6] "Allen" "Hill" "Mostert" "Cook" ...
#>   ..$ display_name          : chr [1:6] "Josh Allen" "Tyreek Hill" "Raheem Mostert" "James Cook" ...
#>   ..$ short_name            : chr [1:6] "J. Allen" "T. Hill" "R. Mostert" "J. Cook" ...
#>   ..$ player_id             : num [1:6] 868199 823156 606501 1131012 821895 ...
#>   ..$ player_dk_id          : num [1:6] 11370 11477 19614 640895 14871 ...
#>   ..$ position              : chr [1:6] "QB" "WR" "RB" "RB" ...
#>   ..$ roster_slot_id        : num [1:6] 511 512 512 512 512 512
#>   ..$ salary                : num [1:6] 18600 11000 8000 5400 3800 3200
#>   ..$ status                : chr [1:6] "None" "None" "None" "None" ...
#>   ..$ is_swappable          : logi [1:6] FALSE FALSE FALSE FALSE FALSE FALSE
#>   ..$ is_disabled           : logi [1:6] FALSE FALSE FALSE FALSE FALSE FALSE
#>   ..$ news_status           : chr [1:6] "Recent" "Recent" "Breaking" "Recent" ...
#>   ..$ player_image50        : chr [1:6] "https://dkn.gs/sports/images/nfl/players/50/11370.png" "https://dkn.gs/sports/images/nfl/players/50/11477.png" "https://dkn.gs/sports/images/nfl/players/50/19614.png" "https://dkn.gs/sports/images/nfl/players/50/640895.png" ...
#>   ..$ player_image160       : chr [1:6] "https://dkn.gs/sports/images/nfl/players/160/11370.png" "https://dkn.gs/sports/images/nfl/players/160/11477.png" "https://dkn.gs/sports/images/nfl/players/160/19614.png" "https://dkn.gs/sports/images/nfl/players/160/640895.png" ...
#>   ..$ alt_player_image50    : chr [1:6] "" "" "" "" ...
#>   ..$ alt_player_image160   : chr [1:6] "" "" "" "" ...
#>   ..$ team_id               : num [1:6] 324 345 345 324 345 345
#>   ..$ team_abbreviation     : chr [1:6] "BUF" "MIA" "MIA" "BUF" ...
#>   ..$ player_game_hash      : chr [1:6] "868199-5819869" "823156-5819869" "606501-5819869" "1131012-5819869" ...
#>   ..$ competition_id        : num [1:6] 5819869 5819869 5819869 5819869 5819869 ...
#>   ..$ competition_name      : chr [1:6] "MIA @ BUF" "MIA @ BUF" "MIA @ BUF" "MIA @ BUF" ...
#>   ..$ competition_start_time: chr [1:6] "2023-01-15T18:00:00.0000000Z" "2023-01-15T18:00:00.0000000Z" "2023-01-15T18:00:00.0000000Z" "2023-01-15T18:00:00.0000000Z" ...
#>   ..$ exp_fp                : num [1:6] 39 24.6 17.4 14.1 8.2 8.6
#>   ..$ is_captain            : logi [1:6] TRUE FALSE FALSE FALSE FALSE FALSE
#>  $ draft_group_id: num 80584
#>  $ salary_total  : num 50000
#>  $ exp_fp_total  : num 112

About

Fetch Draft Kings data and optimize lineups

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages