Example #1
0
        /// <summary>
        /// returns notification if exists by teamId, currency and key search filter
        /// </summary>
        /// <returns></returns>
        private DataAccess.Models.TeamNotification GetTeamNotificationByKeyAndType(Dto.TeamNotification teamNotification)
        {
            var key = teamNotification.Key;

            if (teamNotification.NotificationType == NotificationType.AssetReminder)
            {
                return(_repository.AsQueryable()
                       .FirstOrDefault(p => p.Key == key &&
                                       p.NotificationType == teamNotification.NotificationType &&
                                       p.TeamId == teamNotification.TeamId));
            }

            //for arbitrage and price tracker alarms we need to check existance for splitted value of key
            var keyArray = teamNotification.Key.Split(':');

            //price tracker => 3:1:44000.55:1
            //arbitrage tracker => arb:3:10.00

            key = keyArray[0] + ":" + keyArray[1] + ":";

            return(_repository.AsQueryable()
                   .FirstOrDefault(p => p.Key.Contains(key) &&
                                   p.NotificationType == teamNotification.NotificationType &&
                                   p.TeamId == teamNotification.TeamId));
        }
Example #2
0
        public void Delete(Dto.TeamNotification teamNotification)
        {
            var entity = GetTeamNotificationByKeyAndType(teamNotification);

            if (entity != null)
            {
                _repository.Delete(entity);
                _uow.Save();
            }
        }
        private void SaveArbitrageNotification(Currency currency, decimal percentage)
        {
            var key = "arb:" + (int)currency + ":" + percentage.ToMoneyMarketMoneyFormat();

            var teamNotification = new Dto.TeamNotification
            {
                TeamId           = Team.Id,
                NotificationType = NotificationType.Arbitrage,
                Key            = key,
                LastExecutedAt = DateTime.UtcNow,
                TimeInterval   = 0
            };

            var teamNotificationBusiness = new TeamNotificationBusiness();

            // add or update notification
            teamNotificationBusiness.Add(teamNotification);
        }
        private void SavePriceTrackerNotification(Currency currency, Provider provider, decimal limitAmount, MainCurrency mainCurrency)
        {
            var cryptoCurrencies = GetCryptoCurrencies(currency);

            var limitAmountUsdValue = GetCurrentUsdValueByMainCurrency(limitAmount, mainCurrency);

            Dto.CryptoCurrency cryptoCurrency;

            if (provider == Provider.Unknown)
            {
                cryptoCurrency = cryptoCurrencies.First(p => p.Provider == Provider.CoinMarketCap);
            }
            else
            {
                cryptoCurrency = cryptoCurrencies.First(p => p.Provider == provider);
            }

            var alarmType = cryptoCurrency.UsdValue > limitAmountUsdValue ? AlarmType.Purchase : AlarmType.Sell;

            var key = (int)provider + ":" + (int)currency + ":" + limitAmount.ToMoneyMarketCryptoCurrencyFormat() + ":" + (int)mainCurrency + ":" + (int)alarmType;

            var teamNotification = new Dto.TeamNotification
            {
                TeamId           = Team.Id,
                NotificationType = NotificationType.PriceTracker,
                Key            = key,
                LastExecutedAt = DateTime.UtcNow,
                TimeInterval   = 0 // 0 for alarms
            };

            var teamNotificationBusiness = new TeamNotificationBusiness();

            if (limitAmount == 0)
            {
                //user wants to snooze notification
                teamNotificationBusiness.Delete(teamNotification);
                return;
            }

            // add or update notification
            teamNotificationBusiness.Add(teamNotification);
        }
        private void SaveAssetReminderTrackerNotification(Currency currency, int timeInterval)
        {
            var teamNotification = new Dto.TeamNotification
            {
                TeamId           = Team.Id,
                NotificationType = NotificationType.AssetReminder,
                Key            = ((int)currency).ToString(),
                LastExecutedAt = DateTime.UtcNow,
                TimeInterval   = timeInterval
            };

            var teamNotificationBusiness = new TeamNotificationBusiness();

            if (timeInterval == 0)
            {
                //user wants to snooze notification
                teamNotificationBusiness.Delete(teamNotification);
                return;
            }

            // add or update notification
            teamNotificationBusiness.Add(teamNotification);
        }