Exemplo n.º 1
0
        public IEnumerable <AssetResponse> ListAssetsFollowedByUser(int userId)
        {
            var assetValues   = AssetCurrentValueBusiness.ListAssetsFollowedByUser(userId);
            var advisors      = AdvisorRankingBusiness.ListAdvisorsFullData();
            var loggedUser    = GetValidUser();
            var assetResponse = assetValues.Select(asset => GetAssetResponse(loggedUser, asset, null, advisors));

            return(assetResponse.OrderByDescending(asset => asset.MarketCap));
        }
Exemplo n.º 2
0
        private IEnumerable <AssetResponse> ListAssetResult(int?forcedAssetId = null)
        {
            var selectAssets = forcedAssetId.HasValue ? new int[] { forcedAssetId.Value } : null;
            List <AssetCurrentValue> assets   = null;
            List <AdvisorRanking>    advisors = null;

            Parallel.Invoke(() => assets   = AssetCurrentValueBusiness.ListAllAssets(true, selectAssets),
                            () => advisors = AdvisorRankingBusiness.ListAdvisorsFullData());

            var user = GetLoggedUser();

            return(assets.Select(c => GetAssetResponse(user, c, null, advisors)));
        }
Exemplo n.º 3
0
        public IEnumerable <AssetResponse> ListTrendingAssets(int?listSize)
        {
            var numberOfRecordsInResult = listSize ?? 10;
            var numberOfDays            = 7;
            var statusList = new int[3] {
                OrderStatusType.Executed.Value, OrderStatusType.Close.Value, OrderStatusType.Finished.Value
            };

            var ids = OrderBusiness.ListTrendingAssetIdsBasedOnOrders(statusList, numberOfRecordsInResult, numberOfDays).ToList();

            var assets = AssetCurrentValueBusiness.ListAllAssets(true, ids);

            var loggedUser    = GetLoggedUser();
            var assetResponse = assets.Select(asset => GetAssetResponse(loggedUser, asset, null, null)).OrderBy(asset => ids.IndexOf(asset.AssetId));

            return(assetResponse);
        }
Exemplo n.º 4
0
        private void UpdateAsset7dAnd30dValues(ConcurrentDictionary <int, Tuple <double?, double?> > values)
        {
            var currentValues = new ConcurrentBag <AssetCurrentValue>();

            Parallel.ForEach(values, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 7
            }, assetToUpdate =>
            {
                currentValues.Add(new AssetCurrentValue()
                {
                    Id              = assetToUpdate.Key,
                    Variation7Days  = assetToUpdate.Value.Item1,
                    Variation30Days = assetToUpdate.Value.Item2
                });
            });
            AssetCurrentValueBusiness.UpdateAssetValue7And30Days(currentValues);
        }
Exemplo n.º 5
0
        private void UpdateAssetCurrentValues(DateTime currentDate, Dictionary <int, TickerDataModel> lastValues)
        {
            var currentValues = new ConcurrentBag <AssetCurrentValue>();

            Parallel.ForEach(lastValues, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 7
            }, assetToUpdate =>
            {
                currentValues.Add(new AssetCurrentValue()
                {
                    Id               = assetToUpdate.Key,
                    UpdateDate       = currentDate,
                    CurrentValue     = assetToUpdate.Value.CurrentValue,
                    Variation24Hours = assetToUpdate.Value.Variation24Hours,
                    AskValue         = assetToUpdate.Value.AskValue,
                    BidValue         = assetToUpdate.Value.BidValue
                });
            });
            AssetCurrentValueBusiness.UpdateAssetCurrentValues(currentValues);
        }
Exemplo n.º 6
0
        private void UpdateAssetsMarketcap(IEnumerable <AssetResult> assetResults)
        {
            List <DomainObjects.Asset.Asset> assets             = null;
            List <AssetCurrentValue>         assetCurrentValues = null;

            Parallel.Invoke(() => assets = AssetBusiness.ListAssets(true), () => assetCurrentValues = AssetCurrentValueBusiness.ListAllAssets(true));

            var pendingToInsertValue = assets.Where(c => !assetCurrentValues.Any(v => v.Id == c.Id));
            var resultList           = assetResults.Where(c => (c.MarketCap.HasValue && c.MarketCap > 0) || (pendingToInsertValue.Any() && c.Price.HasValue));

            var assetsToUpdate        = new List <DomainObjects.Asset.Asset>();
            var currentValuesToInsert = new List <AssetCurrentValue>();

            foreach (var assetValue in resultList)
            {
                var asset = assets.FirstOrDefault(c => c.CoinGeckoId == assetValue.Id);
                if (asset != null)
                {
                    if (assetValue.MarketCap.HasValue || assetValue.CirculatingSupply.HasValue)
                    {
                        var update = false;
                        if (assetValue.MarketCap.HasValue && assetValue.MarketCap != asset.MarketCap && assetValue.MarketCap > 0)
                        {
                            asset.MarketCap = assetValue.MarketCap;
                            update          = true;
                        }
                        if (assetValue.CirculatingSupply.HasValue && assetValue.CirculatingSupply != asset.CirculatingSupply && assetValue.CirculatingSupply > 0)
                        {
                            asset.CirculatingSupply = assetValue.CirculatingSupply;
                            update = true;
                        }
                        if (update)
                        {
                            assetsToUpdate.Add(asset);
                        }
                    }
                    if (assetValue.Price.HasValue && pendingToInsertValue.Any(c => c.Id == asset.Id))
                    {
                        currentValuesToInsert.Add(new AssetCurrentValue()
                        {
                            CurrentValue = assetValue.Price.Value, Id = asset.Id, UpdateDate = Data.GetDateTimeNow()
                        });
                    }
                }
            }
            using (var transaction = TransactionalDapperCommand)
            {
                foreach (var asset in assetsToUpdate)
                {
                    transaction.Update(asset);
                }
                foreach (var value in currentValuesToInsert)
                {
                    transaction.Insert(value);
                }

                transaction.Commit();
            }
        }