private void OnStockTick(object?sender, StockTick e) { var symbol = e.Symbol; var price = e.Price; lock (StockLock) { if (StockInfos.TryGetValue(symbol, out var stockInfo)) { var prevPrice = stockInfo.PrevPrice; var changeRatio = Math.Round(Math.Abs(prevPrice - price) / prevPrice, 3); if (changeRatio > MaxChangeRadio) { Console.WriteLine($"Stock:{symbol} has change with {changeRatio} ratio, Old Price:{prevPrice} New Price:{price}"); } StockInfos[symbol].PrevPrice = price; } else { StockInfos.Add(symbol, new StockInfo(symbol, price)); //StockInfos.TryAdd(symbol, new StockInfo(symbol, price)); } } }
public void StockChange(string symbol, decimal price) { StockTick?.Invoke(this, new StockTick(symbol, price)); }