Esempio n. 1
0
        public async Task Invoke(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Invoked timercoinmarket");
            try
            {
                _logger.LogInformation(NoticeStore.NoticesCoinMarket.Count.ToString());
                _logger.LogInformation(CurrencyInfoStore.CoinMarkets.Count.ToString());

                NoticeStore.ClearCoinMarket();

                //_alertRepository.DeleteMany(x=> x.NotifyCost == null && string.IsNullOrEmpty(x.PercentNotify));

                var users = _userRepository.GetItems(z => z.NotifyCoinMarket).ToList(); //+

                var currencyPairs = await _client.GetCoinMarket();

                CurrencyInfoStore.AddCoinMarket(currencyPairs);

                var notifications = _currencyService
                                    .CreateNotifications(users, CurrencyInfoStore.CoinMarkets, 2, _alertRepository);

                await _notifyer.Notify(notifications);
            }
            catch (Exception e)
            {
                _logger.LogError("Timer coinmarket", e.Message);
            }
        }
Esempio n. 2
0
        public async Task Invoke(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Invoked timerbittrex");
            try
            {
                _logger.LogInformation(NoticeStore.NoticesBittrix.Count.ToString());
                _logger.LogInformation(CurrencyInfoStore.Bittrixes.Count.ToString());

                NoticeStore.ClearBittrix();

                var users         = _userRepository.GetItems(x => x.NotifyBittrix).ToList();
                var currencyPairs = await _client.GetBittrix();

                CurrencyInfoStore.AddBittrix(currencyPairs);

                var notifications =
                    _currencyService.CreateNotifications(users, CurrencyInfoStore.Bittrixes, 0, _alertRepository);

                await _notifyer.Notify(notifications);
            }
            catch (Exception e)
            {
                _logger.LogError("Timer bittriex", e.Message);
            }
        }
Esempio n. 3
0
        private List <Report> CreateCoinMarketRepots(User user, List <IEnumerable <CurrencyPair> > currencyPairs,
                                                     IRepository <Alert> _alertRepository)
        {
            var reports = new List <Report>();

            if (currencyPairs.Count == 1)
            {
                return(reports);
            }
            var alerts    = _alertRepository.GetItems(x => x.UserId == user.TelegramUserId);
            var oldValues = currencyPairs[currencyPairs.Count - 2];
            var newValues = currencyPairs.Last();

            foreach (var value in newValues)
            {
                if (
                    alerts.Any(
                        x => string.Equals(x.NameCurrency, value.CurrencyPairName, StringComparison.OrdinalIgnoreCase)))
                {
                    var alert       = alerts.FirstOrDefault(x => x.NameCurrency == value.CurrencyPairName);
                    var percent     = alert.PercentNotify;
                    var cost        = alert.NotifyCost;
                    var oldCurrnecy = oldValues.FirstOrDefault(x => x.CurrencyPairName == value.CurrencyPairName);
                    if (!string.IsNullOrEmpty(percent))
                    {
                        var report = CheckPercent(alert, value);
                        if (report != null &&
                            !NoticeStore.IsNotifiedCoinMarket(user.TelegramUserId, value.CurrencyPairName,
                                                              TypeNotice.Percent))
                        {
                            reports.Add(report);
                            alert.PercentNotify = null;
                        }
                    }
                    if (cost.HasValue)
                    {
                        var report = CheckCost(value, oldCurrnecy, cost.Value);
                        if (report != null &&
                            !NoticeStore.IsNotifiedCoinMarket(user.TelegramUserId, value.CurrencyPairName,
                                                              TypeNotice.Cost))
                        {
                            reports.Add(report);
                            alert.NotifyCost = null;
                        }
                    }
                    if (alert.PercentNotify == null && alert.NotifyCost == null)
                    {
                        _alertRepository.Delete(z => z.UserId == user.TelegramUserId && z.NameCurrency == value.FirstCurrency);
                    }
                    else
                    {
                        _alertRepository.Update(alert, x => x.UserId == user.TelegramUserId && x.NameCurrency == value.FirstCurrency);
                    }
                }
                if (reports.Any(x => x.CurrencyPair == value.CurrencyPairName && x.Type == TypeNotice.Percent))
                {
                    NoticeStore.AddCoinMarket(new Notice(user.TelegramUserId, value.CurrencyPairName, TypeNotice.Percent));
                }
                if (reports.Any(x => x.CurrencyPair == value.CurrencyPairName && x.Type == TypeNotice.Cost))
                {
                    NoticeStore.AddCoinMarket(new Notice(user.TelegramUserId, value.CurrencyPairName, TypeNotice.Cost));
                }
            }
            return(reports);
        }
