Esempio n. 1
0
        private ConcurrentDictionary <int, Tuple <double?, double?> > GetAssets7dAnd30dVariationFromBinanceTicker()
        {
            var pairs     = PairBusiness.ListPairs();
            var usdtPairs = pairs.Where(p => p.QuoteAssetId == AssetUSDId);
            var btcPairs  = pairs.Where(p => !usdtPairs.Any(usdtPair => usdtPair.BaseAssetId == p.BaseAssetId) && p.QuoteAssetId == AssetBTCId);

            var currentValues = new ConcurrentDictionary <int, Tuple <double?, double?> >();

            Parallel.ForEach(usdtPairs,
                             new ParallelOptions()
            {
                MaxDegreeOfParallelism = 5
            },
                             (usdtPair) =>
            {
                var variation = Get7dAnd30dVariation(usdtPair.Symbol);
                currentValues.TryAdd(usdtPair.BaseAssetId, variation);
            });

            Parallel.ForEach(btcPairs,
                             new ParallelOptions()
            {
                MaxDegreeOfParallelism = 5
            },
                             (btcPair) =>
            {
                var variation         = Get7dAnd30dVariation(btcPair.Symbol);
                var totalVariation7d  = GetVariationWithMultiplierQuote(variation.Item1, currentValues[btcPair.QuoteAssetId].Item1);
                var totalVariation30d = GetVariationWithMultiplierQuote(variation.Item2, currentValues[btcPair.QuoteAssetId].Item2);
                currentValues.TryAdd(btcPair.BaseAssetId, new Tuple <double?, double?>(totalVariation7d, totalVariation30d));
            });

            return(currentValues);
        }
Esempio n. 2
0
        private AssetResponse GetAssetResponse(User loggedUser, AssetCurrentValue assetCurrentValue, int?totalFollowers, List <AdvisorRanking> advisors)
        {
            var totalAdvisors = advisors != null?advisors.Where(c => c.AdvisorProfit.Any(a => a.AssetId == assetCurrentValue.Id && a.OrderStatusType != OrderStatusType.Open)) : null;

            var ratingAdvisors = advisors != null?advisors.SelectMany(c => c.AdvisorProfit.Where(a => a.AssetId == assetCurrentValue.Id && a.OrderStatusType == OrderStatusType.Executed).Select(a => a)) : null;

            var distribution = ratingAdvisors != null && ratingAdvisors.Any() ? ratingAdvisors.GroupBy(c => c.Type).Select(g => new RecommendationDistributionResponse()
            {
                Type = g.Key, Total = g.Sum(c => c.OrderCount)
            }).ToList() : new List <RecommendationDistributionResponse>();
            var mode = GetAssetModeType(distribution);

            return(new AssetResponse()
            {
                AssetId = assetCurrentValue.Id,
                Code = assetCurrentValue.Code,
                Name = assetCurrentValue.Name,
                Mode = mode,
                Following = loggedUser?.FollowedAssets?.Any(c => c == assetCurrentValue.Id),
                ShortSellingEnabled = assetCurrentValue.ShortSellingEnabled,
                NumberOfFollowers = totalFollowers,
                TotalAdvisors = totalAdvisors != null && totalAdvisors.Any() ? totalAdvisors.Select(c => c.Id).Distinct().Count() : 0,
                TotalRatings = ratingAdvisors != null && ratingAdvisors.Any() ? ratingAdvisors.Sum(c => c.OrderCount) : 0,
                LastValue = assetCurrentValue.CurrentValue,
                AskValue = assetCurrentValue.AskValue,
                BidValue = assetCurrentValue.BidValue,
                MarketCap = assetCurrentValue.MarketCap,
                CirculatingSupply = assetCurrentValue.CirculatingSupply,
                Variation24h = assetCurrentValue.Variation24Hours,
                Variation7d = assetCurrentValue.Variation7Days,
                Variation30d = assetCurrentValue.Variation30Days,
                Pair = PairBusiness.GetBaseQuotePair(assetCurrentValue.Id),
                RecommendationDistribution = distribution
            });
        }
Esempio n. 3
0
 public List <SimpleAssetResponse> ListAssetsOrderedByMarketCap()
 {
     return(ListAssets(true).Select(c => new SimpleAssetResponse()
     {
         Id = c.Id,
         Name = c.Name,
         Type = c.Type,
         Code = c.Code,
         MarketCap = c.MarketCap,
         CirculatingSupply = c.CirculatingSupply,
         ShortSellingEnabled = c.ShortSellingEnabled,
         Pair = PairBusiness.GetBaseQuotePair(c.Id)
     }).OrderByDescending(c => c.MarketCap ?? 0).ThenBy(c => c.Name).ToList());
 }
