public async Task <ActionResult <IEnumerable <Game> > > GetOddsFromDataFeed( DataFeedId dataFeedId, SportId sportId, CancellationToken cancellation) { return(Ok(await _feedManager.GetOddsFromDataFeed(sportId, dataFeedId, cancellation))); }
public async Task <IEnumerable <Game> > GetOdds(SportId sport, CancellationToken cancellation = default) { var client = _httpClientFactory.CreateClient(ClientName); var request = new HttpRequestMessage(HttpMethod.Get, GetOddsRoute(sport)); using var response = await client.SendAsync(request, cancellation); if (!response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(cancellation); _logger.LogError("Received response with status code {StatusCode} and message: {Message}", response.StatusCode, content); throw new HttpRequestException(content); } var result = await JsonSerializer.DeserializeAsync <Models.GetOddsResponse>( await response.Content.ReadAsStreamAsync(cancellation), cancellationToken : cancellation); if (!result.Success) { throw new HttpRequestException("Request was not successfull"); } return(_responseConverter.Convert(result)); }
/// <summary> /// Determines whether the current mapping can map market with provided specifiers associated with provided producer and sport /// </summary> /// <param name="producer">The <see cref="IProducer" /> associated with the market</param> /// <param name="sportId">The <see cref="URN" /> specifying the sport associated with the market</param> /// <param name="specifiers">The market specifiers</param> /// <returns>True if the current mapping can be used to map the specified market. False otherwise</returns> /// <exception cref="InvalidOperationException">The provided specifiers are not valid</exception> public bool CanMap(IProducer producer, URN sportId, IReadOnlyDictionary <string, string> specifiers) { if (!ProducerIds.Contains(producer.Id) || SportId != null && !SportId.Equals(sportId)) { return(false); } return(_validator?.Validate(specifiers) ?? true); }
/// <summary> /// Asynchronous export item's properties /// </summary> /// <returns>An <see cref="ExportableCI"/> instance containing all relevant properties</returns> public Task <ExportableCI> ExportAsync() { var exportable = new ExportableCategoryCI { Id = Id.ToString(), Name = new ReadOnlyDictionary <CultureInfo, string>(Name), SportId = SportId.ToString(), TournamentIds = TournamentIds != null ? new ReadOnlyCollection <string>(TournamentIds.Select(id => id.ToString()).ToList()) : null, CountryCode = CountryCode }; return(Task.FromResult <ExportableCI>(exportable)); }
public async Task <IEnumerable <Game> > GetOddsFromDataFeed(SportId sportId, DataFeedId dataFeedId, CancellationToken cancellation) { var key = GetFeedKey(sportId, dataFeedId); var result = await _cache.GetAsync <IEnumerable <Game> >(key, cancellation); if (result == null) { var dataFeed = GetDataFeed(dataFeedId); result = await dataFeed.GetOdds(sportId, cancellation); await _cache.SetAsync(key, result, dataFeed.Throttle, cancellation); } return(result); }
public async Task <ActionResult <IEnumerable <Game> > > CalculateArbitrageFromFeed(SportId sportId, DataFeedId dataFeedId, CancellationToken cancellation) { var games = await _feedManager.GetOddsFromDataFeed(sportId, dataFeedId, cancellation); return(Ok(_arbitrageCalculator.CalculateArbitrageOpportunities(games).ToList())); }
private string GetOddsRoute(SportId sport) { var convertedSport = _sportConveter.Convert(sport); return($"odds?sport={convertedSport.Key}®ion=us&dateFormat=iso"); }
private static string GetFeedKey(SportId sportId, DataFeedId dataFeedId) { return($"{{{dataFeedId}}}:{{{sportId}}}"); }