protected override async Task DoWork() { DbContext.DetachEverything(); var tokenList = await DbContext.Tokens.Where(x => x.IsEnabled && !x.IsDeleted).ToListAsync(); var thisDayStart = DayStartOf(DateTime.Now); foreach (var token in tokenList) { var lastStat = await DbContext.TokenStatistics.LastOrDefaultAsync(x => x.TokenId == token.Id); var add = lastStat == null || lastStat.Date != thisDayStart; var price = await TronObserver.GetTokenPrice(token.FotronContractAddress); var buyCount = await TronObserver.GetBuyCount(token.FotronContractAddress); var sellCount = await TronObserver.GetSellCount(token.FotronContractAddress); var bonusPerShare = await TronObserver.GetBonusPerShare(token.FotronContractAddress); var volumeEth = await TronObserver.GetVolumeEth(token.FotronContractAddress); var volumeToken = await TronObserver.GetVolumeToken(token.FotronContractAddress); var blockNum = await TronObserver.GetLatestBlockNumber(); if (add) { var tokenStat = new TokenStatistics { Date = thisDayStart, PriceEth = price, BuyCount = buyCount, SellCount = sellCount, ShareReward = bonusPerShare, VolumeEth = volumeEth, VolumeToken = volumeToken, BlockNum = blockNum, TokenId = token.Id }; await DbContext.TokenStatistics.AddAsync(tokenStat); } else { lastStat.PriceEth = price; lastStat.BuyCount = buyCount; lastStat.SellCount = sellCount; lastStat.ShareReward = bonusPerShare; lastStat.VolumeEth = volumeEth; lastStat.VolumeToken = volumeToken; lastStat.BlockNum = blockNum; } } await DbContext.SaveChangesAsync(); }
protected override async Task DoWork() { DbContext.DetachEverything(); var tokenList = await DbContext.Tokens.Where(x => x.IsEnabled && !x.IsDeleted).ToListAsync(); foreach (var token in tokenList) { token.CurrentPriceEth = await TronObserver.GetTokenPrice(token.FotronContractAddress); token.TimeUpdated = DateTime.Now; } await DbContext.SaveChangesAsync(); }