Esempio n. 1
0
 private void OnTimerElapsed(object sender, ElapsedEventArgs e)
 {
     if (Stocks.Count > 0)
     {
         var nextStock = Stocks.Dequeue();
         StockTick?.Invoke(this, nextStock);
     }
 }
Esempio n. 2
0
        private void OnStockTick(object sender, StockTick changedStock)
        {
            var quoteSymbol     = changedStock.QuoteSymbol;
            var stockInfoExists = _stockInfos.TryGetValue(quoteSymbol, out StockInfo stockInfo);

            if (stockInfoExists)
            {
                var priceDiff        = changedStock.Price - stockInfo.PrevPrice;
                var percentageChange = Math.Abs(priceDiff / stockInfo.PrevPrice);

                if (percentageChange > MaxChangeRatio)
                {
                    Console
                    .WriteLine($"Stock:{quoteSymbol} has changed with ratio {percentageChange:F}\nOld price: {stockInfo.PrevPrice}, New price: {changedStock.Price}");
                }
            }

            _stockInfos[quoteSymbol] = new StockInfo(changedStock.QuoteSymbol, changedStock.Price);
        }