public async Task CheckConsistency()
        {
            var currentCheck = DateTime.UtcNow;
            await _log.WriteInfoAsync("CheckConsistency", null, $"New Consistency Check. Interval:[{LastCheck?.ToString("u")}]->[{currentCheck:u}]");

            var totalErrors = 0;

            try
            {
                var balanceAndTransactionAmount = (await _consistencyService.CheckBalanceAndTransactionAmount(_monitorSettings.CheckSql, LastCheck, currentCheck))
                                                  .ToList();
                totalErrors += balanceAndTransactionAmount.Count;
                await _balanceAndTransactionAmountRepository.AddAsync(balanceAndTransactionAmount, currentCheck);
            }
            catch (Exception ex01) { await _log.WriteErrorAsync(nameof(CheckConsistency), null, ex01); }

            try
            {
                var balanceAndOrderClosed = (await _consistencyService.CheckBalanceAndOrderClosed(_monitorSettings.CheckSql, LastCheck, currentCheck))
                                            .ToList();
                totalErrors += balanceAndOrderClosed.Count;
                await _balanceAndOrderClosedRepository.AddAsync(balanceAndOrderClosed, currentCheck);
            }
            catch (Exception ex01) { await _log.WriteErrorAsync(nameof(CheckConsistency), null, ex01); }

            try
            {
                var ordersReportAndOrderClosedOpened = (await _consistencyService.CheckOrdersReportAndOrderClosedOpened(_monitorSettings.CheckSql, LastCheck, currentCheck))
                                                       .ToList();
                totalErrors += ordersReportAndOrderClosedOpened.Count;
                await _ordersReportAndOrderClosedOpenedRepository.AddAsync(ordersReportAndOrderClosedOpened, currentCheck);
            }
            catch (Exception ex01) { await _log.WriteErrorAsync(nameof(CheckConsistency), null, ex01); }

            try
            {
                var candlesPriceConsistency = (await _consistencyService.CheckCandlesPriceConsistency(_monitorSettings.CheckSql, LastCheck, currentCheck))
                                              .ToList();
                totalErrors += candlesPriceConsistency.Count;
                await _priceCandlesConsistencyRepository.AddAsync(candlesPriceConsistency, currentCheck);
            }
            catch (Exception ex01) { await _log.WriteErrorAsync(nameof(CheckConsistency), null, ex01); }
            try
            {
                var marginEventsAccountStatus = (await _consistencyService.CheckMarginEventsAccountStatus(_monitorSettings.CheckSql, LastCheck, currentCheck))
                                                .ToList();
                totalErrors += marginEventsAccountStatus.Count;
                await _marginEventsAccountStatusRepository.AddAsync(marginEventsAccountStatus, currentCheck);
            }
            catch (Exception ex01) { await _log.WriteErrorAsync(nameof(CheckConsistency), null, ex01); }

            try
            {
                var hedgingServiceVolume = (await _consistencyService.CheckHedgingService(_monitorSettings.CheckSql, LastCheck, currentCheck))
                                           .ToList();
                totalErrors += hedgingServiceVolume.Count;
                await _hedgingServiceRepository.AddAsync(hedgingServiceVolume, currentCheck);
            }
            catch (Exception ex01) { await _log.WriteErrorAsync(nameof(CheckConsistency), null, ex01); }


            await _checkResultRepository.AddAsync(new CheckResult
            {
                Date     = currentCheck,
                DateFrom = LastCheck ?? new DateTime(2000, 01, 01),
                DateTo   = currentCheck,
                Comments = $"Check finished with {totalErrors} errors"
            });

            LastCheck = currentCheck;


            if (totalErrors == 0)
            {
                await _log.WriteInfoAsync("CheckConsistency", null, "Consistency check finished without errors");
            }
            else
            {
                WriteMessage($"Consistency check finished with {totalErrors} errors. Check Date: {currentCheck:u}", EventTypeEnum.ConsistencyError);
            }
        }
Exemple #2
0
 public async Task SaveAsync(CheckResult checkResult)
 => await _checkResultRepository.AddAsync(checkResult);