/// <summary> /// MarginEvents account status consistency with balance transactions /// </summary> /// <param name="isSql"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public async Task <IEnumerable <IMarginEventsAccountStatusCheckResult> > CheckMarginEventsAccountStatus(bool isSql, DateTime?from, DateTime?to) { await _log.WriteInfoAsync("CheckMarginEventsAccountStatus", null, $"Started Check IsSql={isSql} From [{from?.ToString("u")}] To [{to?.ToString("u")}]"); var marginEventsRepo = _repositoryManager.GetAccountMarginEventReport(isSql); var accountTransactionRepo = _repositoryManager.GetAccountTransactionsReport(isSql); var tradingPositionRepo = _repositoryManager.GetTradingPosition(isSql); var marginEvents = (await marginEventsRepo.GetAsync(from, to)) .ToList(); var result = new List <MarginEventsAccountStatusCheckResult>(); // balance equals the account balance calculated for the corresponding date base on transactions like in Check 1) var accountTransaction = await accountTransactionRepo.GetAsync(from, to); result.AddRange(marginEvents.CheckBalanceTransactions(accountTransaction)); // Number of position open should correspond to positions open at that time according to OpenDate and CloseDate fields of Closed or Open Trades var tradingPositions = (await tradingPositionRepo.GetOpenedAsync(from, to)).ToList(); tradingPositions.AddRange((await tradingPositionRepo.GetClosedAsync(from, to))); result.AddRange(marginEvents.CheckOpenPositions(tradingPositions)); await _log.WriteInfoAsync("CheckMarginEventsAccountStatus", null, $"Check finished with {result.Count} errors"); return(result); }