Example #1
0
        public void QAVMATest(QAVTest test)
        {
            Avq.UrlContenResult = File.ReadAllText(AvTimeSeriesMonthlyAdjustedJsonTestFile);
            object actual = Avq.QAVMA(test.Symbol, info: test.Info, tradingMonth: test.DatePart, tradingDate: test.QuoteDate);

            Assert.Equal(test.Expected, actual);
        }
Example #2
0
        private void QAVAssert(QAVTest test, object actual)
        {
            /* If a date specific argument was given and the BestMatch option was set to false,
             * then stock info may not available when trading date is on weekend or a public holiday.*/
            if ((test.DatePart < 0 ||
                 test.QuoteDate != default(DateTime)) &&
                !test.BestMatch)
            {
                DateTime tradingDate = DateTime.Today.AddDays(test.DatePart);
                if (tradingDate.DayOfWeek == DayOfWeek.Saturday ||
                    tradingDate.DayOfWeek == DayOfWeek.Sunday ||
                    DateSystem.IsPublicHoliday(tradingDate, CountryCode.US))
                {
                    // No quotes are available on the weekend or on public holidays.
                    Assert.True(ExcelError.ExcelErrorNA.Equals(actual) || actual is decimal);
                }
            }
            else
            {
                // For current trading dates only test on type is possible.
                switch (test.Info)
                {
                case "volume":
                    Assert.True(int.TryParse(actual.ToString(), out int value));
                    break;

                default:
                    Assert.IsType <decimal>(actual);
                    break;
                }
            }
        }
Example #3
0
        public void QAVMAWebTest(QAVTest test)
        {
            Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol={test.Symbol}&apikey={test.ApiKey}");
            object actual = Avq.QAVMA(test.Symbol, info: test.Info, tradingMonth: test.DatePart, tradingDate: test.QuoteDate, bestMatch: test.BestMatch);

            QAVAssert(test, actual);
        }
Example #4
0
        public void QAVIDTest(QAVTest test)
        {
            Avq.UrlContenResult = File.ReadAllText(AvTimeSeriesIntradayJsonTestFile);
            object actual = Avq.QAVID(test.Symbol, info: test.Info);

            Assert.Equal(test.Expected, actual);
        }
Example #5
0
        public void QAVIDWebTest(QAVTest test)
        {
            if (test.OutputSize.Equals("full"))
            {
                Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={test.Symbol}&interval={test.Interval}&outputsize={test.OutputSize}&apikey={test.ApiKey}");
            }
            else
            {
                Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={test.Symbol}&interval={test.Interval}&apikey={test.ApiKey}");
            }
            object actual = Avq.QAVID(test.Symbol, info: test.Info, dataPointIndex: test.DatePart, interval: test.Interval, outputSize: test.OutputSize);

            QAVAssert(test, actual);
        }
Example #6
0
        public void QAVDAWebTest(QAVTest test)
        {
            if (test.OutputSize.Equals("full"))
            {
                Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={test.Symbol}&outputsize={test.OutputSize}&apikey={test.ApiKey}");
            }
            else
            {
                Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={test.Symbol}&apikey={test.ApiKey}");
            }
            object actual = Avq.QAVDA(test.Symbol, info: test.Info, tradingDay: test.DatePart, tradingDate: test.QuoteDate, bestMatch: test.BestMatch, outputSize: test.OutputSize);

            QAVAssert(test, actual);
        }
Example #7
0
        public void QAVDWebNegativeTest(QAVTest test)
        {
            Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={test.Symbol}&apikey={test.ApiKey}");

            if (test.OutputSize.Equals("n/a"))
            {
                Assert.Throws <ArgumentException>(() => Avq.QAVD(test.Symbol, info: test.Info, tradingDay: test.DatePart, tradingDate: test.QuoteDate, bestMatch: test.BestMatch, outputSize: test.OutputSize));
            }
            else
            {
                object actual = Avq.QAVD(test.Symbol, info: test.Info, tradingDay: test.DatePart, tradingDate: test.QuoteDate, bestMatch: test.BestMatch, outputSize: test.OutputSize);
                Assert.Equal(test.Expected, actual);
            }
        }
Example #8
0
        public void QAVTSWebTest(QAVTest test)
        {
            string api;
            string interval = test.Interval.ToLower();

            if (interval.Equals("daily") ||
                interval.Equals("weekly") ||
                interval.Equals("monthly"))
            {
                api = $"TIME_SERIES_{interval.ToUpper()}" + (test.Adjusted ? "_ADJUSTED" : "");

                // Remove not valid API parameters (for demo API key).
                if (!interval.Equals("daily") ||
                    test.OutputSize.Equals("compact"))
                {
                    test.OutputSize = null;
                }
                test.Interval = null;
            }
            else
            {
                api = "TIME_SERIES_INTRADAY";

                // Remove not valid TIME_SERIES_INTRADAY API parameter (for demo API key).
                test.OutputSize = null;
            }

            Avq.AvStockTimeSeriesOutputSize?outputSize = null;
            if (test.OutputSize != null)
            {
                outputSize = (Avq.AvStockTimeSeriesOutputSize)Enum.Parse(typeof(Avq.AvStockTimeSeriesOutputSize), test.OutputSize);
            }
            string avUri = Avq.AvUrlBuilder(api, apiKey: test.ApiKey, symbol: test.Symbol, outputSize: outputSize, interval: test.Interval);

            Avq.UrlContenResult = FfeWeb.GetHttpResponseContent(avUri);
            object actual = Avq.QAVTS(test.Symbol, info: test.Info, interval: test.Interval, tradingDay: test.DatePart, tradingDate: test.QuoteDate, adjusted: test.Adjusted, outputSize: test.OutputSize, bestMatch: test.BestMatch);

            QAVAssert(test, actual);
        }
Example #9
0
        public void QAVQWebTest(QAVTest test)
        {
            Avq.UrlContenResult = FfeWeb.GetHttpResponseContent($"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={test.Symbol}&apikey={test.ApiKey}");
            object actual = Avq.QAVQ(test.Symbol, info: test.Info);

            // If a date specific argument was given, then stock info may not available when trading date is on weekend or a public holiday.
            DateTime tradingDate = DateTime.Today.AddDays(test.DatePart);

            if (tradingDate.DayOfWeek == DayOfWeek.Saturday ||
                tradingDate.DayOfWeek == DayOfWeek.Sunday ||
                DateSystem.IsPublicHoliday(tradingDate, CountryCode.US))
            {
                // No quotes are available on the weekend or on public holidays.
                Assert.True(ExcelError.ExcelErrorNA.Equals(actual) ||
                            actual is DateTime ||
                            actual is string ||
                            actual is decimal);
            }
            else
            {
                switch (test.Info)
                {
                case "latest trading day":
                    Assert.IsType <DateTime>(actual);
                    break;

                case "change percent":
                    Assert.IsType <string>(actual);
                    break;

                default:
                    Assert.IsType <decimal>(actual);
                    break;
                }
            }
        }