Esempio n. 4
0
        private Dictionary <int, TickerDataModel> GetAssetsCurrentValuesAndVariationFromBinanceTicker()
        {
            var ticker    = BinanceBusiness.GetTicker24h();
            var pairs     = PairBusiness.ListPairs();
            var usdtPairs = pairs.Where(p => p.QuoteAssetId == AssetUSDId);
            var btcPairs  = pairs.Where(p => !usdtPairs.Any(usdtPair => usdtPair.BaseAssetId == p.BaseAssetId) && p.QuoteAssetId == AssetBTCId);

            var currentValues = new Dictionary <int, TickerDataModel>();

            foreach (var usdtPair in usdtPairs)
            {
                var currentTicker = ticker.FirstOrDefault(t => t.Symbol == usdtPair.Symbol);
                if (currentTicker != null)
                {
                    currentValues.Add(usdtPair.BaseAssetId, new TickerDataModel()
                    {
                        CurrentValue     = currentTicker.LastPrice,
                        Variation24Hours = currentTicker.PriceChangePercent / 100.0,
                        AskValue         = currentTicker.AskPrice,
                        BidValue         = currentTicker.BidPrice
                    });
                }
            }

            foreach (var btcPair in btcPairs)
            {
                var currentTicker = ticker.FirstOrDefault(t => t.Symbol == btcPair.Symbol);
                if (currentTicker != null && currentValues.ContainsKey(btcPair.QuoteAssetId))
                {
                    currentValues.Add(btcPair.BaseAssetId, new TickerDataModel()
                    {
                        CurrentValue     = currentTicker.LastPrice * currentValues[btcPair.QuoteAssetId].CurrentValue,
                        Variation24Hours = GetVariation24h(currentTicker.LastPrice, currentTicker.PriceChangePercent / 100.0, currentValues[btcPair.QuoteAssetId].CurrentValue, currentValues[btcPair.QuoteAssetId].Variation24Hours.Value),
                        AskValue         = currentTicker.AskPrice * currentValues[btcPair.QuoteAssetId].AskValue,
                        BidValue         = currentTicker.BidPrice * currentValues[btcPair.QuoteAssetId].BidValue
                    });
                }
            }

            return(currentValues);
        }
        private AdvisorAssetResponse GetAdvisorAssetResponse(AdvisorProfit advisorProfit, List <DomainObjects.Asset.Asset> assets)
        {
            var asset = assets?.FirstOrDefault(c => c.Id == advisorProfit.AssetId);

            return(new AdvisorAssetResponse()
            {
                AssetId = advisorProfit.AssetId,
                AssetName = asset?.Name,
                AssetCode = asset?.Code,
                Pair = PairBusiness.GetBaseQuotePair(advisorProfit.AssetId),
                Type = advisorProfit.Type,
                OrderCount = advisorProfit.OrderCount,
                SuccessCount = advisorProfit.SuccessCount,
                TotalInvested = advisorProfit.TotalDollar - advisorProfit.SummedProfitDollar,
                TotalQuantity = advisorProfit.TotalQuantity,
                TotalProfit = advisorProfit.SummedProfitDollar,
                TotalFee = advisorProfit.TotalFee,
                AveragePrice = (advisorProfit.TotalDollar - advisorProfit.SummedProfitDollar - advisorProfit.TotalFee ?? 0) / advisorProfit.TotalQuantity,
                SuccessRate = (double)advisorProfit.SuccessCount / advisorProfit.OrderCount,
                AverageReturn = advisorProfit.SummedProfitDollar / (advisorProfit.TotalDollar - advisorProfit.SummedProfitDollar),
                TotalVirtual = advisorProfit.TotalDollar,
                SummedTradeMinutes = advisorProfit.SummedTradeMinutes
            });
        }
        public TickerDataModel GetRealCurrentValue(int assetId)
        {
            TickerDataModel currentValue = null;
            var             pairs        = PairBusiness.ListPairs(new int[] { assetId });

            if (pairs.Any())
            {
                var usdQuote = pairs.FirstOrDefault(c => c.QuoteAssetId == AssetUSDId);
                if (usdQuote != null)
                {
                    var ticker = BinanceBusiness.GetTicker24h(usdQuote.Symbol);
                    if (ticker != null)
                    {
                        currentValue = new TickerDataModel()
                        {
                            AskValue         = ticker.AskPrice,
                            BidValue         = ticker.BidPrice,
                            CurrentValue     = ticker.LastPrice,
                            Variation24Hours = ticker.PriceChangePercent / 100
                        };
                    }
                }
                else
                {
                    var btcQuote = pairs.FirstOrDefault(c => c.QuoteAssetId == AssetBTCId);
                    if (btcQuote != null)
                    {
                        var btcPair = PairBusiness.ListPairs(new int[] { AssetBTCId }, new int[] { AssetUSDId }).FirstOrDefault();
                        if (btcPair != null)
                        {
                            var btcValue = BinanceBusiness.GetTicker24h(btcQuote.Symbol);
                            var btcPrice = BinanceBusiness.GetTicker24h(btcPair.Symbol);
                            if (btcPrice != null && btcValue != null)
                            {
                                currentValue = new TickerDataModel()
                                {
                                    AskValue         = btcValue.AskPrice * btcPrice.AskPrice,
                                    BidValue         = btcValue.BidPrice * btcPrice.BidPrice,
                                    CurrentValue     = btcValue.LastPrice * btcPrice.LastPrice,
                                    Variation24Hours = AssetValueBusiness.GetVariation24h(btcValue.LastPrice, btcValue.PriceChangePercent / 100, btcPrice.LastPrice, btcPrice.PriceChangePercent / 100)
                                };
                            }
                        }
                    }
                }
            }
            if (currentValue == null)
            {
                var assetCurrentValue = ListAllAssets(true, new int[] { assetId }).FirstOrDefault();
                if (assetCurrentValue != null && assetCurrentValue.UpdateDate > Data.GetDateTimeNow().AddMinutes(-2))
                {
                    currentValue = new TickerDataModel()
                    {
                        AskValue         = assetCurrentValue.AskValue,
                        BidValue         = assetCurrentValue.BidValue,
                        CurrentValue     = assetCurrentValue.CurrentValue,
                        Variation24Hours = assetCurrentValue.Variation24Hours
                    }
                }
                ;
            }
            return(currentValue);
        }
    }