public async Task <Market> GetMarketForEventAndMarketType(string eventId, string marketType)
        {
            MarketFilter filter = new MarketFilter()
            {
                EventIds = new HashSet <string>()
                {
                    eventId
                },
                MarketTypeCodes = new HashSet <string>()
                {
                    marketType
                }
            };
            HashSet <MarketProjection> marketProjections = new HashSet <MarketProjection>()
            {
                MarketProjection.EVENT,
                MarketProjection.MARKET_DESCRIPTION,
                MarketProjection.RUNNER_DESCRIPTION,
                MarketProjection.RUNNER_METADATA
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter            = filter,
                MarketProjections = marketProjections,
                MaxResults        = _maxResults
            };

            IEnumerable <Market> marketTypes = await _betfairBatchReader.Read(parameters);

            return(marketTypes?.FirstOrDefault(mt => mt.MarketType == marketType));
        }
        public async Task <IEnumerable <Domain.External.Competition> > GetCompetitionsByEventType(string eventTypeId)
        {
            var filter = new MarketFilter()
            {
                EventTypeIds = new HashSet <string>()
                {
                    eventTypeId
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            return(await _competitionsReader.Read(parameters));
        }
        public async Task <Domain.External.Competition> GetCompetition(string id)
        {
            var filter = new MarketFilter()
            {
                CompetitionIds = new HashSet <string>()
                {
                    id
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            return((await _competitionsReader.Read(parameters)).FirstOrDefault());
        }
        public async Task <Domain.External.EventType> GetEventTypeForCompetition(string competitionId)
        {
            var filter = new MarketFilter()
            {
                CompetitionIds = new HashSet <string>()
                {
                    competitionId
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            return((await _betfairBatchReader.Read(parameters)).FirstOrDefault());
        }
        public async Task <IEnumerable <MarketType> > GetMarketTypesByEventTypeId(string eventTypeId)
        {
            MarketFilter filter = new MarketFilter()
            {
                EventTypeIds = new HashSet <string>()
                {
                    eventTypeId
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            IEnumerable <MarketType> marketTypes = await _betfairBatchReader.Read(parameters);

            return(marketTypes);
        }
Пример #6
0
        public async Task <IEnumerable <Domain.External.Event> > GetEventsByCompetitionIdAndMarketType(string competitionId, string marketType)
        {
            var filter = new MarketFilter()
            {
                CompetitionIds = new HashSet <string>()
                {
                    competitionId
                },
                MarketTypeCodes = new HashSet <string>()
                {
                    marketType
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            return(await _eventsReader.Read(parameters));
        }
        public async Task <Domain.External.EventType> Read(string id)
        {
            var filter = new MarketFilter()
            {
                EventTypeIds = new HashSet <string>()
                {
                    id
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            IList <EventTypeResult> results = await _requestInvoker.Invoke <IList <EventTypeResult> >(BetfairMethod.ListEventTypes, parameters);

            var eventTypes = _mapper.Map <IEnumerable <Domain.External.EventType> >(results);

            return(eventTypes.FirstOrDefault());
        }
        public async Task <Domain.External.Competition> Read(string id)
        {
            var filter = new MarketFilter()
            {
                CompetitionIds = new HashSet <string>()
                {
                    id
                }
            };
            var parameters = new BetfairRequestParameters()
            {
                Filter = filter
            };

            IList <CompetitionResult> results = await _requestInvoker.Invoke <IList <CompetitionResult> >(BetfairMethod.ListCompetitions, parameters);

            var competitions = _mapper.Map <IEnumerable <Domain.External.Competition> >(results);

            return(competitions.FirstOrDefault());
        }
        public async Task <IEnumerable <TEntity> > Read(BetfairRequestParameters requestParameters)
        {
            IList <TBetfairDto> results = await _requestInvoker.Invoke <IList <TBetfairDto> >(_method, requestParameters);

            return(_mapper.Map <IEnumerable <TEntity> >(results));
        }
Пример #10
0
        public async Task <T> Invoke <T>(BetfairMethod method, BetfairRequestParameters requestParameters)
        {
            if (method == BetfairMethod.UnknownMethod)
            {
                throw new ArgumentOutOfRangeException("Method must be defined", "method");
            }
            string methodName = BetfairMethodExtensions.GetMethodName(method);

            IDictionary <string, object> args = new Dictionary <string, object>()
            {
                { "filter", requestParameters?.Filter ?? new MarketFilter() }
            };

            if (requestParameters != null && requestParameters.MarketProjections != null &&
                requestParameters.MarketProjections.Count > 0)
            {
                args["marketProjection"] = requestParameters.MarketProjections;
            }
            if (requestParameters != null && requestParameters.MaxResults != null &&
                requestParameters.MaxResults > 0 && requestParameters.MaxResults <= 1000)
            {
                args["maxResults"] = requestParameters.MaxResults;
            }

            LoginResponse loginResponse = await _authenticationClient.Login();

            if (loginResponse == null)
            {
                throw new AuthenticationException("LoginResponse is null");
            }
            else if (loginResponse.SessionToken == null)
            {
                throw new AuthenticationException("LoginResponse does not contain SessionToken");
            }
            else
            {
                _customHeaders[_sessionTokenHeader] = loginResponse.SessionToken;
            }

            var json = JsonConvert.SerializeObject(new JsonRequest {
                Method = _methodPrefix + methodName, Id = 1, Params = args
            },
                                                   new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var content = new StringContent(json, Encoding.UTF8, _requestContentType);

            foreach (var header in _customHeaders)
            {
                content.Headers.Add(header.Key, header.Value);
            }

            var timeoutPolicy  = _registry.Get <IAsyncPolicy>("thirtySecondTimeoutPolicy");
            var asyncGetPolicy = _registry.Get <IAsyncPolicy <HttpResponseMessage> >("thriceTriplingRetryPolicy");
            IAsyncPolicy <JsonResponse <T> > readStreamPolicy = Policy.HandleResult <JsonResponse <T> >(jr => jr.HasError)
                                                                .Or <TimeoutRejectedException>()
                                                                .WaitAndRetryAsync(_retryDelays);

            JsonResponse <T> response = await readStreamPolicy.ExecuteAsync(async() =>
            {
                HttpResponseMessage responseMessage = await asyncGetPolicy.ExecuteAsync(async() =>
                                                                                        await timeoutPolicy.ExecuteAsync(async token =>
                                                                                                                         await _httpClient.PostAsync("", content, token), CancellationToken.None));

                if (!responseMessage.IsSuccessStatusCode)
                {
                    throw new HttpResponseException(responseMessage);
                }
                string responseContent = await responseMessage.Content.ReadAsStringAsync();
                return(JsonConvert.DeserializeObject <JsonResponse <T> >(responseContent));
            });

            if (response.HasError)
            {
                throw ReconstituteException(response.Error);
            }
            else
            {
                return(response.Result);
            }
        }