public IActionResult GetPrices(
            [FromRoute][MinLength(3)] string symbol,
            [FromQuery][Required] string range,
            [FromQuery] string interval)
        {
            if (string.IsNullOrEmpty(range) || !_intervals.ContainsKey(range))
            {
                throw new ValidationException("Invalid range specified.");
            }

            if (interval != null)
            {
                if (_intervals.Values.All(value => value != interval))
                {
                    throw new ValidationException("Invalid interval specified.");
                }
            }
            else
            {
                interval = _intervals[range];
            }

            var prices = _sharePriceHistoryProvider.GetPriceHistory(symbol, DateTime.UtcNow, range, interval);

            if (prices == null)
            {
                return(NotFound());
            }

            var response = prices.Select(price => price.Close).ToArray();

            return(Ok(response));
        }
Пример #2
0
        public IActionResult GetPrices(
            [FromRoute][MinLength(3)] string symbol,
            [FromQuery][Required] string range,
            [FromQuery] string interval,
            [FromQuery] DateTime?endTime)
        {
            if (string.IsNullOrEmpty(range) || !_intervals.ContainsKey(range))
            {
                throw new ValidationException("Invalid range specified.");
            }

            if (interval != null)
            {
                if (_intervals.Values.All(value => value != interval))
                {
                    throw new ValidationException("Invalid interval specified.");
                }
            }
            else
            {
                interval = _intervals[range];
            }

            var prices = _sharePriceHistoryProvider.GetPriceHistory(symbol, endTime ?? DateTime.UtcNow, range, interval);

            if (prices == null)
            {
                return(NotFound());
            }

            var response = new PriceResponse
            {
                Range    = range,
                Interval = interval,
                Prices   = prices.Select(p => new Price
                {
                    Timestamp = p.Timestamp,
                    Open      = p.Open,
                    High      = p.High,
                    Low       = p.Low,
                    Close     = p.Close,
                    Volume    = p.Volume
                })
            };

            return(Ok(response));
        }