def best_matches_combine(site,
                         minimum_odd,
                         bet,
                         sport="football",
                         nb_matches=2,
                         one_site=False,
                         date_max=None,
                         time_max=None,
                         date_min=None,
                         time_min=None,
                         minimum_odd_selection=1.01):
    """
    Retourne les meilleurs matches sur lesquels miser lorsqu'on doit miser une somme
    donnée à une cote donnée sur un combiné
    """
    all_odds = filter_dict_dates(sportsbetting.ODDS[sport], date_max, time_max,
                                 date_min, time_min)
    all_odds = filter_dict_minimum_odd(all_odds, minimum_odd_selection, site)
    sportsbetting.ALL_ODDS_COMBINE = {}
    nb_combine = binomial(len(all_odds), nb_matches)
    sportsbetting.PROGRESS = 0

    def compute_all_odds_combine(nb_combine, combine):
        sportsbetting.PROGRESS += 100 / nb_combine
        try:
            sportsbetting.ALL_ODDS_COMBINE[" / ".join([
                match[0] for match in combine
            ])] = cotes_combine_all_sites(*[match[1] for match in combine])
        except KeyError:
            pass

    ThreadPool(4).map(lambda x: compute_all_odds_combine(nb_combine, x),
                      combinations(all_odds.items(), nb_matches))
    sportsbetting.PROGRESS = 0
    odds_function = get_best_odds(one_site)
    profit_function = get_profit(bet, one_site)
    criteria = lambda odds_to_check, i: (
        (not one_site and odds_to_check[i] >= minimum_odd) or
        (one_site and all(odd >= minimum_odd for odd in odds_to_check)))
    display_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, True)
        if not one_site else mises(best_overall_odds, bet, True))
    result_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, False)
        if not one_site else mises(best_overall_odds, bet, False))
    best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport,
                    date_max,
                    time_max,
                    date_min,
                    time_min,
                    True,
                    nb_matches,
                    one_site=one_site,
                    combine_opt=True)
예제 #2
0
def best_match_under_conditions(site, minimum_odd, bet, sport="football", date_max=None,
                                time_max=None, date_min=None, time_min=None, one_site=False,
                                live=False):
    """
    Retourne le meilleur match sur lequel miser lorsqu'on doit miser une somme
    donnée à une cote donnée. Cette somme peut-être sur seulement une issue
    (one_site=False) ou bien répartie sur plusieurs issues d'un même match
    (one_site=True), auquel cas, chacune des cotes du match doivent respecter le
    critère de cote minimale.
    """
    odds_function = lambda best_odds, odds_site, i: ((best_odds[:i]
                                                      + [odds_site[i] * 0.9 if live else odds_site[
                i]]
                                                      + best_odds[i + 1:]) if not one_site
                                                     else (odds_site[:i]
                                                           + [odds_site[i] * 0.9 if live
                                                              else odds_site[i]]
                                                           + odds_site[i + 1:]))
    profit_function = lambda odds_to_check, i: (gain(odds_to_check, bet) - bet if one_site
                                                else gain2(odds_to_check, i, bet))
    criteria = lambda odds_to_check, i: ((not one_site and odds_to_check[i] >= minimum_odd)
                                         or (one_site and all(odd >= minimum_odd
                                                              for odd in odds_to_check)))
    display_function = lambda best_overall_odds, best_rank: (mises2(best_overall_odds, bet,
                                                                    best_rank, True) if not one_site
                                                             else mises(best_overall_odds, bet,
                                                                        True))
    result_function = lambda best_overall_odds, best_rank: (mises2(best_overall_odds, bet,
                                                                   best_rank, False) if not one_site
                                                            else mises(best_overall_odds, bet,
                                                                       False))
    best_match_base(odds_function, profit_function, criteria, display_function,
                    result_function, site, sport, date_max, time_max, date_min,
                    time_min, one_site=one_site)
예제 #3
0
def best_match_pari_gagnant(site,
                            minimum_odd,
                            bet,
                            sport="football",
                            date_max=None,
                            time_max=None,
                            date_min=None,
                            time_min=None):
    """
    Retourne le meilleur match sur lequel miser lorsqu'on doit gagner un pari à
    une cote donnée sur un site donné.
    """
    odds_function = lambda best_odds, odds_site, i: odds_site
    profit_function = lambda odds_to_check, i: gain2(
        odds_to_check, np.argmax(odds_to_check), bet)
    criteria = lambda odds_to_check, i: all(odd >= minimum_odd
                                            for odd in odds_to_check)
    display_function = lambda best_overall_odds, best_rank: mises2(
        best_overall_odds, bet, np.argmax(best_overall_odds), True)
    result_function = lambda best_overall_odds, best_rank: mises2(
        best_overall_odds, bet, np.argmax(best_overall_odds), False)
    best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport,
                    date_max,
                    time_max,
                    date_min,
                    time_min,
                    one_site=True)
