Example #1
0
        public bool TryGetHistoricalPrices(string ticker, Exchange?exchange, DateTime?from, DateTime?to, PriceInterval interval, out PriceList prices, out string errorMessage)
        {
            //https://api.nasdaq.com/api/quote/AAPL/chart?assetclass=stocks&fromdate=2010-04-15&todate=2020-04-15
            if (from.HasValue == false)
            {
                from = DateTime.Now;
            }

            if (to.HasValue == false)
            {
                to = DateTime.Now;
            }

            bool ok = NasdaqApiCaller.GetPrices(ticker, exchange, from.Value, to.Value, interval, out HttpStatusCode statusCode, out NasdaqResponse nasdaqResponse, out string jsonResponse, out errorMessage);

            prices = new PriceList();
            foreach (var nasdaqPrice in nasdaqResponse.Data.Prices)
            {
                HistoricalPrice price = new HistoricalPrice();
                price.Close = nasdaqPrice.Price;
                prices.Add(price);
            }
            return(true);
        }