Ejemplo n.º 1
0
        public List <Distribution> List(IEnumerable <int> projectionIds)
        {
            if (projectionIds.Count() == 0)
            {
                return(new List <Distribution>());
            }

            var distributions = Data.List(projectionIds);
            var assets        = AssetBusiness.ListAssets();

            distributions.ForEach(c => c.Asset = assets.Single(a => a.Id == c.AssetId));
            return(distributions);
        }
Ejemplo n.º 2
0
        public AdvisorResponse GetAdvisorData(int advisorId)
        {
            AdvisorRanking advisor = null;
            List <DomainObjects.Asset.Asset> assets            = null;
            List <FollowAdvisor>             advisorsFollowers = null;
            AdvisorRankingHistory            advisorHistory    = null;

            Parallel.Invoke(() => advisor           = AdvisorRankingBusiness.GetAdvisorFullData(advisorId),
                            () => assets            = AssetBusiness.ListAssets(false),
                            () => advisorsFollowers = FollowAdvisorBusiness.ListFollowers(new int[] { advisorId }, false),
                            () => advisorHistory    = AdvisorRankingHistoryBusiness.GetLastAdvisorRankingAndProfit(advisorId));

            return(AdvisorRankingBusiness.GetAdvisorResponse(advisor, advisor.TotalAdvisors, advisorsFollowers, GetLoggedUser(), assets, advisorHistory, null, null));
        }
Ejemplo n.º 3
0
        public RiskType GetRisk(double projectionValue, Dictionary <int, double> distribution)
        {
            IEnumerable <DomainObjects.Asset.Asset> assets = AssetBusiness.ListAssets().Where(c => distribution.ContainsKey(c.Id));
            double cryptoAssetsPercentage = assets.Count(c => c.Type == AssetType.Crypto.Value) / assets.Count() * 100.0;

            if (cryptoAssetsPercentage == 0)
            {
                if (projectionValue >= 3)
                {
                    return(RiskType.VeryHigh);
                }
                else if (projectionValue >= 2)
                {
                    return(RiskType.High);
                }
                else if (projectionValue >= 1)
                {
                    return(RiskType.Medium);
                }
                else if (projectionValue >= 0.5)
                {
                    return(RiskType.Low);
                }
                else
                {
                    return(RiskType.VeryLow);
                }
            }
            else if (cryptoAssetsPercentage <= 10)
            {
                if (projectionValue >= 2)
                {
                    return(RiskType.VeryHigh);
                }
                else if (projectionValue >= 1)
                {
                    return(RiskType.High);
                }
                else if (projectionValue >= 0.5)
                {
                    return(RiskType.Medium);
                }
                else
                {
                    return(RiskType.Low);
                }
            }
            else if (cryptoAssetsPercentage <= 30)
            {
                if (projectionValue >= 1)
                {
                    return(RiskType.VeryHigh);
                }
                else if (projectionValue >= 0.5)
                {
                    return(RiskType.High);
                }
                else
                {
                    return(RiskType.Medium);
                }
            }
            else if (cryptoAssetsPercentage <= 50)
            {
                if (projectionValue >= 0.5)
                {
                    return(RiskType.VeryHigh);
                }
                else
                {
                    return(RiskType.High);
                }
            }
            else
            {
                return(RiskType.VeryHigh);
            }
        }
Ejemplo n.º 4
0
 public List <Asset> ListAssets()
 {
     return(AssetBusiness.ListAssets());
 }
