Example #1
0
        public async Task <BasicShareInformation> GetBasicShareInformationAsync(string symbol)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            var range    = ShareHistoryQueryRange.OneWeek;
            var response = await _shareHistoryQueryService.Query(symbol, range);

            // This could all be done in a single for loop if needed, for performance reasons
            // I just split it into three methods for better readability
            var history = response.History;
            var maximumSharePriceForPeriod = CalculateMaximumSharePrice(history.High);
            var minimumSharePriceForPeriod = CalculateMinimumSharePrice(history.Low);
            var averageSharePriceForPeriod = CalculateAverageSharePrice(history);

            var shareInformation = new BasicShareInformation
            {
                ShareName = response.ShareName,
                MaximumSharePriceForPeriod = maximumSharePriceForPeriod,
                MinimumSharePriceForPeriod = minimumSharePriceForPeriod,
                AverageSharePriceForPeriod = averageSharePriceForPeriod
            };

            return(shareInformation);
        }
        public string GetJsonString(BasicShareInformation shareInformation)
        {
            var jsonString = JsonSerializer.Serialize(shareInformation);

            return(jsonString);
        }