コード例 #1
0
        public async Task RecalculateAllAvgPrices(RecalculateAllRequest request)
        {
            var semaphore = SemaphoreManager.GetOrCreate(request.WalletId, request.AssetId);
            await semaphore.WaitAsync();

            try
            {
                _logger.LogInformation("Recalculating average open prices for wallet {WalletId} and asset {AssetId}", request.WalletId, request.AssetId);
                await using var ctx = DatabaseContext.Create(_dbContextOptionsBuilder);
                var entities = ctx.OperationHistory.Where(t => t.WalletId == request.WalletId && t.AssetId == request.AssetId && t.Status == OperationStatuses.Completed);
                var snapshot = await _snapshotCacheManager.GetSnapshot(request.WalletId, request.AssetId);

                if (snapshot != null)
                {
                    entities = entities.Where(t => t.TimeStamp >= snapshot.OpenTimestamp);
                }

                if (entities.Any())
                {
                    await RecalculatePrices(request.WalletId, request.AssetId, entities.Select(t => (OperationUpdate)t).ToList(), null);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "When recalculating average open prices for wallet {WalletId} and asset {AssetId}", request.WalletId, request.AssetId);
                throw;
            }
            finally
            {
                semaphore.Release();
            }
        }
コード例 #2
0
 public async Task <SnapshotEntity> GetSnapshot(GetSnapshotRequest request) => await _cacheManager.GetSnapshot(request.WalletId, request.AssetId);