예제 #4
0
def best_matches_combine(site,
                         minimum_odd,
                         bet,
                         sport="football",
                         nb_matches=2,
                         one_site=False,
                         date_max=None,
                         time_max=None,
                         date_min=None,
                         time_min=None,
                         minimum_odd_selection=1.01):
    """
    Retourne les meilleurs matches sur lesquels miser lorsqu'on doit miser une somme
    donnée à une cote donnée sur un combiné
    """
    all_odds = filter_dict_dates(sportsbetting.ODDS[sport], date_max, time_max,
                                 date_min, time_min)
    sportsbetting.ALL_ODDS_COMBINE = {}
    for combine in combinations(all_odds.items(), nb_matches):
        try:
            if all([
                    odd >= minimum_odd_selection for odds in list(
                        all_odds[match[0]]["odds"][site] for match in combine)
                    for odd in odds
            ]):
                (sportsbetting.ALL_ODDS_COMBINE[" / ".join([
                    match[0] for match in combine
                ])]) = cotes_combine_all_sites(
                    *[match[1] for match in combine])
        except KeyError:
            pass
    odds_function = lambda best_odds, odds_site, i: (
        (best_odds[:i] + [odds_site[i]] + best_odds[i + 1:])
        if not one_site else odds_site)
    profit_function = lambda odds_to_check, i: (gain(odds_to_check, bet) - bet
                                                if one_site else gain2(
                                                    odds_to_check, i, bet))
    criteria = lambda odds_to_check, i: (
        (not one_site and odds_to_check[i] >= minimum_odd) or
        (one_site and all(odd >= minimum_odd for odd in odds_to_check)))
    display_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, True)
        if not one_site else mises(best_overall_odds, bet, True))
    result_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, False)
        if not one_site else mises(best_overall_odds, bet, False))
    best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport,
                    date_max,
                    time_max,
                    date_min,
                    time_min,
                    True,
                    nb_matches,
                    one_site=one_site)
def defined_bets(odds_main, odds_second, main_sites, second_sites):
    """
    second_sites type : [[rank, bet, site],...]
    """
    gain = 0
    bets = []
    if second_sites:
        sites = copy.deepcopy(main_sites)
        odds_adapted = copy.deepcopy(odds_main)
        for bet in second_sites:
            odds_adapted[bet[0]] = odds_second[bet[2]][bet[0]]
            sites[bet[0]] = bet[2]
        for bet in second_sites:
            valid = True
            bets = mises2(odds_adapted, bet[1], bet[0])
            gain = bet[1] * odds_adapted[bet[0]]
            for bet2 in second_sites:
                if bets[bet2[0]] - bet2[
                        1] > 1e-6:  # Si on mise plus que ce qui est disponible
                    valid = False
                    break
            if valid:
                break
        index_to_del = []
        for i, elem in enumerate(second_sites):
            second_sites[i][1] -= bets[elem[0]]
            if elem[1] < 1e-6:
                index_to_del.append(i)
        for i in index_to_del[::-1]:
            del second_sites[i]
        res = defined_bets(odds_main, odds_second, main_sites, second_sites)
        return [gain + res[0], [bets] + res[1], [sites] + res[2]]
    return [0, [], []]
예제 #6
0
def defined_bets(odds_main, odds_second, main_sites, second_sites):
    """
    second_sites type : [[rank, bet, site],...]
    """
    if second_sites:
        sites = copy.deepcopy(main_sites)
        odds_adapted = copy.deepcopy(odds_main)
        for bet in second_sites:
            odds_adapted[bet[0]] = odds_second[bet[2]][bet[0]]
            sites[bet[0]] = bet[2]
        for bet in second_sites:
            valid = True
            bets = mises2(odds_adapted, bet[1], bet[0])
            gain_freebets = bet[1] * odds_adapted[bet[0]]
            for bet2 in second_sites:
                if bets[bet2[0]] > bet2[1]:
                    valid = False
                    break
            if valid:
                break
        for i, elem in enumerate(second_sites):
            second_sites[i][1] -= bets[elem[0]]
            if elem[1] < 1e-6:
                i_0 = i
        del second_sites[i_0]
        res = defined_bets(odds_main, odds_second, main_sites, second_sites)
        return [gain_freebets + res[0], [bets] + res[1], [sites] + res[2]]
    return [0, [], []]
