Exemplo n.º 1
0
        public static async Task <List <Pending> > GetPending()
        {
            try
            {
                var client = new FirebaseClient(_config);

                FirebaseResponse response = await client.GetAsync($"pending_game_evaluation");

                if (string.IsNullOrEmpty(response.Body) || response.Body == "null")
                {
                    return(new List <Pending>());
                }

                var parsed = JObject.Parse(response.Body).Children().Children();

                var pendingList = new List <Pending>();

                foreach (var item in parsed)
                {
                    var pending = new Pending
                    {
                        CustomId   = item.SelectToken("CustomId").Value <string>(),
                        DatePlaced = item.SelectToken("DatePlaced").Value <string>(),
                        Sport      = item.SelectToken("Sport").Value <string>()
                    };

                    pendingList.Add(pending);
                }

                return(pendingList);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error getting pending games. See error message: " + e.Message);
                return(new List <Pending>());
            }
        }
Exemplo n.º 2
0
        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);
            }
        }