Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public async Task ApplyAsync()
        {
            IReadOnlyCollection <SummaryReport> summaryReports = await _summaryReportRepository.GetAllAsync();

            _log.InfoWithDetails("Read summary reports", new
            {
                summaryReports.Count
            });

            await _summaryReportRepository.DeleteAsync();

            foreach (SummaryReport summaryReport in summaryReports)
            {
                summaryReport.TradeAssetPairId = summaryReport.AssetPairId;

                await _summaryReportRepository.InsertAsync(summaryReport);

                _log.InfoWithDetails("Updated summary report.", new
                {
                    SummaryReport = summaryReport
                });
            }
        }