Esempio n. 4
0
        private List <Report> CreatePoloniexReports(User user, List <IEnumerable <CurrencyPair> > currencyPairs)
        {
            var userTimeToCheckPoloniex       = user.TimeToCheckPoloniex;
            var userNumberChat                = user.TelegramUserId;
            var userPoloniexPercentChangeCost = user.PoloniexPercentChangeCost;

            var reports   = new List <Report>();
            int ind       = (int)Math.Round(userTimeToCheckPoloniex / 5);
            var oldValues = currencyPairs.Count <= ind
                ? currencyPairs[0].ToList()
                : currencyPairs[currencyPairs.Count - ind - 1].ToList();

            var newValues = currencyPairs.Last().ToList();

            foreach (var newValue in newValues)
            {
                var oldValue = oldValues
                               .Where(x => x.CurrencyPairName == newValue.CurrencyPairName)
                               .ToList();
                if (oldValue.Any())
                {
                    var percent = (newValue.Last / oldValue.First().Last - 1) * 100;
                    if (Math.Abs(percent) > userPoloniexPercentChangeCost)
                    {
                        var sign  = percent >= 0 ? '+' : '-';
                        var value = Math.Abs(percent);
                        if (!NoticeStore.IsNotifiedPoloniex(user.TelegramUserId, newValue.CurrencyPairName, TypeNotice.Percent))
                        {
                            reports.Add(new Report
                            {
                                Type         = TypeNotice.Percent,
                                Text         = $"Курс {newValue.CurrencyPairName} изменился на {sign}{value:F2}%",
                                CurrencyPair = newValue.CurrencyPairName
                            });
                        }
                    }
                    if (oldValues.Count == newValues.Count)
                    {
                        var sortedOld = oldValues.OrderBy(x => x.BaseVolume).ToList();
                        var indOld    = sortedOld.FindIndex(x => x.CurrencyPairName == newValue.CurrencyPairName);

                        var sortedNew = newValues.OrderBy(x => x.BaseVolume).ToList();
                        var indNew    = sortedNew.FindIndex(x => x.CurrencyPairName == newValue.CurrencyPairName);
                        if (!NoticeStore.IsNotifiedPoloniex(user.TelegramUserId, newValue.CurrencyPairName, TypeNotice.Volume) && indNew - indOld >= 2)
                        {
                            reports.Add(new Report
                            {
                                Type         = TypeNotice.Volume,
                                Text         = $"{newValue.SecondCurrency} поднялся на {indNew - indOld} поз.",
                                CurrencyPair = newValue.CurrencyPairName
                            });
                        }
                    }

                    if (reports.Any(x => x.CurrencyPair == newValue.CurrencyPairName && x.Type == TypeNotice.Percent))
                    {
                        NoticeStore.AddPoloniex(new Notice(userNumberChat, newValue.CurrencyPairName, TypeNotice.Percent));
                    }
                    if (reports.Any(x => x.CurrencyPair == newValue.CurrencyPairName && x.Type == TypeNotice.Volume))
                    {
                        NoticeStore.AddPoloniex(new Notice(userNumberChat, newValue.CurrencyPairName, TypeNotice.Volume));
                    }
                }
            }
            return(reports);
        }
Esempio n. 5
0
        private List <Report> CreateBittrixReports(User user, List <IEnumerable <CurrencyPair> > currencyPairs)
        {
            var userTimeToCheckBittrix       = user.TimeToCheckBittrix;
            var userNumberChat               = user.TelegramUserId;
            var userBittrixPercentChangeCost = user.BittrixPercentChangeCost;
            var userBittrixPercentVolume     = user.BittrixPercentVolume;

            var reports   = new List <Report>();
            int ind       = (int)Math.Round(userTimeToCheckBittrix * 5);
            var oldValues = currencyPairs.Count <= ind
                ? currencyPairs[0]
                : currencyPairs[currencyPairs.Count - ind - 1];

            var newValues = currencyPairs.Last().ToList();

            foreach (var newValue in newValues)
            {
                var oldValue = oldValues
                               .Where(x => x.CurrencyPairName == newValue.CurrencyPairName)
                               .ToList();

                if (oldValue.Any())
                {
                    var percent = (newValue.Last / oldValue.First().Last - 1) * 100;
                    if (Math.Abs(percent) > userBittrixPercentChangeCost)
                    {
                        var sign  = percent >= 0 ? '+' : '-';
                        var value = Math.Abs(percent);
                        if (!NoticeStore.IsNotifiedBittrix(user.TelegramUserId, newValue.CurrencyPairName, TypeNotice.Percent))
                        {
                            reports.Add(new Report
                            {
                                Type         = TypeNotice.Percent,
                                Text         = $"Курс {newValue.CurrencyPairName} изменился на {sign}{value:F2}%",
                                CurrencyPair = newValue.CurrencyPairName
                            });
                        }
                    }
                    percent = (newValue.BaseVolume / oldValue.First().BaseVolume - 1) * 100;
                    if (percent > userBittrixPercentVolume)
                    {
                        var sign  = percent >= 0 ? '+' : '-';
                        var value = Math.Abs(percent);
                        if (!NoticeStore.IsNotifiedBittrix(user.TelegramUserId, newValue.CurrencyPairName, TypeNotice.Volume))
                        {
                            reports.Add(new Report
                            {
                                Type         = TypeNotice.Volume,
                                Text         = $"Объем {newValue.CurrencyPairName} изменился на {sign}{value:F2}%",
                                CurrencyPair = newValue.CurrencyPairName
                            });
                        }
                    }

                    if (reports.Any(x => x.CurrencyPair == newValue.CurrencyPairName && x.Type == TypeNotice.Percent))
                    {
                        NoticeStore.AddBittrix(new Notice(userNumberChat, newValue.CurrencyPairName, TypeNotice.Percent));
                    }
                    if (reports.Any(x => x.CurrencyPair == newValue.CurrencyPairName && x.Type == TypeNotice.Volume))
                    {
                        NoticeStore.AddBittrix(new Notice(userNumberChat, newValue.CurrencyPairName, TypeNotice.Volume));
                    }
                }
            }
            return(reports);
        }