public static Event ResolveMatchDraw(int eventID, string oneOfTheFighters)
        {
            var otherFighter = new BetLine();

            using (var session = RavenDocStore.Store.OpenSession())
            {
                var fullEvent = session.Load <Event>(eventID);
                if (fullEvent == null)
                {
                    throw new Exception("event not found. id: " + eventID);
                }

                var fighter = fullEvent.BetLines.FirstOrDefault(x => x.FighterName == oneOfTheFighters);
                if (fighter == null)
                {
                    throw new Exception("bet line not found for event: " + eventID + ", name: " + oneOfTheFighters);
                }
                otherFighter = fullEvent.BetLines
                               .Where(x => x.MatchNumber == fighter.MatchNumber)
                               .FirstOrDefault(x => x.FighterName != oneOfTheFighters);
                if (otherFighter == null)
                {
                    throw new Exception("other fighter not found for " + oneOfTheFighters + ". Match Number: " + fighter.MatchNumber);
                }
                fighter.Result      = Result.Lose;
                otherFighter.Result = Result.Lose;
                session.SaveChanges();
            }
            EventService.CheckForZeroOutRefunds(eventID);
            BetService.ResolveAllBetsAsDraw(eventID, oneOfTheFighters, otherFighter.FighterName);
            return(EventService.GetFullEvent(eventID));
        }
Esempio n. 2
0
        public void SetupCheckedBets_ShouldSetCorrectLosingBetAccountBalance_WithValidParams(string inputString, FinalResultMarks finalResultMark)
        {
            this.ResetParams();
            var account = new BetfairAccount(this.accountName, this.accountBalance, this.accountCurrency, this.accountRake);
            var line    = new BetLine(account, this.lineName, this.lineStepAmount, this.decreasingStepValue);
            var bet     = new RegularBet(this.mockedMatch.Object, line, finalResultMark.ToString(), this.amount, this.coefficient, this.mockedTipster.Object);

            var mockedResult = new Mock <IFinalResult>();

            mockedResult.Reset();
            mockedResult.Setup(r => r.GetMark()).Returns(inputString);


            this.mockedMatch.Setup(m => m.Results).Returns(new Dictionary <ResultType, IResult>()
            {
                [ResultType.Final] = mockedResult.Object
            });

            var collectionOfBets = new List <IBet>()
            {
                bet
            };

            var betController = new BetController();

            betController.SetupCheckedBets(collectionOfBets);

            Assert.AreEqual(startAccountValue - this.amount, bet.Line.Account.Balance);
        }
        public static Event ResolveMatch(int eventID, String winnerName)
        {
            var loser = new BetLine();

            using (var session = RavenDocStore.Store.OpenSession())
            {
                var fullEvent = session.Load <Event>(eventID);
                if (fullEvent == null)
                {
                    throw new Exception("event not found. id: " + eventID);
                }

                var winner = fullEvent.BetLines.FirstOrDefault(x => x.FighterName == winnerName);
                if (winner == null)
                {
                    throw new Exception("bet line not found for event: " + eventID + ", winner: " + winnerName);
                }
                loser = fullEvent.BetLines
                        .Where(x => x.MatchNumber == winner.MatchNumber)
                        .FirstOrDefault(x => x.FighterName != winnerName);
                if (loser == null)
                {
                    throw new Exception("loser not found for " + winnerName + ". Match Number: " + winner.MatchNumber);
                }
                winner.Result = Result.Win;
                loser.Result  = Result.Lose;
                session.SaveChanges();
            }
            EventService.CheckForZeroOutRefunds(eventID);
            BetService.ResolveAllBets(eventID, winnerName, loser.FighterName);
            return(EventService.GetFullEvent(eventID));
        }
Esempio n. 4
0
        public void RemoveBet_ShouldThrowNullArgumentException_WithNullBet()
        {
            var betLine = new BetLine(this.account, this.lineName, this.stepAmount, this.decreasingStepValue);

            Assert.That(
                () => betLine.RemoveBet(null),
                Throws.ArgumentNullException.With.Message.Contains(string.Format(EngineConstants.ObjectCannotBeNullErrorMessage, "Bet")));
        }
Esempio n. 5
0
        public void AddBet_ShouldThrowArgumentException_WhenTryingToAddSameBetTwice()
        {
            var betLine = new BetLine(this.account, this.lineName, this.stepAmount, this.decreasingStepValue);

            betLine.Bets.Add(this.mockedBet);

            Assert.That(
                () => betLine.AddBet(this.mockedBet),
                Throws.ArgumentException.With.Message.Contains(EngineConstants.SameBetToALineErrorMessage));
        }
