Exemplo n.º 1
0
        public ServerApplication(Action <string> messageCallback)
        {
            _messageCallback = messageCallback;

            // Were this a production server I'd recommend getting all these types from a
            // type provider layer (MEF, Castle, etc)
            var sessionRepository = new SessionRepository();
            var fixSessionFacade  = new StandardFixFacade(messageCallback);

            _sessionMediator = new SessionMediator(sessionRepository, fixSessionFacade);

            _inputQueue  = new CommandQueue();
            _outputQueue = new CommandQueue();

            var asyncProcessing = new TaskBasedCommandProcessingStrategy();
            var syncProcessing  = new SynchronousCommandProcessingStrategy();

            _inputCommandProcessor  = new CommandProcessor(asyncProcessing, _inputQueue);
            _outputCommandProcessor = new CommandProcessor(syncProcessing, _outputQueue);

            var orderMatcher    = new StandardOrderMatcher();
            var orderRepository = new StandardOrderRepository(orderMatcher);

            _orderMediator = new OrderMediator(orderRepository, OnOrderMatched);

            _commandFactory = new CommandFactory(_inputQueue,
                                                 _outputQueue,
                                                 _orderMediator,
                                                 _sessionMediator);

            var messageHandlerCommandFactory = new MessageHandlerCommandFactory(_sessionMediator,
                                                                                _commandFactory);

            var fix42MessageGenerator = new Fix42MessageGenerator();

            _fix42MessageHandler = new Fix42MessageHandler(messageHandlerCommandFactory,
                                                           fix42MessageGenerator,
                                                           fixSessionFacade,
                                                           GenExecID);

            var fix44MessageGenerator = new Fix44MessageGenerator();

            _fix44MessageHandler = new Fix44MessageHandler(messageHandlerCommandFactory,
                                                           fix44MessageGenerator,
                                                           fixSessionFacade,
                                                           GenExecID);
        }
Exemplo n.º 2
0
        public ServerApplication(Action<string> messageCallback)
        {
            _messageCallback = messageCallback;

            // Were this a production server I'd recommend getting all these types from a
            // type provider layer (MEF, Castle, etc)
            var sessionRepository = new SessionRepository();
            var fixSessionFacade = new StandardFixFacade(messageCallback);
            _sessionMediator = new SessionMediator(sessionRepository, fixSessionFacade);

            _inputQueue = new CommandQueue();
            _outputQueue = new CommandQueue();

            var asyncProcessing = new TaskBasedCommandProcessingStrategy();
            var syncProcessing = new SynchronousCommandProcessingStrategy();
            _inputCommandProcessor = new CommandProcessor(asyncProcessing, _inputQueue);
            _outputCommandProcessor = new CommandProcessor(syncProcessing, _outputQueue);

            var orderMatcher = new StandardOrderMatcher();
            var orderRepository = new StandardOrderRepository(orderMatcher);
            _orderMediator = new OrderMediator(orderRepository, OnOrderMatched);

            _commandFactory = new CommandFactory(_inputQueue,
                                                 _outputQueue,
                                                 _orderMediator,
                                                 _sessionMediator);

            var messageHandlerCommandFactory = new MessageHandlerCommandFactory(_sessionMediator,
                                                                                _commandFactory);

            var fix42MessageGenerator = new Fix42MessageGenerator();
            _fix42MessageHandler = new Fix42MessageHandler(messageHandlerCommandFactory,
                                                           fix42MessageGenerator,
                                                           fixSessionFacade,
                                                           GenExecID);

            var fix44MessageGenerator = new Fix44MessageGenerator();
            _fix44MessageHandler = new Fix44MessageHandler(messageHandlerCommandFactory,
                                                           fix44MessageGenerator,
                                                           fixSessionFacade,
                                                           GenExecID);
        }
Exemplo n.º 3
0
        public void CancellingAnOrderWhenYouAreTheOwningSessionSucceeds()
        {
            var mockRepository = new Mock<IOrderRepository>();
            var o = DefaultOrder(1);

            mockRepository.Setup(r => r.AddOrder(o.ID,
                                                 o.Contract,
                                                 o.OrderType,
                                                 o.MarketSide,
                                                 o.Price,
                                                 o.Quantity,
                                                 o.ClOrdID,
                                                 o.Account))
                          .Returns(o);

            mockRepository.Setup(r => r.DeleteOrder(o.ID)).Returns(o);

            Action<OrderMatch, FixSessionID> emptyMatchCallback = (m, s) => { };
            var mediator = new OrderMediator(mockRepository.Object, emptyMatchCallback);
            var fakeSessionId = new FixSessionID();

            var addedOrder = mediator.AddOrder(fakeSessionId,
                                               o.OrderType,
                                               o.Contract.Symbol,
                                               o.MarketSide,
                                               o.ClOrdID,
                                               o.Account,
                                               o.Quantity,
                                               o.Price);

            Assert.AreEqual(o.ID, addedOrder.ID);
            Assert.AreEqual(o.ClOrdID, addedOrder.ClOrdID);

            var cancelledOrder = mediator.CancelOrder(addedOrder.ID, fakeSessionId);
            Assert.IsNotNull(cancelledOrder, "Cancelled order should not be null");

            mockRepository.Verify(r => r.DeleteOrder(o.ID), Times.Once());

            Assert.AreEqual(o.ID, cancelledOrder.ID);
            Assert.AreEqual(o.ClOrdID, cancelledOrder.ClOrdID);
        }
Exemplo n.º 4
0
        public void CancellingAnOrderWhenYouAreNotTheOwningSessionFails()
        {
            var mockRepository = new Mock<IOrderRepository>();
            var o = DefaultOrder(1);

            mockRepository.Setup(r => r.AddOrder(o.ID,
                                                 o.Contract,
                                                 o.OrderType,
                                                 o.MarketSide,
                                                 o.Price,
                                                 o.Quantity,
                                                 o.ClOrdID,
                                                 o.Account))
                          .Returns(o);

            Action<OrderMatch, FixSessionID> emptyMatchCallback = (m, s) => { };
            var mediator = new OrderMediator(mockRepository.Object, emptyMatchCallback);

            var fakeSessionId1 = new FixSessionID();
            var fakeSessionId2 = new FixSessionID();
            Assert.AreNotEqual(fakeSessionId1, fakeSessionId2);

            var addedOrder = mediator.AddOrder(fakeSessionId1,
                                               o.OrderType,
                                               o.Contract.Symbol,
                                               o.MarketSide,
                                               o.ClOrdID,
                                               o.Account,
                                               o.Quantity,
                                               o.Price);

            Assert.Throws<FixATServerException>(
                () => mediator.CancelOrder(addedOrder.ID, fakeSessionId2));

            mockRepository.Verify(r => r.DeleteOrder(o.ID), Times.Never());
        }