def calculator(odds, lay, commissions, stake, reference, outcomes, sites):
    real_odds = []
    back_odds = []
    lay_odds = []
    stakes = []
    backers_stakes = []
    trj = 0
    profit = 0
    try:
        back_odds = ["" if lay else odd for odd, lay in zip(odds, lay)]
        lay_odds = [odd if lay else "" for odd, lay in zip(odds, lay)]
        real_odds = [
            get_real_odd(odd, commission, is_lay)
            for odd, commission, is_lay in zip(odds, commissions, lay)
        ]
        stakes = list(
            map(lambda x: round(x, 2), mises2(real_odds, stake, reference)))
        backers_stakes = [
            round(stake_i / (odd_i - 1), 2) if lay_i else ""
            for stake_i, lay_i, odd_i in zip(stakes, lay, odds)
        ]
        trj = gain(real_odds)
        profit = stake * real_odds[reference] - sum(stakes)
    except ZeroDivisionError:
        pass
    table = {
        "Site":
        sites,
        "Issue":
        outcomes,
        "Lay":
        lay_odds,
        "Cote":
        real_odds,
        "Mise":
        stakes,
        "Stake":
        backers_stakes,
        "Total": [
            round(odd_i * stake_i, 2)
            for odd_i, stake_i in zip(real_odds, stakes)
        ]
    }
    infos = {
        "TRJ": [str(round(trj * 100, 3)) + "%"],
        "Plus-value": [round(profit, 2)]
    }
    if not any(lay):
        del table["Lay"]
        del table["Stake"]
    text = "\n".join([
        tabulate.tabulate(table, headers='keys', tablefmt='fancy_grid'),
        tabulate.tabulate(infos, headers='keys', tablefmt='fancy_grid')
    ])
    print(text)
    if sys.platform.startswith("win"):
        copy_to_clipboard(text)
예제 #8
0
def best_stakes_match(match, site, bet, minimum_odd, sport="football"):
    """
    Pour un match, un bookmaker, une somme à miser sur ce bookmaker et une cote
    minimale donnés, retourne la meilleure combinaison de paris à placer
    """
    best_match, all_odds = odds_match(match, sport)
    if not all_odds:
        print("No match found")
        return
    print(best_match)
    pprint(all_odds)
    odds_site = all_odds['odds'][site]
    best_odds = copy.deepcopy(odds_site)
    best_profit = -float("inf")
    n = len(all_odds['odds'][site])
    best_sites = [site for _ in range(n)]
    best_i = 0
    best_overall_odds = None
    bets = None
    sites = None
    for odds in all_odds['odds'].items():
        for i in range(n):
            if odds[1][i] > best_odds[i] and (odds[1][i] >= 1.1
                                              or odds[0] == "pmu"):
                best_odds[i] = odds[1][i]
                best_sites[i] = odds[0]
    for i in range(n):
        if odds_site[i] >= minimum_odd:
            odds_to_check = (best_odds[:i] + [odds_site[i]] +
                             best_odds[i + 1:])
            profit = gain2(odds_to_check, i, bet)
            if profit > best_profit:
                best_profit = profit
                best_overall_odds = odds_to_check
                sites = best_sites[:i] + [site] + best_sites[i + 1:]
                bets = mises2(odds_to_check, bet, i)
                best_i = i
    if best_overall_odds:
        mises2(best_overall_odds, bet, best_i, True)
        afficher_mises_combine(best_match.split(" / "), [sites], [bets],
                               all_odds["odds"], sport)
    else:
        print("No match found")
