Beispiel #1
0
        private void AlertPriceAsync(SymbolModel symbol, decimal currentPrice)
        {
            Task.Run(() =>
            {
                var symbolAlerts = SymbolAlerts.Where(x => x.SymbolId == symbol.Id && ((x.LessValue.HasValue && x.LessValue.Value >= currentPrice) || (x.GreaterValue.HasValue && x.GreaterValue <= currentPrice)));

                foreach (var symbolAlert in symbolAlerts)
                {
                    if (symbolAlert.LastAlertDate == null || (DateTime.Now - symbolAlert.LastAlertDate.Value).TotalMinutes > 5)
                    {
                        var user = Users.FirstOrDefault(x => x.Id == symbolAlert.UserId);

                        string message = $"[ALERT] {symbol.FriendlyName}: {currentPrice}";

                        _userManager.SendMessage(user.Id, message);

                        _userManager.CallUser(symbolAlert.UserId, $"{symbol.FriendlyName} price is {currentPrice}");

                        symbolAlert.LastAlertDate = DateTime.Now;

                        _alertManager.UpdateAsAlerted(user.Id, symbol.Id, DateTime.Now);
                    }
                }
            });
        }