public async Task ReturnValidNotIntradayTimeSeries(Interval interval, OutputSize size, bool isAdjusted)
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            var timeSeries = await stocksClient.GetTimeSeriesAsync("AAPL", interval, size, isAdjusted);

            timeSeries.Should().NotBeNull()
            .And.Match <StockTimeSeries>(ts =>
                                         ts.IsAdjusted == isAdjusted &&
                                         ts.Interval == interval);

            timeSeries.MetaData.Should().NotBeNull()
            .And.HaveCountGreaterThan(1);

            timeSeries.DataPoints.Should().NotBeNull()
            .And.HaveCountGreaterThan(1)
            .And.NotContainNulls()
            .And.OnlyContain(dp => IsDataPointValid(dp));

            if (isAdjusted == false)
            {
                return;
            }

            timeSeries.DataPoints.Should()
            .OnlyContain(dp =>
                         IsAdjustedDataPointValid(dp, interval == Interval.Daily && isAdjusted));
        }
Пример #2
0
        public async Task ReturnSearchResults()
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            var searchMatches = await stocksClient.SearchSymbolAsync("BA");

            searchMatches.Should().NotBeNull()
            .And.HaveCountGreaterThan(1);

            foreach (var searchMatch in searchMatches)
            {
                searchMatch.Should().NotBeNull()
                .And.Match <SymbolSearchMatch>(sm =>
                                               string.IsNullOrWhiteSpace(sm.Symbol) == false &&
                                               string.IsNullOrWhiteSpace(sm.Name) == false &&
                                               string.IsNullOrWhiteSpace(sm.Type) == false &&
                                               string.IsNullOrWhiteSpace(sm.Region) == false &&
                                               string.IsNullOrWhiteSpace(sm.Timezone) == false &&
                                               string.IsNullOrWhiteSpace(sm.Currency) == false &&
                                               sm.MarketOpen != default &&
                                               sm.MarketClose != default &&
                                               sm.MatchScore <= 1 && sm.MatchScore > 0
                                               );
            }
        }
Пример #3
0
        public async Task ReturnEmptyCollection_OnMeaninglessKeyword()
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            var searchMatches = await stocksClient.SearchSymbolAsync("wrong_symbol_name");

            searchMatches.Should().NotBeNull().And.BeEmpty();
        }
        public async Task ThrowException_ForInvalidSymbol(Interval interval, OutputSize size, bool isAdjusted)
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            await Assert.ThrowsAsync <AlphaVantageException>(async() =>
            {
                await stocksClient.GetTimeSeriesAsync("wrong_symbol", interval, size, isAdjusted);
            });
        }
        public async Task ThrowException_OnNonExistingSymbol()
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            await Assert.ThrowsAsync <AlphaVantageParsingException>(async() =>
            {
                await stocksClient.GetGlobalQuoteAsync("wrong_symbol_name");
            });
        }
Пример #6
0
        public static async Task StocksDemo()
        {
            // use your AlphaVantage API key
            string apiKey = "6FQOAVODM8ZFCE3T";

            // there are 5 more constructors available
            using var client       = new AlphaVantageClient(apiKey);
            using var stocksClient = client.Stocks();

            StockTimeSeries stockTs = await stocksClient.GetTimeSeriesAsync("AAPL", Interval.Daily, OutputSize.Compact, isAdjusted : true);

            GlobalQuote globalQuote = await stocksClient.GetGlobalQuoteAsync("AAPL");

            ICollection <SymbolSearchMatch> searchMatches = await stocksClient.SearchSymbolAsync("BA");
        }
        public async Task ReturnValidIntradayTimeSeries(Interval interval, OutputSize size, bool isAdjusted)
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            var timeSeries = await stocksClient.GetTimeSeriesAsync("AAPL", interval, size, isAdjusted);

            timeSeries.Should().NotBeNull()
            .And.Match <StockTimeSeries>(ts =>
                                         ts.IsAdjusted == false && // intraday ts are always not adjusted
                                         ts.Interval == interval);

            timeSeries.MetaData.Should().NotBeNull()
            .And.HaveCountGreaterThan(1);

            timeSeries.DataPoints.Should().NotBeNull()
            .And.HaveCountGreaterThan(1)
            .And.NotContainNulls()
            .And.OnlyContain(dp =>
                             IsDataPointValid(dp) && dp.GetType() != typeof(StockAdjustedDataPoint));
        }
        public async Task ReturnGlobalQuote()
        {
            using var client       = new AlphaVantageClient(_apiKey);
            using var stocksClient = client.Stocks();

            var globalQuote = await stocksClient.GetGlobalQuoteAsync("AAPL");

            globalQuote.Should().NotBeNull()
            .And
            .Match <GlobalQuote>(sm =>
                                 string.IsNullOrWhiteSpace(sm.Symbol) == false &&
                                 sm.OpeningPrice != default &&
                                 sm.PreviousClosingPrice != default &&
                                 sm.HighestPrice != default &&
                                 sm.LowestPrice != default &&
                                 sm.Price != default &&
                                 sm.Volume != default &&
                                 sm.Change != default &&
                                 sm.ChangePercent != default &&
                                 sm.LatestTradingDay != default
                                 );
        }