Exemplo n.º 1
0
        private static async Task CreateReport()
        {
            ITradesFetcher         tradesFetcher    = new TradesFetcher(ConfigurationManager.Service, ConfigurationManager.TradeType, logger);
            ITradeVolumeCalculator volumeCalculator = new TradeVolumeCalculator(logger);
            IReportCreator         reportCreator    = new ReportCreator(tradesFetcher, volumeCalculator);

            while (true)
            {
                await reportCreator.CreateTradeVolumeReportAsync(DateTime.Now, ConfigurationManager.TradeReportsPath);

                logger.LogEvent(ServiceEvent.ReportCreatedSuccessfully);

                ConfigurationManager.RefreshAppSettings();

                TimeSpan newInterval = ConfigurationManager.GenerationIntervalInMinutes;

                if (IntervalChanged(newInterval))
                {
                    initialInterval = newInterval;

                    logger.LogEvent(ServiceEvent.GenerationIntervalChanged, string.Format("Interval changed to: {0}", newInterval));
                }

                logger.LogEvent(ServiceEvent.Sleeping);

                await Task.Delay(newInterval);
            }
        }
Exemplo n.º 2
0
        private async Task CreateReport(CancellationToken token)
        {
            ITradesFetcher         tradesFetcher    = new TradesFetcher(ConfigurationManager.Service, ConfigurationManager.TradeType, this.logger);
            ITradeVolumeCalculator volumeCalculator = new TradeVolumeCalculator(this.logger);
            IReportCreator         reportCreator    = new ReportCreator(tradesFetcher, volumeCalculator);

            while (!token.IsCancellationRequested)
            {
                await reportCreator.CreateTradeVolumeReportAsync(DateTime.Now, ConfigurationManager.TradeReportsPath);

                this.logger.LogEvent(ServiceEvent.ReportCreatedSuccessfully);

                ConfigurationManager.RefreshAppSettings();

                TimeSpan newInterval = ConfigurationManager.GenerationIntervalInMinutes;

                if (this.IntervalChanged(newInterval))
                {
                    this.logger.LogEvent(ServiceEvent.GenerationIntervalChanged, string.Format("Interval changed to: {0}", newInterval));
                }

                this.logger.LogEvent(ServiceEvent.Sleeping);

                await Task.Delay(newInterval, token);
            }

            this.logger.LogEvent(ServiceEvent.ServiceStopped);
        }
Exemplo n.º 3
0
        public void TradeVolumeCalculator_Should_Correctly_Calculate_Aggregate_PowerTrade_Volumes()
        {
            Environment.SetEnvironmentVariable("Trade", "PowerTrade");

            var mockLogger       = new Mock <IServiceLogger>();
            var calculator       = new TradeVolumeCalculator(mockLogger.Object);
            var aggregateVolumes = calculator.CalculateAggregateVolumes(this.DummyTrades);
            var mappings         = PeriodTimeMappings.GetMapping();

            for (int period = 1; period <= 24; period++)
            {
                var expectedVolume = (this.DummyTrades[0].VolumePerPeriod[period] + this.DummyTrades[1].VolumePerPeriod[period]);

                Assert.AreEqual(expectedVolume, aggregateVolumes[mappings[period]]);
            }
        }