示例#1
0
        public void Execute()
        {
            try
            {
                var order = _orderMediator.AddOrder(_sessionID,
                                                    _orderData.OrderType,
                                                    _orderData.Symbol,
                                                    _orderData.MarketSide,
                                                    _orderData.ClOrdID,
                                                    _orderData.Account,
                                                    _orderData.Quantity,
                                                    _orderData.Price);

                var successCmd = _commandFactory.CreateSendAcceptNewOrder(_sessionID, order);
                _commandFactory.OutgoingQueue.Enqueue(successCmd);

                // Kick off matching for the contract given we have a new order
                var matchOrders = _commandFactory.CreateMatchOrders(_orderData.Symbol);
                _commandFactory.IncomingQueue.Enqueue(matchOrders);
            }
            catch (FixATServerException e)
            {
                var rejectMessage = "Unable to add order: " + e.Message;
                var rejectCmd     = _commandFactory.CreateSendRejectNewOrder(_fixMessageGenerator,
                                                                             _sessionID,
                                                                             _orderData,
                                                                             _execID,
                                                                             rejectMessage,
                                                                             e.RejectionCode);
                _commandFactory.OutgoingQueue.Enqueue(rejectCmd);
            }
        }
示例#2
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);
        }
示例#3
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());
        }