示例#1
0
def best_match_cashback(site, minimum_odd, bet, sport="football", freebet=True,
                        combi_max=0, combi_odd=1, rate_cashback=1, date_max=None,
                        time_max=None, date_min=None, time_min=None):
    """
    Retourne le match qui génère le meilleur gain pour une promotion de type
    "Pari remboursé si perdant". Le bonus combi-max, la côte des sélections
    supposées sûres (dans le cadre d'une promotion sur combiné) ainsi que le
    bonus combi-max sont également paramétrables
    """
    odds_function = lambda best_odds, odds_site, i: (best_odds[:i]
                                                     + [combi_odd * odds_site[i]
                                                        * (1 + combi_max) - combi_max]
                                                     + best_odds[i + 1:])
    profit_function = lambda odds_to_check, i: gain_pari_rembourse_si_perdant(odds_to_check, bet, i,
                                                                              freebet,
                                                                              rate_cashback)
    criteria = lambda odds_to_check, i: (odds_to_check[i] + combi_max) / (
            1 + combi_max) >= minimum_odd
    display_function = lambda x, i: mises_pari_rembourse_si_perdant(x, bet, i, freebet,
                                                                    rate_cashback, True)
    result_function = lambda x, i: mises_pari_rembourse_si_perdant(x, bet, i, freebet,
                                                                   rate_cashback, False)
    best_match_base(odds_function, profit_function, criteria, display_function,
                    result_function, site, sport, date_max, time_max, date_min,
                    time_min)
示例#2
0
def best_matches_combine_cashback(site, minimum_odd, bet, sport="football",
                                  freebet=True, combi_max=0, rate_cashback=1,
                                  nb_matches=2, date_max=None, time_max=None,
                                  date_min=None, time_min=None):
    """
    Calcule la répartition des mises lorsqu'un unique combiné est remboursé s'il est perdant
    """
    all_odds = sportsbetting.ODDS[sport]
    sportsbetting.ALL_ODDS_COMBINE = {}
    for combine in combinations(all_odds.items(), nb_matches):
        (sportsbetting
            .ALL_ODDS_COMBINE[" / "
            .join([match[0]
                   for match
                   in combine])]) = cotes_combine_all_sites(*[match[1]
                                                              for match
                                                              in combine])
    odds_function = lambda best_odds, odds_site, i: (best_odds[:i]
                                                     + [odds_site[i] * (1 + combi_max) - combi_max]
                                                     + best_odds[i + 1:])
    profit_function = lambda odds_to_check, i: gain_pari_rembourse_si_perdant(odds_to_check, bet, i,
                                                                              freebet,
                                                                              rate_cashback)
    criteria = lambda odds_to_check, i: (odds_to_check[i] + combi_max) / (
            1 + combi_max) >= minimum_odd
    display_function = lambda x, i: mises_pari_rembourse_si_perdant(x, bet, i, freebet,
                                                                    rate_cashback, True)
    return_function = lambda x, i: mises_pari_rembourse_si_perdant(x, bet, i, freebet,
                                                                   rate_cashback, False)
    best_match_base(odds_function, profit_function, criteria, display_function,
                    return_function, site, sport, date_max, time_max, date_min,
                    time_min, True, nb_matches)
