Ejemplo n.º 1
0
 public static List <Portfolio> Share(string userId)
 {
     using (var context = new FantasyPortfolio_DBEntities()) {
         var portfolios = context.Portfolios.Where(d => d.UserId == userId && d.RoundId == Round.CurrentRound);
         return(portfolios.ToList());
     }
 }
Ejemplo n.º 2
0
        public static async Task <List <Coin> > GetTickers(string tickerName)
        {
            var coinList = new List <Coin>();

            using (var context = new FantasyPortfolio_DBEntities()) {
                var tickerFormatted = tickerName.ToUpper().Trim();

                var listings = await TickerModule.priceClientNew.GetListingsAsync();

                var listingSingle = listings.Data.Where(d => d.Symbol == tickerFormatted).ToList();

                if (listingSingle.Count == 0)
                {
                    listingSingle = listings.Data.Where(d => string.Equals(d.WebsiteSlug, tickerFormatted, StringComparison.CurrentCultureIgnoreCase)).ToList();
                }

                foreach (var listing in listingSingle)
                {
                    var tickerResponse = await TickerModule.priceClientNew.GetTickerAsync((int)listing.Id);

                    //If there are more than one listing of the same name, search the database using website slug, otherwise use the ticker name.
                    Coin coin;
                    if (listingSingle.Count > 1)
                    {
                        coin = context.Coins.FirstOrDefault(d => d.TickerName == tickerResponse.Data.WebsiteSlug);
                    }
                    else
                    {
                        coin = context.Coins.FirstOrDefault(d => d.TickerName == tickerResponse.Data.WebsiteSlug || d.TickerName == tickerResponse.Data.Symbol);
                    }
                    if (coin == null)
                    {
                        var newCoin = new Coin {
                            TickerId    = (int)listing.Id,
                            LastUpdated = DateTime.Now,
                            //If there are more than one listing of the same name, use the slug, otherwise use the symbol
                            TickerName = listingSingle.Count > 1 ? listing.WebsiteSlug : listing.Symbol
                        };
                        context.Coins.Add(newCoin);
                        if (newCoin.PriceUSD == 0)
                        {
                            var valuePrice = tickerResponse.Data.Quotes.FirstOrDefault(d => d.Key == "USD").Value.Price;
                            if (valuePrice != null)
                            {
                                newCoin.PriceUSD = (decimal)valuePrice;
                            }
                            newCoin.Volume24 = (decimal?)tickerResponse.Data.Quotes.FirstOrDefault(d => d.Key == "USD").Value.Volume24H;
                        }
                        context.SaveChanges();
                        coinList.Add(newCoin);
                    }
                    else
                    {
                        coinList.Add(coin);
                    }
                }
                return(coinList);
            }
        }
Ejemplo n.º 3
0
        public static async Task UpdateCoinValue(int coinId)
        {
            using (var context = new FantasyPortfolio_DBEntities()) {
                var coin = context.Coins.FirstOrDefault(d => d.Id == coinId);
                if (coin != null)
                {
                    var ticker = await TickerModule.priceClientNew.GetTickerAsync(coin.TickerId);

                    coin.LastUpdated = DateTime.Now;
                    var valuePrice = ticker.Data.Quotes.FirstOrDefault(d => d.Key == "USD").Value.Price;
                    if (valuePrice != null)
                    {
                        coin.PriceUSD = (decimal)valuePrice;
                    }
                    coin.Volume24 = (decimal?)ticker.Data.Quotes.FirstOrDefault(d => d.Key == "USD").Value.Volume24H;
                    context.SaveChanges();
                    Console.WriteLine($"{DateTime.Now} - Updated {coin.TickerName} price.");
                }
            }
        }
Ejemplo n.º 4
0
        public static bool Join(string userId)
        {
            using (var context = new FantasyPortfolio_DBEntities()) {
                var users = context.Portfolios.Where(d => d.RoundId == Round.CurrentRound).Select(m => m.UserId).Distinct();
                if (users.Contains(userId))
                {
                    return(false);
                }

                var user = new Portfolio {
                    RoundId    = Round.CurrentRound,
                    CoinAmount = 10000,
                    TickerId   = -1,
                    UserId     = userId
                };
                context.Portfolios.Add(user);
                context.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 5
0
        public static async Task <Coin> GetTicker(int tickerId)
        {
            using (var context = new FantasyPortfolio_DBEntities()) {
                var coin = context.Coins.FirstOrDefault(d => d.TickerId == tickerId);

                var listings = await TickerModule.priceClientNew.GetListingsAsync();

                var listingSingle = listings.Data.OrderByDescending(d => d.Id).FirstOrDefault(d => d.Id == tickerId);
                if (listingSingle != null)
                {
                    var tickerResponse = await TickerModule.priceClientNew.GetTickerAsync((int)listingSingle.Id);

                    if (coin == null)
                    {
                        coin = new Coin {
                            TickerId    = (int)listingSingle.Id,
                            TickerName  = listingSingle.Symbol,
                            LastUpdated = DateTime.Now
                        };
                        context.Coins.Add(coin);
                    }
                    else
                    {
                        context.Coins.Attach(coin);
                    }
                    var valuePrice = tickerResponse.Data.Quotes.FirstOrDefault(d => d.Key == "USD").Value.Price;
                    coin.Volume24 = (decimal?)tickerResponse.Data.Quotes.FirstOrDefault(d => d.Key == "USD").Value.Volume24H;
                    if (valuePrice != null)
                    {
                        coin.PriceUSD = (decimal)valuePrice;
                    }
                    context.SaveChanges();
                }
                return(coin);
            }
        }
Ejemplo n.º 6
0
 public static string GetTickerName(int tickerId)
 {
     using (var context = new FantasyPortfolio_DBEntities()) {
         return(context.Coins.FirstOrDefault(d => d.TickerId == tickerId)?.TickerName);
     }
 }
Ejemplo n.º 7
0
 public static List <FlipLeaderboard> GetLeaderboardBySpend()
 {
     using (var context = new FantasyPortfolio_DBEntities()) {
         return(context.FlipLeaderboard.OrderByDescending(u => u.TotalBet.Value).Take(10).ToList());
     }
 }
Ejemplo n.º 8
0
 public static FlipResultStatistics GetStatistics()
 {
     using (var context = new FantasyPortfolio_DBEntities()) {
         return(context.FlipResultStatistics.FirstOrDefault());
     }
 }