public async Task <ShareHistoryQueryResponse> Query(string symbol, ShareHistoryQueryRange range) { var yahooRange = _shareHistoryQueryRangeConverter.ConvertFrom(range); var interval = YahooInterval.OneDay; // This could be reduced up to 1 minute if we want more granular and precise data var url = $"{_baseUrl}/{symbol}?range={yahooRange}&interval={interval}"; using var response = await _httpClient.GetAsync(url); var result = await ParseResponse(response); if (response.IsSuccessStatusCode) { return(_shareHistoryQueryResponseConverter.ConvertFrom(result)); } var error = result.Chart.Error; throw new InvalidRequestException(error.Code, error.Description); }
public string ConvertFrom(ShareHistoryQueryRange range) { switch (range) { case ShareHistoryQueryRange.OneDay: return(YahooRange.OneDay); case ShareHistoryQueryRange.OneWeek: return(YahooRange.FiveDays); case ShareHistoryQueryRange.OneMonth: return(YahooRange.OneMonth); case ShareHistoryQueryRange.ThreeMonths: return(YahooRange.ThreeMonths); default: throw new NotSupportedException("The range requested is not supported by this api."); } }