private async Task <IReadOnlyCollection <PositionSummaryReport> > ConvertToReportsAsync(
            IEnumerable <SummaryReport> summaryReports)
        {
            IReadOnlyCollection <Position> openPositions = await _openPositionRepository.GetAllAsync();

            IReadOnlyCollection <Instrument> instruments = await _instrumentService.GetAllAsync();

            var items = new List <PositionSummaryReport>();

            foreach (SummaryReport summaryReport in summaryReports)
            {
                Instrument instrument = instruments.FirstOrDefault(o => o.AssetPairId == summaryReport.AssetPairId);

                decimal openVolume = openPositions
                                     .Where(o => o.AssetPairId == summaryReport.AssetPairId &&
                                            o.TradeAssetPairId == summaryReport.TradeAssetPairId)
                                     .Sum(o => Math.Abs(o.Volume));

                decimal?pnlUsd = await _crossRateInstrumentService.ConvertPriceAsync(summaryReport.AssetPairId,
                                                                                     summaryReport.PnL);

                items.Add(new PositionSummaryReport
                {
                    AssetPairId          = summaryReport.AssetPairId,
                    TradeAssetPairId     = summaryReport.TradeAssetPairId,
                    OpenPositionsCount   = summaryReport.OpenPositionsCount,
                    ClosedPositionsCount = summaryReport.ClosedPositionsCount,
                    PnL                       = summaryReport.PnL,
                    PnLUsd                    = pnlUsd,
                    BaseAssetVolume           = summaryReport.BaseAssetVolume,
                    QuoteAssetVolume          = summaryReport.QuoteAssetVolume,
                    TotalSellBaseAssetVolume  = summaryReport.TotalSellBaseAssetVolume,
                    TotalBuyBaseAssetVolume   = summaryReport.TotalBuyBaseAssetVolume,
                    TotalSellQuoteAssetVolume = summaryReport.TotalSellQuoteAssetVolume,
                    TotalBuyQuoteAssetVolume  = summaryReport.TotalBuyQuoteAssetVolume,
                    SellTradesCount           = summaryReport.SellTradesCount,
                    BuyTradesCount            = summaryReport.BuyTradesCount,
                    OpenVolume                = openVolume,
                    OpenVolumeLimit           = openVolume / instrument?.InventoryThreshold
                });
            }

            return(items);
        }
 public Task <IReadOnlyCollection <Position> > GetOpenAllAsync()
 {
     return(_openPositionRepository.GetAllAsync());
 }