/// <summary> /// OrdersReport should be consistent with TradePositionReportClosed & TradePositionReportOpened tables /// </summary> /// <param name="isSql">Use SQL database or Azure database</param> /// <param name="from">Start Date</param> /// <param name="to">End Date</param> /// <returns></returns> public async Task <IEnumerable <IOrdersReportAndOrderClosedOpenedCheckResult> > CheckOrdersReportAndOrderClosedOpened(bool isSql, DateTime?from, DateTime?to) { await _log.WriteInfoAsync("CheckOrdersReportAndOrderClosedOpened", null, $"Started Check IsSql={isSql} From [{from?.ToString("u")}] To [{to?.ToString("u")}]"); var tradingOrdersReportRepo = _repositoryManager.GetTradingOrder(isSql); var tradingPositionRepo = _repositoryManager.GetTradingPosition(isSql); // Ignore LykkeHedgingService var tradingOrders = (await tradingOrdersReportRepo.GetAsync(from, to)) .Where(x => x.TakerCounterpartyId != Constants.HedgingServiceName) .ToList(); var tradingPositions = new List <ITradingPosition>(); tradingPositions.AddRange((await tradingPositionRepo.GetClosedAsync(from, to)) .Where(x => x.TakerCounterpartyId != Constants.HedgingServiceName) .ToList()); tradingPositions.AddRange((await tradingPositionRepo.GetOpenedAsync(from, to)) .Where(x => x.TakerCounterpartyId != Constants.HedgingServiceName) .ToList()); var result = new List <OrdersReportAndOrderClosedOpenedCheckResult>(); // for each TradePosition based on TakerPositionID (Closed Positions Table) // there should exist one and only one order for OpenDate and another for CloseDate (if closed) result.AddRange(tradingOrders.CheckNumberOfOrders(tradingPositions)); // Date should exactly match result.AddRange(tradingOrders.CheckOrdersDate(tradingPositions)); // OrderType should match the CloseReason for close orders - //TODO: result.AddRange(tradingOrders.CheckOrderTypes(tradingPositions)); // AccountID should match - No AccountId in Orders.. So check may be removed //TODO: result.AddRange(tradingOrders.CheckOrderAccountID(tradingPositions)); // ClientID should match result.AddRange(tradingOrders.CheckOrderClientId(tradingPositions)); await _log.WriteInfoAsync("CheckOrdersReportAndOrderClosedOpened", null, $"Check finished with {result.Count} errors"); return(result); }