コード例 #1
0
        public async Task GetPricesAndDeviation()
        {
            var symbols = _fileOperations.ReadCsv(_inputFilePath);

            var stocks = new List <Stock>();

            int counter = 0;

            foreach (var symbol in symbols)
            {
                try
                {
                    var prices = _client.GetPricesAndDeviations(symbol);

                    if (prices?.Count > 0)
                    {
                        var stock = new Stock
                        {
                            Symbol    = symbol,
                            Price     = prices.First(),
                            Deviation = prices.GetDeviation()
                        };

                        stocks.Add(stock);

                        PriceRerieved(this, new PriceRetrievedEventArgs(stock));
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                }

                counter++;
                if (counter % 5 == 0)
                {
                    counter = 0;
                    await Task.Delay(61000);
                }
            }

            _fileOperations.WriteCsv(stocks, _outputFilePath);
        }