public void MarketOrderMessageTestCase()
        {
            Thread.Sleep(1000);
            bool marketOrderReceived = false;
            var  marketOrderEvent    = new ManualResetEvent(false);

            _executionMqServer.MarketOrderRequestRecieved += delegate(MarketOrder obj, string arg2)
            {
                marketOrderReceived = true;
                marketOrderEvent.Set();
                Logger.Info("Market Order Request receievd: " + obj, "MQServerTestCases", "ConsumeOrderRequestQueue");
            };

            MarketOrder marketOrder = new MarketOrder("01", "BUY", 10, "GTC", "EUR", new Security()
            {
                Symbol = "TEST"
            }, "TestCase");

            byte[] message = Encoding.UTF8.GetBytes("A00," + marketOrder.DataToPublish());

            string           corrId     = Guid.NewGuid().ToString();
            IBasicProperties replyProps = _rabbitMqOrderChannel.CreateBasicProperties();

            replyProps.CorrelationId = corrId;

            // Publish Order Reqeusts to MQ Exchange
            _rabbitMqOrderChannel.BasicPublish("orderexecution_exchange", "orderexecution.engine.orderrequest", replyProps, message);

            //IMessage<MarketOrder> message = new Message<MarketOrder>(new MarketOrder(""));
            //_advancedBus.Publish(_adminExchange, "orderexecution.engine.marketorder", true, false, message);

            marketOrderEvent.WaitOne(50000, false);
            Assert.AreEqual(true, marketOrderReceived, "Market Order Received");
        }
 /// <summary>
 /// Converts incoming Market order to Byte stream
 /// Sends to the singular order request sender function
 /// </summary>
 /// <param name="marketOrder">TardeHub MarketOrder</param>
 private void SendMarketOrderRequest(MarketOrder marketOrder)
 {
     // Convert MarketOrder to Byte Stream and pass it onto distuptor
     byte[] responseBytes = Encoding.UTF8.GetBytes(marketOrder.DataToPublish());
     //SendOrderRequests(responseBytes);
     _sendOrderRequests(responseBytes);
 }
Beispiel #3
0
        public void MarketOrderTestCase()
        {
            MarketOrder marketOrder = new MarketOrder(TradeHubConstants.OrderExecutionProvider.Simulated)
            {
                OrderID  = "A00",
                Security = new Security {
                    Symbol = "AAPL"
                },
                OrderSide = TradeHubConstants.OrderSide.SELL,
                OrderSize = 100
            };
            Execution execution = null;

            bool logonArrived     = false;
            bool logoutArrived    = false;
            bool connected        = false;
            bool newArrived       = false;
            bool executionArrived = false;

            ManualResetEvent manualLogonEvent     = new ManualResetEvent(false);
            ManualResetEvent manualLogoutEvent    = new ManualResetEvent(false);
            ManualResetEvent manualConnectedEvent = new ManualResetEvent(false);
            ManualResetEvent manualNewEvent       = new ManualResetEvent(false);
            ManualResetEvent manualExecutionEvent = new ManualResetEvent(false);

            _executionEngineClient.ServerConnected += delegate()
            {
                connected = true;
                _executionEngineClient.SendLoginRequest(new Login()
                {
                    OrderExecutionProvider = TradeHubConstants.OrderExecutionProvider.Simulated
                });
                manualConnectedEvent.Set();
            };

            _executionEngineClient.LogonArrived +=
                delegate(string obj)
            {
                logonArrived = true;

                //_executionEngineClient.SendMarketOrderRequest(marketOrder);
                RabbitMqRequestMessage entryMessage = new RabbitMqRequestMessage();
                var messageBytes = Encoding.UTF8.GetBytes(marketOrder.DataToPublish());

                // Initialize property
                entryMessage.Message = new byte[messageBytes.Length];
                // Update object values
                messageBytes.CopyTo(entryMessage.Message, 0);

                _executionEngineClient.SendOrderRequests(entryMessage);

                manualLogonEvent.Set();
            };

            _executionEngineClient.NewArrived +=
                delegate(Order obj)
            {
                newArrived = true;
                manualNewEvent.Set();
            };

            _executionEngineClient.ExecutionArrived +=
                delegate(Execution obj)
            {
                if (obj.Fill.LeavesQuantity.Equals(0))
                {
                    executionArrived = true;
                    execution        = obj;
                    _executionEngineClient.SendLogoutRequest(new Logout {
                        OrderExecutionProvider = TradeHubConstants.OrderExecutionProvider.Simulated
                    });
                    manualExecutionEvent.Set();
                }
            };

            _executionEngineClient.LogoutArrived +=
                delegate(string obj)
            {
                logoutArrived = true;
                manualLogoutEvent.Set();
            };

            _executionEngineClient.Start();

            manualConnectedEvent.WaitOne(30000, false);
            manualLogonEvent.WaitOne(30000, false);
            manualNewEvent.WaitOne(30000, false);
            manualExecutionEvent.WaitOne(30000, false);
            manualLogoutEvent.WaitOne(30000, false);

            Thread.Sleep(1000);

            Assert.AreEqual(true, logonArrived, "Logon Arrived");
            Assert.AreEqual(true, newArrived, "New Arrived");
            Assert.AreEqual(true, executionArrived, "Execution Arrived");
            Assert.AreEqual(true, execution.Fill.ExecutionSide.Equals(TradeHubConstants.OrderSide.SELL), "Execution Side");
            Assert.AreEqual(true, logoutArrived, "Logout Arrived");
        }