Exemplo n.º 1
0
        private async Task SyncPerformanceAsync(
            IGraphClient graphClient,
            IFundPerformanceRepository repository,
            IStakeSettings stake,
            DateTimeOffset startDate,
            DateTimeOffset endDate,
            CancellationToken cancellationToken)
        {
            var start = new DateTimeOffset(startDate.Date, TimeSpan.Zero);

            while (!cancellationToken.IsCancellationRequested)
            {
                if (start >= DateTimeOffset.UtcNow)
                {
                    break;
                }

                var end = start.AddDays(MaxDays).Round();

                Console.WriteLine($"[{stake.ContractAddress}] Processing Batch: {start} -> {end}");

                var uniswapPrices = await graphClient
                                    .ListUniswapTokenPerformanceAsync(stake.ContractAddress, start, end)
                                    .ToListAsync(cancellationToken);

                foreach (var priceData in uniswapPrices)
                {
                    var perf = new DataFundPerformance()
                    {
                        Address   = stake.ContractAddress,
                        Date      = priceData.Date,
                        Nav       = priceData.Price,
                        Price     = priceData.Price,
                        MarketCap = priceData.MarketCap,
                        Volume    = priceData.Volume
                    };

                    await repository.UploadItemsAsync(perf);
                }

                Console.WriteLine($"[{stake.ContractAddress}] Finished Batch: {start} -> {end}");

                if (end >= endDate)
                {
                    break;
                }
                else
                {
                    start = end;
                }
            }
        }