public async Task one_failing_handler_should_not_abort_others()
        {
            var       container      = Substitute.For <IContainer>();
            var       scope          = Substitute.For <IContainerScope>();
            var       evt            = new IocEventBusTests.TestEvent();
            var       successHandler = new IocEventBusTests.SuccessfulHandler();
            Exception actual         = null;

            container.CreateScope().Returns(scope);
            scope.ResolveAll <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >()
            .Returns(new IApplicationEventSubscriber <IocEventBusTests.TestEvent>[]
            {
                new IocEventBusTests.FailingHandler(),
                successHandler
            });
            var inner = new IocEventBus(container);

            var sut = new QueuedEventBus(inner, 1);

            try
            {
                await sut.PublishAsync(evt);

                await sut.ExecuteJobAsync();
            }
            catch (Exception exception)
            {
                actual = exception;
            }


            successHandler.IsCalled.Should().BeTrue();
            actual.Should().BeOfType <AggregateException>();
        }
        public async Task event_should_report_Failure_if_one_handler_throws_an_exception()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();
            var actual    = false;

            container.CreateScope().Returns(scope);
            scope.ResolveAll <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >()
            .Returns(new[]
            {
                Substitute.For <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >(),
                new IocEventBusTests.FailingHandler(),
            });
            var inner = new IocEventBus(container);

            var sut = new QueuedEventBus(inner, 1);

            sut.EventPublished += (sender, args) => actual = args.Successful;
            try
            {
                sut.PublishAsync(new IocEventBusTests.TestEvent());
            }
            catch { }

            actual.Should().BeFalse();
        }
Beispiel #3
0
        private static void DoMainBackTest()
        {
            var eventBus         = new QueuedEventBus();
            var dataSource       = CsvDataSource.CreateFromFiles("Data\\Min1", new[] { Symbols.Sber, Symbols.Vtbr });
            var marketData       = new ComposedMarketData(dataSource.Bars);
            var bars             = new HistoricDataHandler(eventBus, marketData);
            var strategy         = new BuyAndHoldStrategy(eventBus, bars);
            var executionHandler = new SimulatedExecutionHandler(eventBus, bars);
            var portfolio        = new NaivePortfolio(eventBus, bars, 10000m);
            var backTest         = new BackTest(eventBus, bars, strategy, portfolio, executionHandler);

            backTest.SimulateTrading();
        }
        public void CanGetLastBarFromCsvMarketData()
        {
            var dataSource = CsvDataSource.CreateFormStrings(Mother.GenericCsvData);
            var marketData = new ComposedMarketData(dataSource.Bars);
            var eventBus   = new QueuedEventBus();

            var handler = new HistoricDataHandler(eventBus, marketData);

            Console.WriteLine("Total rows = {0}", marketData.RowKeys.Count);

            var i = 0;

            while (handler.ContinueBacktest)
            {
                handler.Update();
                i++;

                var sber = handler.GetLast(Symbols.Sber);
                var vtbr = handler.GetLast(Symbols.Vtbr);

                Console.WriteLine($"Iteration {i}");

                if (sber == null)
                {
                    Console.WriteLine($"{handler.CurrentTime} => SBER is NULL");
                }
                else
                {
                    sber.Print();
                }
                if (vtbr == null)
                {
                    Console.WriteLine($"{handler.CurrentTime} => VTBR is NULL");
                }
                else
                {
                    vtbr.Print();
                }
                Console.WriteLine("------------------");
            }
        }
        public async Task works_with_multiple_handlers()
        {
            var container   = Substitute.For <IContainer>();
            var scope       = Substitute.For <IContainerScope>();
            var subscriber1 = Substitute.For <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >();
            var subscriber2 = Substitute.For <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >();
            var evt         = new IocEventBusTests.TestEvent();

            container.CreateScope().Returns(scope);
            scope.ResolveAll <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >()
            .Returns(new[] { subscriber1, subscriber2 });
            var innerBus = new IocEventBus(container);

            var sut = new QueuedEventBus(innerBus, 1);
            await sut.PublishAsync(evt);

            await sut.ExecuteJobAsync();

            subscriber1.Received().HandleAsync(evt);
            subscriber2.Received().HandleAsync(evt);
        }
        public async Task should_trigger_event_upon_successful_completion()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();
            var actual    = false;

            container.CreateScope().Returns(scope);
            scope.ResolveAll <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >()
            .Returns(new[]
            {
                Substitute.For <IApplicationEventSubscriber <IocEventBusTests.TestEvent> >(),
            });
            var inner = new IocEventBus(container);

            var sut = new QueuedEventBus(inner, 1);

            sut.EventPublished += (sender, args) => actual = true;
            await sut.PublishAsync(new IocEventBusTests.TestEvent());

            await sut.ExecuteJobAsync();

            actual.Should().BeTrue();
        }