Пример #1
0
def cotes_combine_all_sites(*matches, freebet=False):
    """
    Calcule les cotes combinées de matches dont on connait les cotes sur plusieurs
    bookmakers
    """
    sites = set(matches[0]["odds"].keys())
    for match in matches:
        sites = sites.intersection(match["odds"].keys())
    combine_dict = {"date": max([match["date"] for match in matches]), "odds": {}}
    for site in sites:
        if freebet:
            combine_dict["odds"][site] = cotes_freebet(cotes_combine([match["odds"][site]
                                                                      for match in matches]))
        else:
            combine_dict["odds"][site] = cotes_combine([match["odds"][site] for match in matches])
    return combine_dict
Пример #2
0
def best_matches_freebet(main_sites, freebets, *matches):
    """
    Compute of best way to bet freebets following the model
    [[bet, bookmaker], ...]
    """
    second_sites = {freebet[1] for freebet in freebets}
    if not second_sites:
        print("Veuillez sélectionner des freebets secondaires")
        return
    if matches:
        new_odds = {}
        for match in matches:
            match_name, odds = odds_match(match)
            new_odds[match_name] = odds
    else:
        new_odds = sportsbetting.ODDS["football"]
    all_odds = {}
    for match in new_odds:
        if (not (any([
                site not in new_odds[match]["odds"].keys()
                for site in main_sites
        ]) or any([
                site not in new_odds[match]["odds"].keys()
                for site in second_sites
        ]))):
            if new_odds[match]["odds"]:
                all_odds[match] = new_odds[match]
    best_rate = 0
    nb_matches = 2
    n = 3**nb_matches
    nb_freebets = len(freebets)
    all_odds_combine = {}
    combis = list(combinations(all_odds.items(), nb_matches))
    nb_combis = len(combis)
    progress = 10
    start = time.time()
    for i, combine in enumerate(combis):
        if i == 20:
            print("appr. time to wait:",
                  int((time.time() - start) * nb_combis / 20), "s")
        if i / nb_combis * 100 > progress:
            print(str(progress) + "%")
            progress += 10
        match_combine = " / ".join([match[0] for match in combine])
        all_odds_combine[match_combine] = cotes_combine_all_sites(
            *[match[1] for match in combine], freebet=True)
        main_sites_distribution = [main_sites[0] for _ in range(n)]
        main_site_odds = cotes_freebet(
            cotes_combine([
                combine[x][1]['odds'][main_sites[0]] for x in range(nb_matches)
            ]))
        main_site_odds = all_odds_combine[match_combine]["odds"][main_sites[0]]
        for main in main_sites[1:]:
            potential_odds = all_odds_combine[match_combine]["odds"][main]
            for j, odd in enumerate(potential_odds):
                if odd > main_site_odds[j]:
                    main_site_odds[j] = odd
                    main_sites_distribution[j] = main
        second_odds = {
            second_site: all_odds_combine[match_combine]["odds"][second_site]
            for second_site in second_sites
        }
        dict_combine_odds = copy.deepcopy(second_odds)
        for perm in permutations(range(n), nb_freebets):
            defined_second_sites = [[perm[i], freebet[0], freebet[1]]
                                    for i, freebet in enumerate(freebets)]
            defined_bets_temp = defined_bets(main_site_odds, dict_combine_odds,
                                             main_sites_distribution,
                                             defined_second_sites)
            if defined_bets_temp[0] / np.sum(defined_bets_temp[1]) > best_rate:
                best_rate = defined_bets_temp[0] / np.sum(defined_bets_temp[1])
                best_combine = combine
                best_bets = defined_bets_temp
    print("Temps d'exécution =", time.time() - start)
    best_match_combine = " / ".join([match[0] for match in best_combine])
    odds_best_match = copy.deepcopy(all_odds_combine[best_match_combine])
    all_sites = main_sites + list(second_sites)
    for site in all_odds_combine[best_match_combine]["odds"]:
        if site not in all_sites:
            del odds_best_match["odds"][site]
    print(best_match_combine)
    pprint(odds_best_match, compact=1)
    print("Taux =", best_rate)
    print("Gain référence =", best_bets[0])
    print("Somme des mises =", np.sum(best_bets[1]))
    afficher_mises_combine([x[0] for x in best_combine],
                           best_bets[2],
                           best_bets[1],
                           all_odds_combine[best_match_combine]["odds"],
                           "football",
                           uniquement_freebet=True)