예제 #9
0
def compute_odds(window, values):
    try:
        sport = values["SPORT_ODDS"][0]
        stake = float(values["STAKE_ODDS"])
        match = values["MATCHES_ODDS"][0]
        _, bookmakers, best_odds = trj_match(sb.ODDS[sport][match])
    except (ValueError, IndexError) as _:
        return
    if values["OUTCOME_ODDS_SPLIT_STAKE"]:
        old_stdout = sys.stdout  # Memorize the default stdout stream
        sys.stdout = buffer = io.StringIO()
        mises(best_odds, stake, True)
        sys.stdout = old_stdout  # Put the old stream back in place
        what_was_printed = buffer.getvalue()
        profit = float(what_was_printed.split("\n")[4].split(' = ')[1])
        stakes = eval(what_was_printed.split("\n")[5].split(' = ')[1])
    else:
        outcomes = ["1", "2"]
        if get_nb_outcomes(sport) == 3:
            outcomes.insert(1, "N")
        outcome = 0
        for i, outcome_i in enumerate(outcomes):
            if values["OUTCOME_ODDS_"+outcome_i]:
                outcome = i
                break
        old_stdout = sys.stdout  # Memorize the default stdout stream
        sys.stdout = buffer = io.StringIO()
        mises2(best_odds, stake, outcome, True)
        sys.stdout = old_stdout  # Put the old stream back in place
        what_was_printed = buffer.getvalue()
        profit = float(what_was_printed.split("\n")[5].split(' = ')[1])
        stakes = eval(what_was_printed.split("\n")[6].split(' = ')[1])
    teams = match.split(" - ")
    if get_nb_outcomes(sport) == 3:
        teams.insert(1, "Nul")
    totals = [round(stake_i * odd_i, 2) for stake_i, odd_i in zip(stakes, best_odds)]
    table = {"Issue": teams, "Bookmaker": bookmakers, "Cote": best_odds, "Mise": stakes, "Total": totals}
    text = tabulate.tabulate(table, headers='keys', tablefmt='fancy_grid')
    window["RESULT_ODDS"].update(text + "\nPlus-value : {}".format(profit), visible=True)
    if sys.platform.startswith("win"):
        copy_to_clipboard(text)
예제 #10
0
def best_combine_reduit(matches,
                        combinaison_boostee,
                        site_combinaison,
                        mise,
                        sport,
                        cote_boostee=0):
    def get_odd(combinaison, matches, site_combinaison=None):
        sites = [
            'betclic', 'betstars', 'bwin', 'france_pari', 'joa', 'netbet',
            'parionssport', 'pasinobet', 'pmu', 'unibet', 'winamax', 'zebet'
        ]
        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 sportsbetting.ODDS[sport][match]["odds"].keys():
                        odd *= sportsbetting.ODDS[sport][match]["odds"][site][
                            i]
                    else:
                        break
            if odd > best_odd:
                best_odd = odd
                best_site = site


#         print(best_odd, best_site)
        return best_odd, best_site

    odds = {}
    for match in matches:
        odds[match] = sportsbetting.ODDS[sport][match]
    best_combinaison = []
    best_cotes = []
    best_sites = []
    best_gain = -mise
    best_i = -1
    for combinaisons in combine_reduit_rec(combinaison_boostee, 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])
        new_gain = gain2(cotes, i_boost, mise)
        if new_gain > best_gain:
            best_cotes = cotes
            best_sites = sites
            best_combinaison = combinaisons
            best_gain = new_gain
            best_i = i_boost
    matches_name = " / ".join(matches)
    print(matches_name)
    mises = mises2(best_cotes, mise, best_i)
    out = {}

    def get_issue(match, i, sport):
        if i == float("inf"):
            return
        elif sport in ["basketball", "tennis"]:
            return match.split(" - ")[i]
        elif i == 1:
            return "Nul"
        else:
            return match.split(" - ")[i // 2]

    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 = [
        'betclic', 'betstars', 'bwin', 'france_pari', 'joa', 'netbet',
        'parionssport', 'pasinobet', 'pmu', 'unibet', 'winamax', 'zebet'
    ]
    odds = {
        site:
        [get_odd(combine, matches, site)[0] for combine in best_combinaison]
        for site in sites
    }

    pprint(
        {
            "date":
            max(date for date in [
                sportsbetting.ODDS[sport][match]["date"] for match in matches
            ]),
            "odds":
            odds
        },
        compact=True)
    print("plus-value =", round(best_gain, 2))
    print()
    print(
        "Répartition des mises (les totaux affichés prennent en compte les éventuels freebets):"
    )
    for combine, mise, cote, site in zip(best_combinaison, mises, 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)
        sites_bet_combinaison = {
            site: {
                "mise": round(mise, 2),
                "cote": round(cote, 2)
            },
            "total": round(round(mise, 2) * cote, 2)
        }
        print(name_combine + " " * diff + "\t", sites_bet_combinaison)
예제 #11
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)
예제 #12
0
def best_matches_combine2(site,
                          minimum_odd,
                          bet,
                          sport,
                          minimum_odd_selection,
                          date_max=None,
                          time_max=None,
                          date_min=None,
                          time_min=None):
    nb_matches = 2
    all_odds = filter_dict_dates(sb.ODDS[sport], date_max, time_max, date_min,
                                 time_min)
    all_odds = filter_dict_minimum_odd(all_odds, minimum_odd_selection, site)
    odds_combine_opt = [{} for _ in range(6)]
    nb_combine = binomial(len(all_odds), nb_matches)
    sb.PROGRESS = 0
    combis = cotes_combine_optimise([[1 for _ in range(3)]
                                     for i in range(nb_matches)])[1]
    print(combis)

    def compute_all_odds_combine_optimise(nb_combine, combine,
                                          odds_combine_opt):
        sb.PROGRESS += 100 / nb_combine
        try:
            cotes_combination = cotes_combine_reduit_all_sites(
                *[match[1] for match in combine])
            for i in range(6):
                odds_combine_opt[i][" / ".join([match[0] for match in combine
                                                ])] = cotes_combination[i]


