Exemple #1
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();
            }
        }
        public List <AssetResponse.ValuesResponse> FilterValueResponse(int assetId, DateTime?dateTime)
        {
            dateTime = dateTime ?? Data.GetDateTimeNow().AddDays(-30);
            var asset = AssetBusiness.GetById(assetId);
            var days  = Math.Ceiling(Data.GetDateTimeNow().Subtract(dateTime.Value).TotalDays);

            return(CoinGeckoBusiness.GetAssetValues(asset.CoinGeckoId, (int)days));
        }
Exemple #3
0
        private async Task UpdateIconsAsync(IEnumerable <AssetResult> assetResults)
        {
            var assets = AssetBusiness.ListAll();

            foreach (var assetData in assetResults)
            {
                var asset = assets.FirstOrDefault(c => c.CoinGeckoId == assetData.Id);
                if (asset != null)
                {
                    await UploadAssetIconAsync(asset.Id, assetData.ImageUrl);
                }
            }
        }
Exemple #4
0
        private async Task CreateNotIncludedAssetsAsync(IEnumerable <AssetResult> assetResults)
        {
            var assets = AssetBusiness.ListAll();

            foreach (var asset in assetResults)
            {
                if (!asset.Price.HasValue)
                {
                    continue;
                }

                if (assets.Any(c => c.CoinGeckoId == asset.Id))
                {
                    continue;
                }

                var newAsset = new DomainObjects.Asset.Asset()
                {
                    Code                = asset.Symbol.ToUpper(),
                    Name                = asset.Name,
                    Type                = AssetType.Crypto.Value,
                    MarketCap           = asset.MarketCap,
                    CirculatingSupply   = asset.CirculatingSupply,
                    ShortSellingEnabled = true,
                    CoinGeckoId         = asset.Id
                };

                using (var transaction = TransactionalDapperCommand)
                {
                    transaction.Insert(newAsset);
                    transaction.Insert(new AssetCurrentValue()
                    {
                        CurrentValue = asset.Price.Value, Id = newAsset.Id, UpdateDate = Data.GetDateTimeNow()
                    });
                    transaction.Commit();
                }
                await UploadAssetIconAsync(newAsset.Id, asset.ImageUrl);
            }
        }