private static List <LiveGame> GetOddsForCurrentLiveGames(IEnumerable <LiveGame> currentLiveGames) { foreach (var liveGame in currentLiveGames) { var currentOddsUrl = $"https://api.sofascore.com/api/v1/event/{liveGame.Id}/odds/1/all"; using WebClient webClient = new WebClient(); var liveGamesString = webClient.DownloadString(currentOddsUrl); var currentOdds = JsonConvert.DeserializeObject <Odds.RootObject>(liveGamesString); var fullTimeOdds = currentOdds.markets.Where(input => input.marketName == "Full time"); if (fullTimeOdds.Any()) { var closingOdds = fullTimeOdds.First(); var homeTeamClosingOdds = closingOdds.choices.FirstOrDefault(input => input.name == "1"); if (homeTeamClosingOdds != null) { liveGame.HomeTeamClosingOdds = OddsConverter.FractionToDecimalOdds(homeTeamClosingOdds.fractionalValue); } var awayTeamClosingOdds = closingOdds.choices.FirstOrDefault(input => input.name == "2"); if (awayTeamClosingOdds != null) { liveGame.AwayTeamClosingOdds = OddsConverter.FractionToDecimalOdds(awayTeamClosingOdds.fractionalValue); } liveGame.HasCurrentOdds = fullTimeOdds.Count() > 1; } } return((List <LiveGame>)currentLiveGames); }
public static void TwoPointO(LiveGame game, double maxDecimal) { if (game.SetAlgorithms.Any(input => input == 1)) { return; } var teamToWatch = game.HomeTeamClosingOdds < maxDecimal ? 1 : 2; var currentOddsUrl = $"https://api.sofascore.com/api/v1/event/{game.Id}/odds/1/all"; using WebClient webClient = new WebClient(); var liveGamesString = webClient.DownloadString(currentOddsUrl); var currentOdds = JsonConvert.DeserializeObject <Odds.RootObject>(liveGamesString); var fullTimeOdds = currentOdds.markets.Where(input => input.marketName == "Full time"); var currentFullTimeOdds = fullTimeOdds.Skip(1).FirstOrDefault(); var fraction = currentFullTimeOdds?.choices.FirstOrDefault(input => input.name == teamToWatch.ToString()); if (fraction == null) { return; } var odds = OddsConverter.FractionToDecimalOdds(fraction.fractionalValue); if (!(odds > 2.0)) { return; } var bet = new PlacedBet { Id = game.Id, Sport = (int)game.Sport, SportName = game.Sport.ToString(), AlgorithmId = 1, CustomId = game.CustomId, Game = game.GameName, OddsPlaced = odds, TournamentName = game.TournamentName, TournamentId = game.TournamentId, BetPlacedOnTeam = teamToWatch, }; var pending = new Pending { CustomId = game.CustomId, DatePlaced = DateTime.Today.ToString("yyyy-MM-dd"), Sport = game.Sport.ToString(), }; //var pending = new Dictionary<string, string> {{game.CustomId, DateTime.Today.ToString("yyyy-MM-dd")}}; var client = new FirebaseClient(_config); try { //Task<SetResponse> response = client.SetAsync($"placed_bets/{DateTime.Now.Year.ToString()}/{DateTime.Now.Month.ToString()}/{DateTime.Now.Day.ToString()}/{game.Sport.ToString()}/{game.CustomId}", bet); Task <SetResponse> response = client.SetAsync(Helper.GetPlacedBetUrl(DateTime.Now.ToString("yyyy-MM-dd"), game.CustomId, game.Sport.ToString()), bet); Task <SetResponse> reTask = client.SetAsync($"pending_game_evaluation/{game.CustomId}", pending); game.SetAlgorithms.Add(1); Console.WriteLine($"Placed bet on {bet.Game} ({bet.SportName}) on team {bet.BetPlacedOnTeam} to odds {bet.OddsPlaced}"); Console.WriteLine(); } catch (Exception e) { Console.WriteLine("Could not add the bet. See error message: " + e.Message); } }