#                 combis[i] = cotes_combination[i][1]
        except KeyError:
            pass

    ThreadPool(4).map(
        lambda x: compute_all_odds_combine_optimise(nb_combine, x,
                                                    odds_combine_opt),
        combinations(all_odds.items(), nb_matches))
    sb.PROGRESS = 0
    odds_function = get_best_odds(False)
    profit_function = get_profit(bet, False)
    criteria = lambda odds_to_check, i: all(odd >= minimum_odd
                                            for odd in odds_to_check)
    for i, combination in enumerate(combis):
        sb.ALL_ODDS_COMBINE = odds_combine_opt[i]
        #         display_function = lambda odds_to_check, i: mises_combine_optimise(odds_to_check, combination, bet, minimum_odd, True)
        #         result_function = lambda odds_to_check, i: mises_combine_optimise(odds_to_check, combination, bet, minimum_odd, False)
        display_function = lambda best_overall_odds, best_rank: mises2(
            best_overall_odds, bet, best_rank, True)
        result_function = lambda best_overall_odds, best_rank: mises2(
            best_overall_odds, bet, best_rank, False)
        best_match_base(odds_function,
                        profit_function,
                        criteria,
                        display_function,
                        result_function,
                        site,
                        sport,
                        date_max,
                        time_max,
                        date_min,
                        time_min,
                        True,
                        nb_matches,
                        combine_opt=True)
예제 #13
0
def best_combine_reduit(matches, combinaison_boostee, cote, site_booste,
                        mise_max):
    def get_odd(combinaison, matches):
        sites = [
            'betclic', 'betstars', 'bwin', 'france_pari', 'joa', 'netbet',
            'parionssport', 'pasinobet', 'pmu', 'unibet', 'winamax', 'zebet'
        ]
        best_odd = 1
        best_site = ""
        for site in sites:
            odd = 1
            for i, match in zip(combinaison, matches):
                if i != -1:
                    if site in sportsbetting.ODDS["football"][match][
                            "odds"].keys():
                        odd *= sportsbetting.ODDS["football"][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] = sportsbetting.ODDS["football"][match]
    best_combinaison = []
    best_cotes = []
    best_sites = []
    best_gain = -mise_max
    best_i = -1
    for combinaisons in combine_reduit(len(matches), combinaison_boostee):
        cotes = []
        sites = []
        for i, combinaison in enumerate(combinaisons):
            if list(combinaison) == combinaison_boostee:
                cotes.append(cote)
                sites.append(site_booste)
                i_boost = i
            else:
                res = get_odd(combinaison, matches)
                cotes.append(res[0])
                sites.append(res[1])
        new_gain = gain2(cotes, i_boost, mise_max)
        if new_gain > best_gain:
            best_cotes = cotes
            best_sites = sites
            best_combinaison = combinaisons
            best_gain = new_gain
            best_i = i_boost
    print(best_gain)
    mises = mises2(best_cotes, mise_max, best_i)
    #     return best_cotes, best_sites, best_combinaison
    out = {}

    def get_issue(match, i):
        if i == -1:
            return
        elif i == 1:
            return "Nul"
        else:
            return match.split(" - ")[i // 2]

    opponents = []
    for match in matches:
        opponents_match = match.split(" - ")
        opponents_match.insert(1, "Nul")
        opponents.append(opponents_match)
    nb_chars = max(map(lambda x: len(" / ".join(x)), product(*opponents)))
    for combine, mise, cote, site in zip(best_combinaison, mises, best_cotes,
                                         best_sites):
        names = [
            opponents_match[i] if i > -1 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)
        sites_bet_combinaison = {
            site: {
                "mise": mise,
                "cote": cote
            },
            "total": mise * cote
        }
        print(name_combine + " " * diff + "\t", sites_bet_combinaison)