Esempio n. 1
0
def best_combine_reduit_interface(window, values, visible_combi_opt):
    stakes_list = []
    match_list = []
    combi_boostee = []
    sport = values["SPORT_COMBI_OPT"][0]
    issues = ["1", "N", "2"
              ] if sport and get_nb_issues(sport) == 3 else ["1", "2"]
    for i in range(visible_combi_opt):
        match_list.append(values["MATCH_COMBI_OPT_" + str(i)])
        for j, issue in enumerate(issues):
            if values[issue + "_RES_COMBI_OPT_" + str(i)]:
                combi_boostee.append(j)
                break
    site_booste = values["SITE_COMBI_OPT"]
    mise_max = float(values["STAKE_COMBI_OPT"])
    cote_boostee = float(values["ODD_COMBI_OPT"])
    old_stdout = sys.stdout  # Memorize the default stdout stream
    sys.stdout = buffer = io.StringIO()
    best_combine_booste(match_list, combi_boostee, site_booste, mise_max,
                        sport, cote_boostee)
    sys.stdout = old_stdout  # Put the old stream back in place
    what_was_printed = buffer.getvalue()
    match, date = infos(what_was_printed)
    window["MATCH_COMBI_OPT"].update(match)
    window["DATE_COMBI_OPT"].update(date)
    window["ODDS_COMBI_OPT"].update(visible=True)
    window["RESULT_COMBI_OPT"].update(stakes(what_was_printed), visible=True)
    window["TEXT_COMBI_OPT"].update(visible=True)
    for i, elem in enumerate(indicators(what_was_printed)):
        window["INDICATORS_COMBI_OPT" + str(i)].update(elem[0].capitalize(),
                                                       visible=True)
        window["RESULTS_COMBI_OPT" + str(i)].update(elem[1], visible=True)
    buffer.close()
    sportsbetting.ODDS_INTERFACE = what_was_printed