Esempio n. 6
0
        public void RemoveBet_ShouldThrowArgumentException_WhenTryingToRemoveExistingBet()
        {
            var betLine = new BetLine(this.account, this.lineName, this.stepAmount, this.decreasingStepValue);

            betLine.Bets.Add(this.mockedBet);

            Assert.AreEqual(1, betLine.Bets.Count);

            betLine.RemoveBet(this.mockedBet);

            Assert.AreEqual(0, betLine.Bets.Count);
        }
        public static Event DeleteSingleLine(int eventID, BetLine line1, BetLine line2)
        {
            if (line1.MatchNumber != line2.MatchNumber)
            {
                return(null);
            }

            using (var session = RavenDocStore.Store.OpenSession())
            {
                var myEvent = session.Query <Event>()
                              .Where(x => x.Id == eventID)
                              .FirstOrDefault();
                if (myEvent == null)
                {
                    return(null);
                }

                // update the event to remove that specific line
                myEvent.BetLines.RemoveAll(x => x.MatchNumber == line1.MatchNumber);

                // delete all bets associated with the cancelled line
                var betsToDelete = session.Query <Bet>()
                                   .Where(x => x.EventID == eventID)
                                   .Where(x => x.IndividualBets.Any(b => b.MatchNumber == line1.MatchNumber))
                                   .ToArray();

                foreach (var bet in betsToDelete)
                {
                    session.Delete <Bet>(bet);
                }

                session.SaveChanges();
            }

            return(GetFullEvent(eventID));
        }
Esempio n. 8
0
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.OddsFeed.GetFeedUrl(this.apiBasketballLeagueId, this.apiBasketballSeasonKey);
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);

            if (!string.IsNullOrEmpty(rawJson))
            {
                var feed = Feeds.OddsFeed.FromJson(rawJson);

                int leagueSeasonId = dbContext.LeagueSeasons.First(x => x.ApiBasketballLeagueId == this.apiBasketballLeagueId && x.ApiBasketballSeasonKey == this.apiBasketballSeasonKey).LeagueSeasonId;
                var gameDict       = dbContext.Games.Where(x => x.LeagueSeasonId == leagueSeasonId).ToDictionary(x => x.ApiBasketballGameId, y => y.GameId);

                var apiOddsGames = feed.OddsGames.ToList();
                foreach (var apiOddsGame in apiOddsGames)
                {
                    if (gameDict.TryGetValue(apiOddsGame.Game.Id, out int gameId))
                    {
                        var allGameLines = dbContext.BetLines.Where(x => x.GameId == gameId).ToList();
                        foreach (var apiBookmaker in apiOddsGame.Bookmakers)
                        {
                            int bookmakerId = this.bookmakersDict[apiBookmaker.BookmakerId];
                            foreach (var apiBetType in apiBookmaker.BetTypes)
                            {
                                int betTypeId = this.betTypesDict[apiBetType.BetTypeId];
                                foreach (var apiBetLine in apiBetType.BetLines)
                                {
                                    decimal betLine  = apiBetLine.Line_Decimal;
                                    decimal?betValue = null;
                                    string  betName  = apiBetLine.BetName.ToUpperInvariant();
                                    if (betName.StartsWith("OVER ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("UNDER ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("HOME ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("AWAY ", StringComparison.InvariantCulture) ||
                                        betName.StartsWith("DRAW ", StringComparison.InvariantCulture))
                                    {
                                        string[] arrBetName = betName.Split(' ');
                                        betName = arrBetName[0];
                                        if (arrBetName.Length > 1)
                                        {
                                            string strBetValue = arrBetName[1];
                                            if (!string.IsNullOrEmpty(strBetValue))
                                            {
                                                betValue = decimal.Parse(strBetValue);
                                            }
                                        }
                                    }
                                    var dbBetLine = allGameLines.SingleOrDefault(x => x.GameId == gameId && x.BookmakerId == bookmakerId && x.BetTypeId == betTypeId && x.BetName == betName);
                                    if (dbBetLine == null)
                                    {
                                        dbBetLine = new BetLine
                                        {
                                            GameId      = gameId,
                                            BookmakerId = bookmakerId,
                                            BetTypeId   = betTypeId,
                                            BetName     = betName,
                                            BetValue    = betValue,
                                            Line        = betLine
                                        };
                                        allGameLines.Add(dbBetLine);
                                        dbContext.BetLines.Add(dbBetLine);
                                    }
                                    else if (dbBetLine.BetValue != betValue || dbBetLine.Line != betLine)
                                    {
                                        dbBetLine.BetValue = betValue;
                                        dbBetLine.Line     = betLine;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public void Constructor_ShouldPass_WithValidParams()
        {
            var betLine = new BetLine(this.account, this.lineName, this.stepAmount, this.decreasingStepValue);

            Assert.IsInstanceOf <BetLine>(betLine);
        }