Ejemplo n.º 1
0
        public async Task <List <KeyValuePair <string, double> > > GetStockPrices(List <KeyValuePair <string, int> > stocks)
        {
            string apiKey = "O8UW3NE3Z3CEYSVB"; // API KEY

            var client = new AlphaVantageStocksClient(apiKey);


            //This list will contain the stocks' symbols and the prices
            List <KeyValuePair <string, double> > stocksAndPrice = new List <KeyValuePair <string, double> >();

            string[] stockSymbols = new string[stocks.Count];

            for (int i = 0; i < stocks.Count; i++)
            {
                stockSymbols[i] = stocks[i].Key;
            }


            // retrieve stocks batch quotes for Apple Inc. and Facebook Inc.:
            ICollection <StockQuote> batchQuotes = await client.RequestBatchQuotesAsync(stockSymbols);

            foreach (var stockQuote in batchQuotes)
            {
                stocksAndPrice.Add(new KeyValuePair <string, double>(stockQuote.Symbol, (double)stockQuote.Price));
                Console.WriteLine($"{stockQuote.Symbol}: {stockQuote.Price}");
            }

            return(stocksAndPrice);
        }
Ejemplo n.º 2
0
        public async Task RequestBatchQuotesAsync_Test()
        {
            var client = new AlphaVantageStocksClient(ApiKey);

            var result =
                await client.RequestBatchQuotesAsync(new [] { "AAPL", "FB", "MSFT" });

            Assert.NotNull(result);
            Assert.Equal(3, result.Count);
            Assert.True(
                result.Any(r => r.Symbol == "MSFT") &&
                result.Any(r => r.Symbol == "FB") &&
                result.Any(r => r.Symbol == "AAPL"));
        }
Ejemplo n.º 3
0
        public async static Task <IEnumerable <StockQuote> > GetQuotes(params string[] symbols)
        {
            var avClient = new AlphaVantageStocksClient(API_KEY_ALPHA_VANTAGE);

            return(await avClient.RequestBatchQuotesAsync(symbols));
        }