Ejemplo n.º 1
0
            //rest of the code

            void OnStockTick(object sender, StockTick stockTick)
            {
                const decimal maxChangeRatio = 0.1m;
                StockInfo     stockInfo;
                var           quoteSymbol = stockTick.QuoteSymbol;

                lock (_stockTickLocker)
                {
                    var stockInfoExists = _stockInfos.TryGetValue(quoteSymbol, out stockInfo);
                    if (stockInfoExists)
                    {
                        var priceDiff   = stockTick.Price - stockInfo.PrevPrice;
                        var changeRatio = Math.Abs(priceDiff / stockInfo.PrevPrice); //#A the percentage of change
                        if (changeRatio > maxChangeRatio)
                        {
                            Console.WriteLine("Stock:{0} has changed with {1} 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);
                    }
                }
            }
Ejemplo n.º 2
0
 //rest of the code
 void OnStockTick(object sender, StockTick stockTick)
 {
     const decimal maxChangeRatio = 0.1m;
     StockInfo stockInfo;
     var quoteSymbol = stockTick.QuoteSymbol;
     lock (_stockTickLocker)
     {
         var stockInfoExists = _stockInfos.TryGetValue(quoteSymbol, out stockInfo);
         if (stockInfoExists)
         {
             var priceDiff = stockTick.Price - stockInfo.PrevPrice;
             var changeRatio = Math.Abs(priceDiff / stockInfo.PrevPrice); //#A the percentage of change
             if (changeRatio > maxChangeRatio)
             {
                 Console.WriteLine("Stock:{0} has changed with {1} 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);
         }
     }
 }
Ejemplo n.º 3
0
        private void OnStockTick(object sender, StockTick stockTick)
        {
            const decimal maxChangeRatio = 0.1m;
            var           quoteSymbol    = stockTick.QuoteSymbol;

            lock (_stockTickLocker)
            {
                if (_stockInfos.TryGetValue(quoteSymbol, out StockInfo stockInfo))
                {
                    var priceDiff   = stockTick.Price - stockInfo.PrevPrice;
                    var changeRatio = Math.Abs(priceDiff / stockInfo.PrevPrice); //#A the percentage of change
                    if (changeRatio > maxChangeRatio)
                    {
                        Console.WriteLine(
                            $"Stock:{quoteSymbol} has changed with {changeRatio} ratio, Old Price:{stockInfo.PrevPrice} New Price:{stockTick.Price}");
                    }
                    stockInfo.PrevPrice = stockTick.Price;
                }
                else
                {
                    _stockInfos[quoteSymbol] = new StockInfo(quoteSymbol, stockTick.Price);
                }
            }
        }
Ejemplo n.º 4
0
 public void Notify(StockTick tick)
 {
     StockTick(this, tick);
 }
Ejemplo n.º 5
0
 public void Notify(StockTick tick)
 {
     StockTick(this, tick);
 }