Ejemplo n.º 5
0
        public async Task UpdateAssetEventsAsync()
        {
            var startDate = Data.GetDateTimeNow().AddDays(-1).Date;

            List <DomainObjects.Asset.Asset> assets     = null;
            List <AssetEventCategory>        categories = null;
            List <AssetEvent> assetEvents = null;
            List <Record>     events      = null;

            Parallel.Invoke(() => assets      = AssetBusiness.ListAssets(true),
                            () => categories  = AssetEventCategoryBusiness.ListCategories(),
                            () => assetEvents = Data.ListAssetEventsWithPagination(startDate, null, null, null, null, null),
                            () => events      = CoinMarketCalBusiness.ListEvents(startDate));

            events = events.OrderBy(c => c.FormattedCreatedDate).ThenBy(c => c.FormattedEventDate).ToList();

            foreach (var e in events)
            {
                bool updateProofImage     = false;
                bool isNewEvent           = false;
                var  linkCategoryToDelete = new List <LinkEventCategory>();
                var  linkCategoryToInsert = new List <LinkEventCategory>();
                var  linkAssetToDelete    = new List <LinkEventAsset>();
                var  linkAssetToInsert    = new List <LinkEventAsset>();

                var coinsId         = e.Coins.Select(c => c.Id).Distinct().ToHashSet();
                var eventAssets     = assets.Where(c => coinsId.Contains(c.CoinMarketCalId)).ToList();
                var categoriesId    = e.Categories.Select(c => c.Id).Distinct().ToHashSet();
                var eventCategories = categories.Where(c => categoriesId.Contains(c.Id)).ToList();

                if (eventAssets.Any())
                {
                    var workingEvent = assetEvents.FirstOrDefault(c => c.ExternalId == e.Id.ToString());
                    if (workingEvent == null)
                    {
                        isNewEvent       = true;
                        updateProofImage = true;
                        workingEvent     = new AssetEvent()
                        {
                            ExternalId   = e.Id.ToString(),
                            CreationDate = Data.GetDateTimeNow()
                        };
                        linkCategoryToInsert = eventCategories.Select(c => new LinkEventCategory()
                        {
                            AssetEventCategoryId = c.Id
                        }).ToList();
                        linkAssetToInsert = eventAssets.Select(c => new LinkEventAsset()
                        {
                            AssetId = c.Id
                        }).ToList();
                    }
                    else
                    {
                        linkCategoryToDelete = workingEvent.LinkEventCategory.Where(c => !eventCategories.Any(a => a.Id == c.AssetEventCategoryId)).ToList();
                        linkAssetToDelete    = workingEvent.LinkEventAsset.Where(c => !eventAssets.Any(a => a.Id == c.AssetId)).ToList();
                        linkCategoryToInsert = eventCategories.Where(c => !workingEvent.LinkEventCategory.Any(a => a.AssetEventCategoryId == c.Id)).Select(c => new LinkEventCategory()
                        {
                            AssetEventCategoryId = c.Id,
                            AssetEventId         = workingEvent.Id
                        }).ToList();
                        linkAssetToInsert = eventAssets.Where(c => !workingEvent.LinkEventAsset.Any(a => a.AssetId == c.Id)).Select(c => new LinkEventAsset()
                        {
                            AssetId      = c.Id,
                            AssetEventId = workingEvent.Id
                        }).ToList();

                        if (workingEvent.Title == e.Title && workingEvent.Description == e.Description && workingEvent.EventDate == e.FormattedEventDate &&
                            workingEvent.ExternalCreationDate == e.FormattedCreatedDate && workingEvent.CanOccurBefore == e.CanOccurBefore &&
                            workingEvent.ReliablePercentage == e.Percentage && workingEvent.Source == e.Source && workingEvent.Proof == e.Proof &&
                            linkCategoryToDelete.Count == 0 && linkAssetToDelete.Count == 0 && linkCategoryToInsert.Count == 0 && linkAssetToInsert.Count == 0)
                        {
                            continue;
                        }

                        updateProofImage = workingEvent.Proof != e.Proof;
                    }

                    UpdateAssetEventData(workingEvent, e);

                    try
                    {
                        using (var transaction = TransactionalDapperCommand)
                        {
                            if (isNewEvent)
                            {
                                transaction.Insert(workingEvent);
                            }
                            else
                            {
                                transaction.Update(workingEvent);
                            }

                            foreach (var linkCategory in linkCategoryToDelete)
                            {
                                transaction.Delete(linkCategory);
                            }
                            foreach (var linkCategory in linkCategoryToInsert)
                            {
                                linkCategory.AssetEventId = workingEvent.Id;
                                transaction.Insert(linkCategory);
                            }

                            foreach (var linkAsset in linkAssetToDelete)
                            {
                                transaction.Delete(linkAsset);
                            }
                            foreach (var linkAsset in linkAssetToInsert)
                            {
                                linkAsset.AssetEventId = workingEvent.Id;
                                transaction.Insert(linkAsset);
                            }

                            transaction.Commit();
                        }
                        if (updateProofImage)
                        {
                            var    fileName    = $"{workingEvent.Id}.png";
                            var    contentType = workingEvent.Proof.ToLower().EndsWith("png") ? "image/png" : workingEvent.Proof.ToLower().EndsWith("pdf") ? "application/pdf" : "image/jpeg";
                            byte[] file;
                            using (var client = new WebClient())
                            {
                                file = client.DownloadData(workingEvent.Proof);
                            }
                            if (!await AzureStorageBusiness.UploadAssetEventFromByteAsync(fileName, file, contentType))
                            {
                                throw new BusinessException($"Error on upload asset event proof image. (Id {workingEvent.Id} - Url {workingEvent.Proof}");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var telemetry = new TelemetryClient();
                        telemetry.TrackEvent($"AssetEventBusiness.UpdateAssetEvents.Id.{e?.Id}");
                        telemetry.TrackException(ex);
                    }
                }
            }
        }