コード例 #1
0
        private void OnStockTick(object sender, StockTick stockTick)
        {
            var quoteSymbol = stockTick.QuoteSymbol;

            lock (_stockTickLocker)
            {
                var stockInfoExists = _stockInfos.TryGetValue(quoteSymbol, out StockInfo stockInfo);
                if (stockInfoExists)
                {
                    var priceDiff   = stockTick.Price - stockInfo.PrevPrice;
                    var changeRatio = Math.Abs(priceDiff / stockInfo.PrevPrice);
                    if (changeRatio > maxChangeRatio)
                    {
                        //Do SOmething with the stock - notify user or display on screen
                        Console.WriteLine("Stock:{0} has changed with {1:N2} ratio, Old Price:{2} New Price:{3}",
                                          quoteSymbol,
                                          changeRatio,
                                          stockInfo.PrevPrice,
                                          stockTick.Price);
                    }
                    _stockInfos[quoteSymbol].PrevPrice = stockTick.Price;
                }
                else
                {
                    _stockInfos[quoteSymbol] = new StockInfo(quoteSymbol, stockTick.Price);
                }
            }
        }
コード例 #2
0
 public void Tick(StockTick stockTick)
 {
     StockTick.Invoke(this, stockTick);
 }