Пример #1
0
        public async Task RegisterTradeAsync(Trade trade)
        {
            IReadOnlyCollection <SummaryReport> summaryReports = await GetAllAsync();

            SummaryReport summaryReport = summaryReports.SingleOrDefault(o => o.AssetPairId == trade.AssetPairId);

            bool isNew = false;

            if (summaryReport == null)
            {
                summaryReport = new SummaryReport {
                    AssetPairId = trade.AssetPairId
                };
                isNew = true;
            }

            summaryReport.ApplyTrade(trade);

            if (isNew)
            {
                await _summaryReportRepository.InsertAsync(summaryReport);
            }
            else
            {
                await _summaryReportRepository.UpdateAsync(summaryReport);
            }

            _cache.Set(summaryReport);
        }
        public async Task RegisterOpenPositionAsync(Position position,
                                                    IReadOnlyCollection <InternalTrade> internalTrades)
        {
            IReadOnlyCollection <SummaryReport> summaryReports = await GetAllAsync();

            SummaryReport summaryReport = summaryReports.SingleOrDefault(o =>
                                                                         o.AssetPairId == position.AssetPairId && o.TradeAssetPairId == position.TradeAssetPairId);

            bool isNew = false;

            if (summaryReport == null)
            {
                summaryReport = new SummaryReport
                {
                    AssetPairId      = position.AssetPairId,
                    TradeAssetPairId = position.TradeAssetPairId
                };
                isNew = true;
            }

            foreach (InternalTrade internalTrade in internalTrades)
            {
                summaryReport.ApplyTrade(internalTrade);
            }

            summaryReport.ApplyOpenPosition();

            if (isNew)
            {
                await _summaryReportRepository.InsertAsync(summaryReport);
            }
            else
            {
                await _summaryReportRepository.UpdateAsync(summaryReport);
            }

            _cache.Set(summaryReport);
        }