Esempio n. 1
0
        public async Task WatchAsync(
            [Summary("The token address")] string address, decimal priceUsd)
        {
            var tokenAttempt = await this._tokenRequester.GetTokenData(address);

            if (tokenAttempt == null)
            {
                var embed = new EmbedBuilder {
                    Title       = "Address does not exist",
                    Description = $"Address **{address}** does not exist on BscScan!",
                    Color       = Color.Red
                };

                await this.ReplyAsync(embed : embed.Build());
            }
            else
            {
                // We can also access the channel from the Command Context.
                var token = new WatchedToken(this.Context.Message.Author.Id, address, priceUsd);
                _tokenWatcher.AddToken(token);

                var embed = new EmbedBuilder {
                    Title       = "Address added to watchlist",
                    Description = $"**{address}** has been added to the watchlist",
                    Color       = Color.Green
                }.WithCurrentTimestamp();;

                await this.ReplyAsync(embed : embed.Build());
            }
        }
Esempio n. 2
0
        public static List <WatchedToken> Update(DbCryptoContext db)
        {
            List <WatchedToken> res           = new List <WatchedToken>();
            List <WatchedToken> resTwoEntries = new List <WatchedToken>();

            List <WatchedToken> counterTokens = new List <WatchedToken>();

            foreach (Exchange ex in db.Exchange)
            {
                List <WatchedToken> wt = db.WatchedTokens.Where(w => w.Exchange.ID == ex.ID).ToList();

                List <Wallet> wallets = db.Wallets.Where(w => w.Exchange.ID == ex.ID).ToList();
                if (wallets.Count == 0)
                {
                    continue;
                }

                foreach (Wallet w in wallets)
                {
                    BuildURLForWalletBalance(w.Address);
                    List <WatchedToken> responsedTokens = GetWalletTokens(w.Address);

                    foreach (WatchedToken token in responsedTokens)
                    {
                        if (wt.FirstOrDefault(t => t.Name == token.Name) == null)
                        {
                            WatchedToken watchToken = new WatchedToken()
                            {
                                DateTime  = token.DateTime,
                                Exchange  = ex,
                                Name      = token.Name,
                                ShortName = token.ShortName,
                                Comment   = w.Address
                            };

                            res.Add(watchToken);
                        }
                        else
                        {
                            if (wt.FirstOrDefault(t => t.Name == token.Name) != null && counterTokens.Where(t => t.Name == token.Name).Count() == 0 &&
                                res.Where(t => t.Name == token.Name).Count() == 0)
                            {
                                counterTokens.Add(wt.FirstOrDefault(t => t.Name == token.Name));
                            }
                        }
                    }

                    wt = db.WatchedTokens.Where(wtc => wtc.Exchange.ID == ex.ID).ToList();
                }

                foreach (WatchedToken token in counterTokens)
                {
                    WatchedToken tfu = db.WatchedTokens.Where(wtc => wtc.Exchange.ID == ex.ID).FirstOrDefault(t => t.Name == token.Name);

                    if (tfu != null)
                    {
                        tfu.Counter++;
                        db.SaveChanges();
                        if (tfu.Counter == 2)
                        {
                            resTwoEntries.Add(tfu);
                        }
                    }
                }
            }

            db.WatchedTokens.RemoveRange(db.WatchedTokens.Where(t => t.Counter == 0));
            db.SaveChanges();
            res.ForEach(rt => db.WatchedTokens.Add(rt));
            db.SaveChanges();

            //тут фильтровать, если дохуя возвращается новых токенов
            return(resTwoEntries);
        }