コード例 #1
0
ファイル: DividendProvider.cs プロジェクト: Cytra/StocksApi
        private async Task UpdateStockPrices(List <DividendCalendarItem> stocks)
        {
            var stockSplits = ListExtensions.Split(stocks, 10);
            var allPrices   = new ConcurrentBag <StockPriceItem>();

            foreach (var stockSplit in stockSplits)
            {
                var stockSymbols = StringExtensions.GetSymbolsString(stockSplit.Select(x => x.Symbol).ToArray());
                var prices       = await _stockPriceService.GetStockPrices(stockSymbols);

                foreach (var price in prices)
                {
                    allPrices.Add(price);
                }
            }

            foreach (var stockPrice in allPrices)
            {
                var stockToUpdate = stocks.FirstOrDefault(x => x.Symbol == stockPrice.Symbol);
                if (stockToUpdate != null)
                {
                    stockToUpdate.Price = stockPrice.Price;
                }
            }
        }
コード例 #2
0
ファイル: StockPriceProvider.cs プロジェクト: Cytra/StocksApi
        public async Task <List <StockPriceItem> > GetStockPrices(List <string> symbols)
        {
            var result      = new List <StockPriceItem>();
            var stockSplits = ListExtensions.Split(symbols, 10);

            foreach (var stockSplit in stockSplits)
            {
                var stockSymbols = StringExtensions.GetSymbolsString(stockSplit);
                var prices       = await _stockPriceService.GetStockPrices(stockSymbols);

                foreach (var price in prices)
                {
                    result.Add(price);
                }
            }
            return(result);
        }
コード例 #3
0
        public IActionResult GetStockPrices(string cname)
        {
            var o = stockService.GetStockPrices(cname);

            if (o == null)
            {
                return(NotFound("Data not present for this company"));
            }
            return(Ok(o));
        }