def best_match_under_conditions2(site,
                                 minimum_odd,
                                 stake,
                                 sport="football",
                                 date_max=None,
                                 time_max=None,
                                 date_min=None,
                                 time_min=None):
    all_odds = filter_dict_dates(sportsbetting.ODDS[sport], date_max, time_max,
                                 date_min, time_min)
    best_profit = -float("inf")
    best_match = None
    best_overall_odds = None
    sites = None
    nb_matches = len(all_odds)
    n = get_nb_issues(sport)
    for match in all_odds:
        sportsbetting.PROGRESS += 100 / nb_matches
        if site in all_odds[match]['odds']:
            odds_site = all_odds[match]['odds'][site]
            best_odds = copy.deepcopy(odds_site)
            best_sites = [site for _ in range(n)]
            for odds in all_odds[match]['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 odd_i, site_i in zip(best_odds, best_sites):
                if odd_i < 1.1 and site_i != "pmu":
                    break
            else:
                profit = gain3(odds_site, best_odds, stake, minimum_odd)
                if profit > best_profit:
                    best_profit = profit
                    best_odds_site = copy.deepcopy(odds_site)
                    best_best_odds = copy.deepcopy(best_odds)
                    best_match = match
                    stakes, best_indices = mises3(odds_site, best_odds, stake,
                                                  minimum_odd)
                    sites = [
                        site if i in best_indices else best_sites[i]
                        for i in range(n)
                    ]
    if best_match:
        print(best_match)
        pprint(all_odds[best_match])
        mises3(best_odds_site, best_best_odds, stake, minimum_odd, True)
        afficher_mises_combine([best_match], [sites], [stakes],
                               all_odds[best_match]["odds"], sport)
    else:
        print("No match found")
     except KeyError:
         window['MATCHES_ODDS'].update(values=[])
 elif event == "MATCHES_ODDS":
     odds_match_interface(window, values)
 elif event == "DELETE_ODDS":
     delete_odds_interface(window, values)
     pickle.dump(sportsbetting.ODDS, open(PATH_DATA, "wb"))
 elif event == "ADD_COMBI_OPT":
     sport = ""
     if values["SPORT_COMBI_OPT"]:
         sport = values["SPORT_COMBI_OPT"][0]
     if visible_combi_opt < 9:
         window["MATCH_COMBI_OPT_" +
                str(visible_combi_opt)].update(visible=True)
         issues = ["1", "N", "2"
                   ] if sport and get_nb_issues(sport) == 3 else ["1", "2"]
         for issue in issues:
             window[issue + "_RES_COMBI_OPT_" +
                    str(visible_combi_opt)].update(visible=True)
         visible_combi_opt += 1
 elif event == "REMOVE_COMBI_OPT":
     if visible_combi_opt > 1:
         visible_combi_opt -= 1
         window["MATCH_COMBI_OPT_" +
                str(visible_combi_opt)].update(visible=False)
         for issue in ["1", "N", "2"]:
             window[issue + "_RES_COMBI_OPT_" +
                    str(visible_combi_opt)].update(visible=False)
 elif event == "BEST_COMBI_OPT":
     best_combine_reduit_interface(window, values, visible_combi_opt)
 elif event == "SPORT_COMBI_OPT":
Esempio n. 4
0
def best_match_stakes_to_bet(stakes, nb_matches=1, sport="football", date_max=None, time_max=None, identical_stakes=False):
    second_sites = {stake[1] for stake in stakes}
    main_sites = ['betclic', 'betstars', 'bwin', 'france_pari', 'joa', 'netbet',
                  'parionssport', 'pasinobet', 'pmu', 'unibet', 'winamax', 'zebet']
    all_odds = filter_dict_dates(sb.ODDS[sport], date_max, time_max)
    best_profit = -sum(stake[0] for stake in stakes)
    n = get_nb_issues(sport) ** nb_matches
    nb_stakes = len(stakes)
    all_odds_combine = {}
    combis = list(combinations(all_odds.items(), nb_matches))
    nb_combis = len(combis)
    best_combine = None
    best_bets = None
    main_site_odds = []
    main_sites_distribution = []
    sb.PROGRESS = 0
    for i, combine in enumerate(combis):
        sb.PROGRESS += 100 / nb_combis
        match_combine = " / ".join([match[0] for match in combine])
        all_odds_combine[match_combine] = cotes_combine_all_sites(*[match[1] for match in combine])
        for main0 in main_sites:
            try:
                main_sites_distribution = [main0 for _ in range(n)]
                main_site_odds = copy.deepcopy(all_odds_combine[match_combine]["odds"][main0])
                break
            except KeyError:
                pass
        for main in main_sites[:i] + main_sites[i + 1:]:
            try:
                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
            except KeyError:
                pass
        second_odds = {second_site: all_odds_combine[match_combine]["odds"][second_site]
                       for second_site in second_sites if second_site in all_odds_combine[match_combine]["odds"]}
        if not second_odds:
            continue
        dict_combine_odds = copy.deepcopy(second_odds)
        for perm in permutations(range(n), nb_stakes):
            valid_perm = True
            defined_second_sites = [[perm[j], stake[0], stake[1]]
                                    for j, stake in enumerate(stakes)]
            for j, stake in enumerate(stakes):
                if dict_combine_odds[defined_second_sites[j][2]][defined_second_sites[j][0]] < stake[2]:
                    valid_perm = False
                    break
            if not valid_perm:
                if identical_stakes:
                    break
                continue
            defined_bets_temp = defined_bets(main_site_odds, dict_combine_odds,
                                             main_sites_distribution,
                                             defined_second_sites)
            profit = defined_bets_temp[0] - np.sum(defined_bets_temp[1])
            if profit > best_profit:
                best_profit = profit
                best_combine = combine
                best_bets = defined_bets_temp
            if identical_stakes:
                break
    if best_combine:
        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("Plus-value =", round(best_profit, 2))
        print("Gain référence =", round(best_bets[0], 2))
        print("Somme des mises =", round(np.sum(best_bets[1]), 2))
        afficher_mises_combine([x[0] for x in best_combine], best_bets[2], best_bets[1],
                               all_odds_combine[best_match_combine]["odds"], sport)
    else:
        print("No match found")