示例#3
0
def best_combine_reduit(matches,
                        combinaison_boostee,
                        site_combinaison,
                        mise,
                        sport,
                        cote_boostee=0,
                        taux_cashback=0,
                        cashback_freebet=True,
                        freebet=False,
                        output=True):
    def get_odd(combinaison, matches, site_combinaison=None):
        sites = sb.BOOKMAKERS
        if site_combinaison:
            sites = [site_combinaison]
        best_odd = 1
        best_site = ""
        for site in sites:
            odd = 1
            for i, match in zip(combinaison, matches):
                if i != float("inf"):
                    if site in sb.ODDS[sport][match]["odds"].keys():
                        odd *= sb.ODDS[sport][match]["odds"][site][i]
                    else:
                        break
            if odd > best_odd:
                best_odd = odd
                best_site = site
        return best_odd, best_site

    odds = {}
    for match in matches:
        odds[match] = sb.ODDS[sport][match]
    best_combinaison = []
    best_cotes = []
    best_sites = []
    best_gain = -float("inf")
    best_i = -1
    for combinaisons in combine_reduit_rec(combinaison_boostee,
                                           get_nb_outcomes(sport)):
        cotes = []
        sites = []
        for i, combinaison in enumerate(combinaisons):
            if list(combinaison) == combinaison_boostee:
                i_boost = i
                sites.append(site_combinaison)
                if cote_boostee:
                    cotes.append(cote_boostee)
                else:
                    cotes.append(
                        get_odd(combinaison, matches, site_combinaison)[0])
            else:
                res = get_odd(combinaison, matches)
                cotes.append(res[0])
                sites.append(res[1])
        if not taux_cashback:
            new_gain = gain2(cotes, i_boost, mise)
        else:
            new_gain = gain_pari_rembourse_si_perdant(cotes, mise, i_boost,
                                                      cashback_freebet,
                                                      taux_cashback)
        if new_gain > best_gain:  # and all(cote>cote_minimale for cote in cotes:
            best_cotes = cotes
            best_sites = sites
            best_combinaison = combinaisons
            best_gain = new_gain
            best_i = i_boost
    matches_name = " / ".join(matches)
    if output:
        print(matches_name)
    if not taux_cashback:
        stakes = mises2(best_cotes, mise, best_i)
    else:
        stakes = mises_pari_rembourse_si_perdant(best_cotes, mise, best_i,
                                                 cashback_freebet,
                                                 taux_cashback)
    opponents = []
    for match in matches:
        opponents_match = match.split(" - ")
        if sport not in ["basketball", "tennis"]:
            opponents_match.insert(1, "Nul")
        opponents.append(opponents_match)
    nb_chars = max(map(lambda x: len(" / ".join(x)), product(*opponents)))
    sites = sb.BOOKMAKERS
    odds = {
        site:
        [get_odd(combine, matches, site)[0] for combine in best_combinaison]
        for site in sites
    }
    if not output:
        return best_gain
    pprint(
        {
            "date":
            max(date for date in
                [sb.ODDS[sport][match]["date"] for match in matches]),
            "odds":
            odds
        },
        compact=True)
    print("plus-value =", round(best_gain + freebet * mise, 2))
    if freebet:
        print("taux de conversion =", round((best_gain + mise) / mise * 100,
                                            3), "%")
    print("taux de retour au joueur =", round(gain(best_cotes) * 100, 3), "%")
    print()
    print(
        "Répartition des mises (les totaux affichés prennent en compte les éventuels freebets):"
    )
    table_teams = []
    table_odds = []
    table_stakes = []
    table_totals = []
    table_bookmakers = []
    for combine, stake, cote, site in zip(best_combinaison, stakes, best_cotes,
                                          best_sites):
        names = [
            opponents_match[i] if i != float("inf") else ""
            for match, i, opponents_match in zip(matches, combine, opponents)
        ]
        name_combine = " / ".join(x for x in names if x)
        diff = nb_chars - len(name_combine)
        if freebet and combine == combinaison_boostee:
            sites_bet_combinaison = {
                site: {
                    "mise freebet": round(stake, 2),
                    "cote": round(cote + 1, 3)
                },
                "total": round(round(stake, 2) * cote, 2)
            }
            table_stakes.append("{} (freebet)".format(stake))
            table_odds.append(round(cote + 1, 3))
        else:
            sites_bet_combinaison = {
                site: {
                    "mise": round(stake, 2),
                    "cote": round(cote, 3)
                },
                "total": round(round(stake, 2) * cote, 2)
            }
            table_stakes.append(round(stake, 2))
            table_odds.append(round(cote, 3))
        table_teams.append(name_combine)
        table_totals.append(round(round(stake, 2) * cote, 2))
        table_bookmakers.append(site)
    table = {
        "Issue": table_teams,
        "Bookmaker": table_bookmakers,
        "Cote": table_odds,
        "Mise": table_stakes,
        "Total": table_totals
    }
    text = tabulate.tabulate(table, headers='keys', tablefmt='fancy_grid')
    print(text)
    if sys.platform.startswith("win"):
        copy_to_clipboard(text)