/* Проверяем response после сделанной ставки(place bet) */ protected void ManagePlaceResult(Bet bet, JToken placeResult) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var responseCoupon = placeResult["responseCoupon"]; var errors = responseCoupon["generalErrors"]; if (errors != null) { IdentifyError(bet, errors); return; } SetMatchedSingleOdds(responseCoupon); var historyCoupon = responseCoupon["historyCoupon"]; var totalStake = (int?)historyCoupon["stake"] ?? 0; var countStakes = historyCoupon["systems"]?.First()["bets"]?.Count() ?? 0; var unitStake = totalStake / countStakes; CurrentBetslip.Status = BetslipStatus.Placed; var betToPlace = CurrentBetslip.GetBetToPlace(); CurrentBetslip.SetMatched(betToPlace, (double)unitStake / 1000, (double)totalStake / 1000, bet.EW); } }
/* Проверяем, если лошади добавлены из одной скачки */ private void CheckSameEvent(JToken outcomesIds) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var sameEvent = string.Empty; var seenIds = new List <long>(); var horsesInfo = new List <HorseInfo>(); foreach (long outcomeId in outcomesIds.Select(outcomeId => outcomeId.First())) { var horse = (HorseInfo)CurrentBetslip.GetSelectionByKey(outcomeId).Data; horsesInfo.Add(horse); } var eventIds = horsesInfo.Select(horse => horse.Race.Id) ?? new List <long>(); foreach (long id in eventIds) { var sameIds = eventIds.Where(eventId => eventId == id && !seenIds.Contains(id)); if (sameIds.Count() > 1) { var names = horsesInfo.Where(horse => horse.Race.Id == id).Select(horse => horse.Name); sameEvent += "The same event: " + string.Join(" & ", names) + "\n"; seenIds.Add(id); } } if (!string.IsNullOrEmpty(sameEvent)) { throw new Exception(sameEvent); } } }
public override double GetBalance() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { var isSuccessBalance = IsSuccessBalance(out decimal balance); if (!isSuccessBalance) { Login(); if (!IsSuccessBalance(out balance)) { throw new Exception("Error login"); } } return((double)balance); } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller()} failed"); throw ex.PreserveStackTrace(); } } }
public void ChooseBet(Bet bet) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { CurrentBetslip.SetBetToPlace(bet); } }
public void AddSelectionToBetslip(SelectionRequest selectionRequest) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { var horse = FindBet(selectionRequest); Logger.LogDebug("horse was found:\n" + horse.GetDump()); var selection = new Selection(horse.Id, selectionRequest) { Data = horse, Odds = (double)horse.Odds, Stake = 0, EW = false }; CurrentBetslip.AddSelection(selection); GenerateMultiple(); } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller() } failed"); throw ex.PreserveStackTrace(); } } }
/* Обновляем коэффициент при ошибке "VET_ODDS_CHANGED" */ private void UpdateOdds(Bet bet, int newOdds) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var selection = CurrentBetslip.GetSelectionByKey(bet.Key); var horseInfo = (HorseInfo)selection.Data; horseInfo.Odds = newOdds / 1000; horseInfo.SelectedOutcomeJData["approvedOdds"] = newOdds; CurrentBetslip.UpdateSelection(selection.Key, (double)newOdds / 1000, selection.Stake, selection.EW, horseInfo); } }
private List <RaceInfo> GetAllRacesAtTime(JToken allMeetings, DateTime selectionRaceStartTime) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var allRaces = ExtractRaces(allMeetings); var racesAtTime = allRaces.FindAll(item => item.StartTime.ToString("dd:HH:mm") == selectionRaceStartTime.ToString("dd:HH:mm")); return(racesAtTime); } }
public void Get_Success_ValidateCoupon_Tests() { using (logger.BeginScope(LoggerHelper.GetCaller())) { var toValidateCoupon = helper.CreateCouponToValidate(betType, outcomes, true); //logger.LogDebug("Generated to validate coupon:\n" + toValidateCoupon.GetDump()); //logger.LogDebug("Validate coupon was got from site:\n" + ToValidateCouponBySite["requestCoupon"].GetDump()); Assert.IsTrue(JToken.DeepEquals(toValidateCoupon, ToValidateCouponBySite["requestCoupon"])); } }
public void Get_Success_PlaceBetCoupon_Tests() { using (logger.BeginScope(LoggerHelper.GetCaller())) { var placeBet = helper.GenerateCouponToPlaceBet(outcomes, CheckedCouponBySite, betType, stake, ew); logger.LogDebug("Validate coupon:\n" + CheckedCouponBySite.GetDump()); logger.LogDebug("Generated place bet coupon:\n" + placeBet.GetDump()); logger.LogDebug("Place bet coupon was got from site:\n" + PlaceBetBySite.GetDump()); Assert.IsTrue(JToken.DeepEquals(placeBet, PlaceBetBySite)); } }
public void ClearBetslip() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { CurrentBetslip.ClearBetslip(); } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller()} failed"); throw ex.PreserveStackTrace(); } } }
public void Place() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { var bet = GetBetToPlace(); var outcomes = CreateOutcomes(bet); var toCheckCoupon = _helper.CreateCouponToValidate(bet.BetType, outcomes, _isLogged); Logger.LogDebug("Was generated to validate coupon: " + toCheckCoupon.GetDump()); if (_isLogged && IsValidateCoupon(SessionToken, toCheckCoupon, out JToken responseCheckCoupon)) { var checkedCoupon = responseCheckCoupon["requestCoupon"]; var placeBet = _helper.GenerateCouponToPlaceBet(outcomes, checkedCoupon, bet.BetType, bet.Stake, bet.EW); Logger.LogDebug("Was generated placebet: " + placeBet.GetDump()); var placeResult = _web.Place(SessionToken, placeBet); ManagePlaceResult(bet, placeResult); } //For test without authentification else if (IsValidateCouponNoAuth(toCheckCoupon, out responseCheckCoupon)) { //For test Logger.LogDebug("Checked coupon: " + responseCheckCoupon.GetDump()); var checkedCoupon = responseCheckCoupon["requestCoupon"]; var placeBet = _helper.GenerateCouponToPlaceBet(outcomes, checkedCoupon, bet.BetType, bet.Stake, bet.EW); Logger.LogDebug("Was generated placebet: " + placeBet.GetDump()); //var jsonResult = ""; //var placeResult = JToken.Parse(jsonResult); //ManagePlaceResult(bet, placeResult); } else { Logger.LogDebug($"Validate coupon is fault.\n{responseCheckCoupon.GetDump()}"); ManageValidateResult(bet, responseCheckCoupon); } } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller()} failed"); throw ex.PreserveStackTrace(); } } }
public void StartListening() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { _remoteEvent?.Dispose(); _remoteEvent = new FbRemoteEvent(ConnectionString); var events = _triggers.Select(item => item.EventName).ToList(); _remoteEvent.QueueEvents(events.ToArray()); _remoteEvent.RemoteEventCounts += OnDbEvent; var eventsStr = events.Aggregate("", (current, item) => current + $"{item} "); Logger.LogDebug($"Listening events: {eventsStr}"); } }
public void RemoveSelectionFromBetslip(SelectionRequest selectionQuery) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { var selection = CurrentBetslip.GetSelectionByQuery(selectionQuery); CurrentBetslip.RemoveSelection(selection, true); GenerateMultiple(); } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller()} failed"); throw ex.PreserveStackTrace(); } } }
public void SetRequested(SelectionRequest selectionRequest, double?stake, bool?ew) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { if ((stake.HasValue ^ ew.HasValue) == false) { throw new Exception($"Stake or ew must have value, stake: {stake} ew: {ew}"); } var selection = CurrentBetslip.GetSelectionByQuery(selectionRequest); CurrentBetslip.SetRequested(selection, stake, ew); if (stake.HasValue) { CurrentBetslip.UpdateSelection( selection.Key, selection.Odds, stake.Value, selection.EW, selection.Data, selection.MinStake ?? _minStake ?? 0.1, selection.MaxStake); } if (ew.HasValue) { CurrentBetslip.UpdateSelection( selection.Key, selection.Odds, selection.Stake, (bool)ew, selection.Data, selection.MinStake ?? _minStake ?? 0.1, selection.MaxStake); } } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller()} failed"); UpdateBetslip(); throw ex.PreserveStackTrace(); } } }
private void SetMatchedSingleOdds(JToken responseCoupon) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var historyCoupon = responseCoupon["historyCoupon"]; foreach (var system in historyCoupon["systems"]) { var betOutcomes = system["betOutcomes"]; for (int i = 0; i < betOutcomes?.Count(); i++) { var id = (long)betOutcomes[i]["id"]; var odds = (int)betOutcomes[i]["playedOdds"]; var selection = CurrentBetslip.GetSelectionByKey(id); CurrentBetslip.SetMatchedOdds(selection, (double)odds / 1000); } } } }
public void EnsureTriggerRemoved(TriggerMetaData trigger) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var triggerName = trigger.Name; var cmdQuery = $"DROP TRIGGER {triggerName}"; ExecuteNonQuery(cmdQuery, (ex) => { var fbEx = (FbException)ex; if (fbEx.ErrorCode == 335544351) // trigger already deleted { Logger.LogWarning($"Trigger already removed: {trigger.Name}"); } else { throw ex; } }); } }
public override void Login() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { if (LoadSessionAndInit(_sessionFile)) { return; } _web.Login(UserName, Password); if (!IsSuccessInitData()) { Logger.LogDebug("Login failed!"); throw new AuthenticationException($"Login failed"); } Logger.LogDebug("Login completed"); StartRefreshToken(); } }
public override void Login() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { if (LoadSessionAndInit(_sessionFile)) { _isLogged = true; return; } var logged = _web.Login(UserName, Password, FirstName); _isLogged = (bool)logged["ok"]; if (!_isLogged || !IsSuccessInitData()) { Logger.LogDebug("Login failed!"); throw new AuthenticationException($"Login failed"); } Logger.LogDebug("Login completed"); } }
/* Проверяем результат валидации coupon-а на ошибки * "betErrors": [ * {"betIndex": 0, * "errors": [{"type": "VET_INVALID_BET"}] * }], * "outcomeErrors": [ * {"outcomeId": 2699153202, * "outcomeIds": [2699153202], * "errors": [ * {"type": "VET_ODDS_CHANGED", * "arguments": ["6000"]} * ]}]*/ protected void ManageValidateResult(Bet bet, JToken responseCheckCoupon) { using (Logger.BeginScope(LoggerHelper.GetCaller())) { var outcomeErrors = responseCheckCoupon["outcomeErrors"]; if (outcomeErrors != null) { for (var i = 0; i < outcomeErrors.Count(); i++) { var id = (long)outcomeErrors[i]["outcomeId"]; var betError = CurrentBetslip.GetSelectionByKey(id); IdentifyError(betError, outcomeErrors[i]["errors"]); } } if (bet.BetType.Code != BetTypeCode.Single) { bet.AddError(BetError.Unexpected); } CheckSameEvent(responseCheckCoupon["requestCoupon"]?["outcomeIds"]); } }
public override double GetBalance() { using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { var isLogged = IsSuccessInitData(); if (!isLogged) { Login(); } return((double)UserContext.userBalance.ExtractDecimal()); } catch (Exception ex) { Logger.LogError(ex, $"{ LoggerHelper.GetCaller()} failed"); throw ex.PreserveStackTrace(); } } }
private HorseInfo FindBet(SelectionRequest selection) { HorseInfo horse = null; using (Logger.BeginScope(LoggerHelper.GetCaller())) { try { JToken allRacesJData = _web.GetHorseRacing(); var racesAtTime = GetAllRacesAtTime(allRacesJData, selection.RaceStartTime); var firstRace = SortRacesBySimilarity(racesAtTime, selection.EventName).FirstOrDefault(); JToken raceHorsesJData = _web.GetBetoffer(firstRace.Id); var horses = ExtractHorses(raceHorsesJData); horse = FindHorseByName(horses, selection.Name); horse.Race = firstRace; return(horse); } catch (Exception ex) { throw new Exception($"Horse racing or betoffer are not found!\n{ex.Message}"); } } }