public async Task <ListLoadedResponse <Token, Gem> > LoadAllAsync(string storagePath)
        {
            var result = new ListLoadedResponse <Token, Gem>();

            try
            {
                result.OldList = await _fileService.GetAsync <IEnumerable <Token> >(PathTo.All(DexType.UNISWAP, storagePath));

                result.OldListDeleted = await _fileService.GetAsync <List <Gem> >(PathTo.Deleted(DexType.UNISWAP, storagePath));

                result.OldListAdded = await _fileService.GetAsync <List <Gem> >(PathTo.Added(DexType.UNISWAP, storagePath));
            }
            catch (Exception ex)
            {
                result.Message = ex.GetFullMessage();
            }
            return(result);
        }
Example #2
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var jobConfigFileName = context.JobDetail.JobDataMap["FileName"] as string;
                var storagePath       = context.JobDetail.JobDataMap["StoragePath"] as string;
                var interval          = context.JobDetail.JobDataMap["Interval"] as int?;

                var cfg = await _configurationService.GetJobConfigAsync(jobConfigFileName);

                var added = await _fileService.GetAsync <List <Gem> >(PathTo.Added(DexType.UNISWAP, storagePath));

                var deleted = await _fileService.GetAsync <List <Gem> >(PathTo.Deleted(DexType.UNISWAP, storagePath));

                if (added.AnyAndNotNull())
                {
                    Logger.Info($"V2|SUMMARY|ADDED|{added.Count}");

                    var newestAdded = added
                                      .Where(
                        g =>
                        g.Recently == TokenActionType.ADDED &&
                        (DateTime.UtcNow - g.DateTime).TotalMinutes < interval)
                                      .OrderByDescending(g => g.DateTime)
                                      .ToList();

                    Logger.Info($"V2|SUMMARY|ADDED|NEWEST|{newestAdded.Count}");

                    if (newestAdded.AnyAndNotNull())
                    {
                        var msg = UniMsg.ForTwitterSummary(newestAdded, TokenActionType.ADDED, interval.Value);

                        var sent = await _twitterService.SendMessageAsync(msg);

                        if (sent.Success)
                        {
                            Logger.Info($"V2|SUMMARY|ADDED|NEWEST|SENT");
                        }
                        else
                        {
                            Logger.Error($"{sent.Message}");
                        }
                    }
                }

                if (deleted.AnyAndNotNull())
                {
                    Logger.Info($"V2|SUMMARY|DELETED|NEWEST|{deleted.Count}");

                    var newestDeleted = deleted
                                        .Where(
                        g =>
                        g.Recently == TokenActionType.DELETED &&
                        (DateTime.Now - g.DateTime).TotalMinutes < interval)
                                        .OrderByDescending(g => g.DateTime)
                                        .ToList();

                    Logger.Info($"V2|SUMMARY|DELETED|NEWEST|{newestDeleted.Count}");

                    if (newestDeleted.AnyAndNotNull())
                    {
                        var msg = UniMsg.ForTwitterSummary(newestDeleted, TokenActionType.DELETED, interval.Value);

                        var sent = await _twitterService.SendMessageAsync(msg);

                        if (sent.Success)
                        {
                            Logger.Info($"V2|SUMMARY|DELETED|NEWEST|SENT");
                        }
                        else
                        {
                            Logger.Error($"{sent.Message}");
                        }
                    }
                }

                if (cfg.Success)
                {
                    Logger.Info($"Job: {cfg.JobConfig.Label} - DONE");
                }
            }
            catch (Exception e)
            {
                Logger.Fatal($"{e.GetFullMessage()}");
            }
        }
