Skip to main content

A tool to automate and optimize DraftKings and FanDuel lineup construction.

Project description

Introduction

Build Status

An incredibly powerful tool that automates and optimizes lineup building, allowing you to enter thousands of lineups in any DraftKings or FanDuel contest in the time it takes you to grab a coffee.

Installation

Requires Python 7.

pip install tfb-draftfast

Usage

Example usage

from draftfast import rules
from draftfast.optimize import run
from draftfast.orm import Player
from draftfast.csv_parse import salary_download

# Create players for a classic DraftKings game
player_pool = [
    Player(name='A1', cost=5500, proj=55, pos='PG'),
    Player(name='A2', cost=5500, proj=55, pos='PG'),
    Player(name='A3', cost=5500, proj=55, pos='SG'),
    Player(name='A4', cost=5500, proj=55, pos='SG'),
    Player(name='A5', cost=5500, proj=55, pos='SF'),
    Player(name='A6', cost=5500, proj=55, pos='SF'),
    Player(name='A7', cost=5500, proj=55, pos='PF'),
    Player(name='A8', cost=5500, proj=55, pos='PF'),
    Player(name='A9', cost=5500, proj=55, pos='C'),
    Player(name='A10', cost=5500, proj=55, pos='C'),
]

roster = run(
    rule_set=rules.DK_NBA_RULE_SET,
    player_pool=player_pool,
    verbose=True,
)

# Or, alternatively, generate players from a CSV
players = salary_download.generate_players_from_csvs(
  salary_file_location='./salaries.csv',
  game=rules.DRAFT_KINGS,
)

roster = run(
  rule_set=rules.DK_NBA_RULE_SET,
  player_pool=players,
  verbose=True,
)

You can see more examples in the examples directory.

Game Rules

Optimizing for a particular game is as easy as setting the RuleSet (see the example above). Game rules in the library are in the table below:

League Site Reference
NFL DraftKings DK_NFL_RULE_SET
NFL FanDuel FD_NFL_RULE_SET
NBA DraftKings DK_NBA_RULE_SET
NBA FanDuel FD_NBA_RULE_SET
MLB DraftKings DK_MLB_RULE_SET
MLB FanDuel FD_MLB_RULE_SET
WNBA DraftKings DK_WNBA_RULE_SET
WNBA FanDuel FD_WNBA_RULE_SET
PGA FanDuel FD_PGA_RULE_SET
NASCAR FanDuel FD_NASCAR_RULE_SET
SOCCER DraftKings DK_SOCCER_RULE_SET
EuroLeague DraftKings DK_EURO_LEAGUE_RULE_SET
NHL DraftKings DK_NHL_RULE_SET
NBA Pickem DraftKings DK_NBA_PICKEM_RULE_SET
NFL Showdown DraftKings DK_NFL_SHOWDOWN_RULE_SET
NBA Showdown DraftKings DK_NBA_SHOWDOWN_RULE_SET
MLB Showdown DraftKings DK_MLB_SHOWDOWN_RULE_SET

Note that you can also tune draftfast for any game of your choice even if it's not implemented in the library (PRs welcome!). Using the RuleSet class, you can generate your own game rules that specific number of players, salary, etc. Example:

from draftfast import rules

golf_rules = rules.RuleSet(
    site=rules.DRAFT_KINGS,
    league='PGA',
    roster_size='6',
    position_limits=[['G', 6, 6]],
    salary_max=50_000,
)

Settings

Usage example:

class Showdown(Roster):
    POSITION_ORDER = {
        'M': 0,
        'F': 1,
        'D': 2,
        'GK': 3,
    }


showdown_limits = [
    ['M', 0, 6],
    ['F', 0, 6],
    ['D', 0, 6],
    ['GK', 0, 6],
]

soccer_rules = rules.RuleSet(
    site=rules.DRAFT_KINGS,
    league='SOCCER_SHOWDOWN',
    roster_size=6,
    position_limits=showdown_limits,
    salary_max=50_000,
    general_position_limits=[],
)
player_pool = salary_download.generate_players_from_csvs(
    salary_file_location=salary_file,
    game=rules.DRAFT_KINGS,
)
roster = run(
    rule_set=soccer_rules,
    player_pool=player_pool,
    verbose=True,
    roster_gen=Showdown,
)

PlayerPoolSettings

  • min_proj
  • max_proj
  • min_salary
  • max_salary
  • min_avg
  • max_avg

OptimizerSettings

  • stacks - A list of Stack objects. Example:
roster = run(
    rule_set=rules.DK_NHL_RULE_SET,
    player_pool=player_pool,
    verbose=True,
    optimizer_settings=OptimizerSettings(
        stacks=[
            Stack(team='PHI', count=3),
            Stack(team='FLA', count=3),
            Stack(team='NSH', count=2),
        ]
    ),
)

LineupConstraints

  • locked - list of players to lock
  • banned - list of players to ban
  • groups - list of player groups constraints. See below
roster = run(
    rule_set=rules.DK_NFL_RULE_SET,
    player_pool=player_pool,
    verbose=True,
    constraints=LineupConstraints(
        locked=['Rob Gronkowski'],
        banned=['Mark Ingram', 'Doug Martin'],
        groups=[
            [('Todd Gurley', 'Melvin Gordon', 'Christian McCaffrey'), (2, 3)],
            [('Chris Carson', 'Mike Davis'), 1],
        ]
    )
)
  • no_offense_against_defense - Do not allow offensive players to be matched up against defensive players in the optimized lineup. Currently only implemented for soccer, NHL, and NFL -- PRs welcome!

CSV Upload

from draftfast.csv_parse import uploaders

uploader = uploaders.DraftKingsNBAUploader(
    pid_file='./pid_file.csv',
)
uploader.write_rosters(rosters)

Support and Consulting

DFS optimization is only one part of a sustainable strategy. Long-term DFS winners have the best:

  • Player projections
  • Bankroll management
  • Diversification in contests played
  • Diversification across lineups (see draftfast.exposure)
  • Research process
  • 1 hour before gametime lineup changes
  • ...and so much more

DraftFast provides support and consulting services that can help with all of these. Let's get in touch today.

Credits

Special thanks to Ben Brostoff, who authored this repo, which was the inspiration for this one.

Current project maintainers:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfb-draftfast-1.0.0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

tfb_draftfast-1.0.0-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file tfb-draftfast-1.0.0.tar.gz.

File metadata

  • Download URL: tfb-draftfast-1.0.0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for tfb-draftfast-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0487d8b1a846fff33ed938b1934072c412dd0967e9c846cd7f5d7dc7112fa688
MD5 9cfc13dad214bf190a9788e4e48badbf
BLAKE2b-256 3336dfa5e1f4e6c841b609c93ba37dc49d26d66abd08a2e8c7f459ecda2237b8

See more details on using hashes here.

File details

Details for the file tfb_draftfast-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tfb_draftfast-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 48.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for tfb_draftfast-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f82ba03c90e31799979affc5926560aa77ffb338a671bce3a63fab9dd16ee196
MD5 2e1144c2b572026b7f39aeed182928fb
BLAKE2b-256 df0259116d3f3076e9bc41056cd63df74a1e2eb7768cc36ed3bbe99903f2f83a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page