public void NewExecution_SendExecutionToServer_ExecutionReceivedByServer() { Thread.Sleep(5000); bool executionReceived = false; var executionManualResetEvent = new ManualResetEvent(false); // Create Order Object Order order = new Order(OrderExecutionProvider.Simulated) { Security = new Security() { Symbol = "GOOG" } }; // Create Fill Object Fill fill = new Fill(new Security() { Symbol = "GOOG" }, OrderExecutionProvider.Simulated, "1"); fill.ExecutionId = "1"; fill.ExecutionSide = OrderSide.BUY; fill.ExecutionSize = 40; // Create Execution Object Execution execution = new Execution(fill, order); _tradeManagerMqServer.NewExecutionReceivedEvent += delegate(Execution executionObject) { executionReceived = true; executionManualResetEvent.Set(); }; byte[] message = Encoding.UTF8.GetBytes(execution.DataToPublish()); string corrId = Guid.NewGuid().ToString(); IBasicProperties replyProps = _rabbitMqChannel.CreateBasicProperties(); replyProps.CorrelationId = corrId; // Publish Execution to MQ Exchange _rabbitMqChannel.BasicPublish("trademanager_exchange", "trademanager.execution.message", replyProps, message); executionManualResetEvent.WaitOne(10000, false); Assert.AreEqual(true, executionReceived, "Execution Received"); }
/// <summary> /// Forwards Execution messages to Client to be sent to Server /// </summary> /// <param name="execution">Contains Order Execution information</param> public void SendExecution(Execution execution) { try { // Process request only if the Client is working if (_tradeManagerClient.IsConnected()) { if (Logger.IsDebugEnabled) { Logger.Debug("Execution received: " + execution, _type.FullName, "SendExecution"); } // Send Execution to Disruptor _messagePublisher.PublishEvent((messageQueueObject, sequenceNo) => { byte[] messageBytes = Encoding.UTF8.GetBytes(execution.DataToPublish()); // Initialize Parameter messageQueueObject.Message = new byte[messageBytes.Length]; // Copy information messageBytes.CopyTo(messageQueueObject.Message, 0); // Return updated object return(messageQueueObject); }); } else { if (Logger.IsInfoEnabled) { Logger.Info("Execution not sent as Client is not connected", _type.FullName, "SendExecution"); } } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "SendExecution"); } }
public void NewExecution_SendInformationToTradeManagerServer_ExecutionReceivedByServer() { Thread.Sleep(2000); bool executionReceived = false; var executionManualResetEvent = new ManualResetEvent(false); // Create Order Object Order order = new Order(OrderExecutionProvider.Simulated) { OrderID = "1", OrderSide = OrderSide.BUY, Security = new Security() { Symbol = "GOOG" } }; // Create Fill Object Fill fill = new Fill(new Security() { Symbol = "GOOG" }, OrderExecutionProvider.Simulated, "1"); fill.ExecutionId = "1"; fill.ExecutionSide = OrderSide.BUY; fill.ExecutionSize = 40; fill.ExecutionDateTime = new DateTime(2014, 01, 22, 18, 20, 57); // Create Execution Object Execution execution = new Execution(fill, order); Execution executionReceivedObject = null; _tradeManagerMqServer.NewExecutionReceivedEvent += delegate(Execution executionObject) { executionReceivedObject = executionObject; executionReceived = true; executionManualResetEvent.Set(); }; byte[] message = Encoding.UTF8.GetBytes(execution.DataToPublish()); var requestMessage = new MessageQueueObject(); requestMessage.Message = message; // Publish Execution to MQ Exchange _tradeManagerClient.SendExecution(requestMessage); executionManualResetEvent.WaitOne(10000, false); Assert.AreEqual(true, executionReceived, "Execution Received"); Assert.AreEqual(execution.Order.OrderExecutionProvider, executionReceivedObject.Order.OrderExecutionProvider, "Order Execution Provider"); Assert.AreEqual(execution.Order.OrderID, executionReceivedObject.Order.OrderID, "Order ID"); Assert.AreEqual(execution.Order.Security.Symbol, executionReceivedObject.Order.Security.Symbol, "Order Symbol"); Assert.AreEqual(execution.Order.OrderSide, executionReceivedObject.Order.OrderSide, "Order Side"); Assert.AreEqual(execution.Fill.Security.Symbol, executionReceivedObject.Fill.Security.Symbol, "Fill Symbol"); Assert.AreEqual(execution.Fill.OrderExecutionProvider, executionReceivedObject.Fill.OrderExecutionProvider, "Fill Execution Provider"); Assert.AreEqual(execution.Fill.ExecutionId, executionReceivedObject.Fill.ExecutionId, "Execution ID"); Assert.AreEqual(execution.Fill.OrderId, executionReceivedObject.Fill.OrderId, "Order ID in Fill"); Assert.AreEqual(execution.Fill.ExecutionSide, executionReceivedObject.Fill.ExecutionSide, "Execution Side"); Assert.AreEqual(execution.Fill.ExecutionSize, executionReceivedObject.Fill.ExecutionSize, "Execution Size"); }
public void MultipleExecutions_SendInformationToTradeManagerServer_ExecutionReceivedByServerTradeCompleted() { Thread.Sleep(2000); int executionCount = 0; bool executionReceived = false; var executionManualResetEvent = new ManualResetEvent(false); Execution executionOne = null; Execution executionTwo = null; MessageQueueObject requestMessage; { // Create Order Object Order order = new Order(OrderExecutionProvider.Simulated) { OrderID = "1", OrderSide = OrderSide.BUY, Security = new Security() { Symbol = "GOOG" } }; // Create Fill Object Fill fill = new Fill(new Security() { Symbol = "GOOG" }, OrderExecutionProvider.Simulated, "1"); fill.ExecutionId = "1"; fill.ExecutionSide = OrderSide.BUY; fill.ExecutionSize = 40; fill.ExecutionDateTime = new DateTime(2014, 01, 22, 18, 20, 57); // Create Execution Object executionOne = new Execution(fill, order); byte[] message = Encoding.UTF8.GetBytes(executionOne.DataToPublish()); requestMessage = new MessageQueueObject(); requestMessage.Message = message; } Execution executionReceivedObjectOne = null; Execution executionReceivedObjectTwo = null; _tradeManagerMqServer.NewExecutionReceivedEvent += delegate(Execution executionObject) { executionCount++; if (executionCount == 1) { executionReceivedObjectOne = executionObject; // Create Order Object Order order = new Order(OrderExecutionProvider.Simulated) { OrderID = "2", OrderSide = OrderSide.BUY, Security = new Security() { Symbol = "GOOG" } }; // Create Fill Object Fill fill = new Fill(new Security() { Symbol = "GOOG" }, OrderExecutionProvider.Simulated, "2"); fill.ExecutionId = "2"; fill.ExecutionSide = OrderSide.SELL; fill.ExecutionSize = 40; fill.ExecutionDateTime = new DateTime(2014, 01, 22, 18, 20, 59); // Create Execution Object executionTwo = new Execution(fill, order); byte[] message = Encoding.UTF8.GetBytes(executionTwo.DataToPublish()); requestMessage = new MessageQueueObject(); requestMessage.Message = message; // Publish Execution to MQ Exchange _tradeManagerClient.SendExecution(requestMessage); } if (executionCount == 2) { executionReceived = true; executionReceivedObjectTwo = executionObject; //Give Repo time to save data Thread.Sleep(2000); executionManualResetEvent.Set(); } }; // Publish Execution to MQ Exchange _tradeManagerClient.SendExecution(requestMessage); executionManualResetEvent.WaitOne(10000, false); Assert.AreEqual(true, executionReceived, "Execution Received"); Assert.AreEqual(executionOne.Order.OrderExecutionProvider, executionReceivedObjectOne.Order.OrderExecutionProvider, "Order Execution Provider - ONE"); Assert.AreEqual(executionOne.Order.OrderID, executionReceivedObjectOne.Order.OrderID, "Order ID - ONE"); Assert.AreEqual(executionOne.Order.Security.Symbol, executionReceivedObjectOne.Order.Security.Symbol, "Order Symbol - ONE"); Assert.AreEqual(executionOne.Order.OrderSide, executionReceivedObjectOne.Order.OrderSide, "Order Side - ONE"); Assert.AreEqual(executionOne.Fill.Security.Symbol, executionReceivedObjectOne.Fill.Security.Symbol, "Fill Symbol - ONE"); Assert.AreEqual(executionOne.Fill.OrderExecutionProvider, executionReceivedObjectOne.Fill.OrderExecutionProvider, "Fill Execution Provider - ONE"); Assert.AreEqual(executionOne.Fill.ExecutionId, executionReceivedObjectOne.Fill.ExecutionId, "Execution ID - ONE"); Assert.AreEqual(executionOne.Fill.OrderId, executionReceivedObjectOne.Fill.OrderId, "Order ID in Fill - ONE"); Assert.AreEqual(executionOne.Fill.ExecutionSide, executionReceivedObjectOne.Fill.ExecutionSide, "Execution Side - ONE"); Assert.AreEqual(executionOne.Fill.ExecutionSize, executionReceivedObjectOne.Fill.ExecutionSize, "Execution Size - ONE"); Assert.AreEqual(executionTwo.Order.OrderExecutionProvider, executionReceivedObjectTwo.Order.OrderExecutionProvider, "Order Execution Provider - TWO"); Assert.AreEqual(executionTwo.Order.OrderID, executionReceivedObjectTwo.Order.OrderID, "Order ID - TWO"); Assert.AreEqual(executionTwo.Order.Security.Symbol, executionReceivedObjectTwo.Order.Security.Symbol, "Order Symbol - TWO"); Assert.AreEqual(executionTwo.Order.OrderSide, executionReceivedObjectTwo.Order.OrderSide, "Order Side - TWO"); Assert.AreEqual(executionTwo.Fill.Security.Symbol, executionReceivedObjectTwo.Fill.Security.Symbol, "Fill Symbol - TWO"); Assert.AreEqual(executionTwo.Fill.OrderExecutionProvider, executionReceivedObjectTwo.Fill.OrderExecutionProvider, "Fill Execution Provider - TWO"); Assert.AreEqual(executionTwo.Fill.ExecutionId, executionReceivedObjectTwo.Fill.ExecutionId, "Execution ID - TWO"); Assert.AreEqual(executionTwo.Fill.OrderId, executionReceivedObjectTwo.Fill.OrderId, "Order ID in Fill - TWO"); Assert.AreEqual(executionTwo.Fill.ExecutionSide, executionReceivedObjectTwo.Fill.ExecutionSide, "Execution Side - TWO"); Assert.AreEqual(executionTwo.Fill.ExecutionSize, executionReceivedObjectTwo.Fill.ExecutionSize, "Execution Size - TWO"); }