Example #3
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var jobConfigFileName = context.JobDetail.JobDataMap["FileName"] as string;
                var storagePath       = context.JobDetail.JobDataMap["StoragePath"] as string;

                var cfg = await _configurationService.GetJobConfigAsync(jobConfigFileName);

                var latestAll = await _dexchange.FetchAllAsync();

                if (latestAll.Success)
                {
                    Logger.Info($"{Dex}|LATEST|{latestAll.ListResponse.Count()}");

                    var loadedAll = await _dexchange.LoadAllAsync(storagePath);

                    if (loadedAll.Success)
                    {
                        Logger.Info($"{Dex}|LOADED ALL|{loadedAll.OldList.Count()}");
                        Logger.Info($"{Dex}|LOADED ALL DELETED|{loadedAll.OldListDeleted.Count()}");
                        Logger.Info($"{Dex}|LOADED ALL ADDED|{loadedAll.OldListAdded.Count()}");

                        var latestNotActive = latestAll.ListResponse.Where(t => !t.Active).ToList();
                        var latestActive    = latestAll.ListResponse.Where(t => t.Active).ToList();

                        var loadedNotActive = loadedAll.OldListDeleted.ToList();
                        var loadedActive    = loadedAll.OldListAdded.ToList();

                        var recentlyAddedToActive =
                            DexTokenCompare.AddedTokens(loadedActive, latestActive, TokenActionType.KYBER_ADDED_TO_ACTIVE, DexType.KYBER);
                        var recentlyDeletedFromActive =
                            DexTokenCompare.DeletedTokens(loadedActive, latestActive, TokenActionType.KYBER_DELETED_FROM_ACTIVE, DexType.KYBER);

                        var recentlyAddedToNotActive =
                            DexTokenCompare.AddedTokens(loadedNotActive, latestNotActive, TokenActionType.KYBER_ADDED_TO_NOT_ACTIVE, DexType.KYBER);
                        var recentlyDeletedFromNotActive =
                            DexTokenCompare.DeletedTokens(loadedNotActive, latestNotActive, TokenActionType.KYBER_DELETED_FROM_NOT_ACTIVE, DexType.KYBER);

                        loadedAll.OldListDeleted.AddRange(recentlyAddedToNotActive);
                        foreach (var item in recentlyDeletedFromNotActive)
                        {
                            var toDelete = loadedAll.OldListDeleted.FirstOrDefault(t => t.Id == item.Id);
                            if (!(toDelete is null))
                            {
                                loadedAll.OldListDeleted.Remove(toDelete);
                            }
                        }
                        loadedAll.OldListAdded.AddRange(recentlyAddedToActive);
                        foreach (var item in recentlyDeletedFromActive)
                        {
                            var toDelete = loadedAll.OldListAdded.FirstOrDefault(t => t.Id == item.Id);
                            if (!(toDelete is null))
                            {
                                loadedAll.OldListAdded.Remove(toDelete);
                            }
                        }

                        await _fileService.SetAsync(PathTo.Deleted(Type, storagePath), loadedAll.OldListDeleted);

                        await _fileService.SetAsync(PathTo.Added(Type, storagePath), loadedAll.OldListAdded);

                        await _fileService.SetAsync(PathTo.All(Type, storagePath), latestAll.ListResponse);

                        if (cfg.JobConfig.Notify)
                        {
                            Logger.Info($"{Dex}|TELEGRAM|ON");

                            if (recentlyAddedToActive.AnyAndNotNull())
                            {
                                var filledForSend = await _fetchDataForKyber.FetchData(recentlyAddedToActive);

                                if (filledForSend.AnyAndNotNull())
                                {
                                }
                            }

                            if (recentlyDeletedFromActive.AnyAndNotNull())
                            {
                                var filledForSend = await _fetchDataForKyber.FetchData(recentlyDeletedFromActive);

                                if (filledForSend.AnyAndNotNull())
                                {
                                }
                            }

                            if (recentlyAddedToNotActive.AnyAndNotNull())
                            {
                                var filledForSend = await _fetchDataForKyber.FetchData(recentlyAddedToNotActive);

                                if (filledForSend.AnyAndNotNull())
                                {
                                }
                            }

                            if (recentlyDeletedFromNotActive.AnyAndNotNull())
                            {
                                var filledForSend = await _fetchDataForKyber.FetchData(recentlyDeletedFromNotActive);

                                if (filledForSend.AnyAndNotNull())
                                {
                                }
                            }

                            var notifiedAddedToActive = await _notificationFromKyber.SendAsync(recentlyAddedToActive);

                            if (notifiedAddedToActive.Success)
                            {
                                Logger.Info($"{Dex}|TELEGRAM|ADDED TO ACTIVE|SENT");
                            }
                            else
                            {
                                Logger.Warn($"{Dex}|TELEGRAM|ADDED TO ACTIVE|{notifiedAddedToActive.Message}");
                            }

                            var notifiedDeletedFromActive = await _notificationFromKyber.SendAsync(recentlyDeletedFromActive);

                            if (notifiedDeletedFromActive.Success)
                            {
                                Logger.Info($"{Dex}|TELEGRAM|DELETED FROM ACTIVE|SENT");
                            }
                            else
                            {
                                Logger.Warn($"{Dex}|TELEGRAM|DELETED FROM ACTIVE|{notifiedDeletedFromActive.Message}");
                            }

                            var notifiedAddedToNotActive = await _notificationFromKyber.SendAsync(recentlyAddedToNotActive);

                            if (notifiedAddedToNotActive.Success)
                            {
                                Logger.Info($"{Dex}|TELEGRAM|ADDED TO NOT ACTIVE|SENT");
                            }
                            else
                            {
                                Logger.Warn($"{Dex}|TELEGRAM|ADDED TO NOT ACTIVE|{notifiedAddedToNotActive.Message}");
                            }

                            var notifiedDeletedFromNotActive = await _notificationFromKyber.SendAsync(recentlyDeletedFromNotActive);

                            if (notifiedDeletedFromNotActive.Success)
                            {
                                Logger.Info($"{Dex}|TELEGRAM|DELETED FROM NOT ACTIVE|SENT");
                            }
                            else
                            {
                                Logger.Warn($"{Dex}|TELEGRAM|DELETED FROM NOT ACTIVE|{notifiedDeletedFromNotActive.Message}");
                            }
                        }
                    }
                    else
                    {
                        Logger.Error($"{Dex}|{loadedAll.Message}");
                    }
                }
                else
                {
                    Logger.Error($"{Dex}|{latestAll.Message}");
                }

                if (cfg.Success)
                {
                    Logger.Info($"Job: {cfg.JobConfig.Label} - DONE");
                }
            }
            catch (Exception e)
            {
                Logger.Fatal($"{e.GetFullMessage()}");
            }
        }
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var jobConfigFileName = context.JobDetail.JobDataMap["FileName"] as string;
                var storagePath       = context.JobDetail.JobDataMap["StoragePath"] as string;

                var cfg = await _configurationService.GetJobConfigAsync(jobConfigFileName);

                var latestAll = await _dexchange.FetchAllAsync();

                if (latestAll.Success)
                {
                    Logger.Info($"{Dex}|LATEST|{latestAll.ListResponse.Count()}");

                    var loadedAll = await _dexchange.LoadAllAsync(storagePath);

                    if (loadedAll.Success)
                    {
                        Logger.Info($"{Dex}|LOADED ALL|{loadedAll.OldList.Count()}");
                        Logger.Info($"{Dex}|LOADED ALL DELETED|{loadedAll.OldListDeleted.Count()}");
                        Logger.Info($"{Dex}|LOADED ALL ADDED|{loadedAll.OldListAdded.Count()}");

                        var recentlyDeletedAll =
                            DexTokenCompare.DeletedTokens(loadedAll.OldList, latestAll.ListResponse, TokenActionType.DELETED, DexType.UNISWAP);
                        var recentlyAddedAll =
                            DexTokenCompare.AddedTokens(loadedAll.OldList, latestAll.ListResponse, TokenActionType.ADDED, DexType.UNISWAP);

                        loadedAll.OldListDeleted.AddRange(recentlyDeletedAll);
                        loadedAll.OldListAdded.AddRange(recentlyAddedAll);

                        await _fileService.SetAsync(PathTo.Deleted(Type, storagePath), loadedAll.OldListDeleted);

                        await _fileService.SetAsync(PathTo.Added(Type, storagePath), loadedAll.OldListAdded);

                        await _fileService.SetAsync(PathTo.All(Type, storagePath), latestAll.ListResponse);

                        if (cfg.JobConfig.Notify)
                        {
                            Logger.Info($"{Dex}|TELEGRAM|ON");

                            if (recentlyAddedAll.AnyAndNotNull())
                            {
                                var filledForSend = await _fetchDataForUniswap.FetchData(recentlyAddedAll);

                                if (filledForSend.AnyAndNotNull())
                                {
                                }
                            }

                            if (recentlyDeletedAll.AnyAndNotNull())
                            {
                                var filledForSend = await _fetchDataForUniswap.FetchData(recentlyDeletedAll);

                                if (filledForSend.AnyAndNotNull())
                                {
                                }
                            }

                            var notifiedAboutDeleted = await _notificationFromUniswap.SendAsync(recentlyDeletedAll);

                            if (notifiedAboutDeleted.Success)
                            {
                                Logger.Info($"{Dex}|TELEGRAM|DELETED|SENT");
                            }
                            else
                            {
                                Logger.Warn($"{Dex}|TELEGRAM|DELETED|{notifiedAboutDeleted.Message}");
                            }

                            var notifiedAboutAdded = await _notificationFromUniswap.SendAsync(recentlyAddedAll);

                            if (notifiedAboutAdded.Success)
                            {
                                Logger.Info($"{Dex}|TELEGRAM|ADDED|SENT");
                            }
                            else
                            {
                                Logger.Warn($"{Dex}|TELEGRAM|ADDED|{notifiedAboutAdded.Message}");
                            }
                        }
                        else
                        {
                            Logger.Info($"{Dex}|TELEGRAM|OFF");
                        }
                    }
                    else
                    {
                        Logger.Error($"{Dex}|{loadedAll.Message}");
                    }
                }
                else
                {
                    Logger.Error($"{Dex}|{latestAll.Message}");
                }

                if (cfg.Success)
                {
                    Logger.Info($"Job: {cfg.JobConfig.Label} - DONE");
                }
            }
            catch (Exception e)
            {
                Logger.Fatal($"{e.GetFullMessage()}");
            }
        }