/// <summary> /// Unhooks Limit Order events (New/Cancellation/Execution/Rejection) /// </summary> /// <param name="limitOrderProvider">TradeHub Limit Order Provider object</param> private void UnregisterLimitOrderEvents(ILimitOrderProvider limitOrderProvider) { limitOrderProvider.NewArrived -= OnNewArrived; limitOrderProvider.CancellationArrived -= OnCancellationArrived; limitOrderProvider.ExecutionArrived -= OnExecutionArrived; limitOrderProvider.RejectionArrived -= OnOrderRejectionArrived; }
/// <summary> /// Hooks Limit Order events (New/Cancellation/Execution/Rejection) /// </summary> /// <param name="limitOrderProvider">TradeHub Limit Order Provider object</param> private void RegisterLimitOrderEvents(ILimitOrderProvider limitOrderProvider) { // Unhook to avoid multiple event registration UnregisterLimitOrderEvents(limitOrderProvider); limitOrderProvider.NewArrived += OnNewArrived; limitOrderProvider.CancellationArrived += OnCancellationArrived; limitOrderProvider.ExecutionArrived += OnExecutionArrived; limitOrderProvider.RejectionArrived += OnOrderRejectionArrived; }
/// <summary> /// Handles New Limit Order Request messages from Applications /// </summary> /// <param name="limitOrder">TradeHub Limit Order</param> /// <param name="appId">Unique Application ID</param> public void LimitOrderRequestReceived(LimitOrder limitOrder, string appId) { try { if (Logger.IsDebugEnabled) { Logger.Debug( "New Limit Order request received from: " + appId + limitOrder.OrderID + " for: " + limitOrder.OrderExecutionProvider, _type.FullName, "LimitOrderRequestReceived"); } IOrderExecutionProvider orderExecutionProvider; if (_providersMap.TryGetValue(limitOrder.OrderExecutionProvider, out orderExecutionProvider)) { ILimitOrderProvider limitOrderProvider = orderExecutionProvider as ILimitOrderProvider; if (limitOrderProvider != null) { // Modify Order ID by appending Application ID in the front limitOrder.OrderID = appId + "|" + limitOrder.OrderID; // Register Market Order Events RegisterLimitOrderEvents(limitOrderProvider); // Send Limit Order to Execution Provider limitOrderProvider.SendLimitOrder(limitOrder); } else { if (Logger.IsInfoEnabled) { Logger.Info("Requested provider doesn't support Limit Orders", _type.FullName, "LimitOrderRequestReceived"); } } } else { if (Logger.IsInfoEnabled) { Logger.Info( "Order Execution Provider module not available for: " + limitOrder.OrderExecutionProvider, _type.FullName, "LimitOrderRequestReceived"); } } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "LimitOrderRequestReceived"); } }
/// <summary> /// Handles New Cancel Order Request messages from Applications /// </summary> /// <param name="order">TradeHub Order</param> /// <param name="appId">Unique Application ID</param> public void CancelOrderRequestReceived(Order order, string appId) { try { if (Logger.IsDebugEnabled) { Logger.Debug( "New Cancel Order request received from: " + appId + order.OrderID + " for: " + order.OrderExecutionProvider, _type.FullName, "CancelOrderRequestReceived"); } IOrderExecutionProvider orderExecutionProvider; if (_providersMap.TryGetValue(order.OrderExecutionProvider, out orderExecutionProvider)) { ILimitOrderProvider limitOrderProvider = orderExecutionProvider as ILimitOrderProvider; if (limitOrderProvider != null) { // Modify Order ID by appending Application ID in the front order.OrderID = appId + "|" + order.OrderID; // Send Order Cancel request to Execution Provider limitOrderProvider.CancelLimitOrder(order); } else { if (Logger.IsInfoEnabled) { Logger.Info("Requested provider doesn't support Order Cancellations", _type.FullName, "CancelOrderRequestReceived"); } } } else { if (Logger.IsInfoEnabled) { Logger.Info( "Order Execution Provider module not available for: " + order.OrderExecutionProvider, _type.FullName, "CancelOrderRequestReceived"); } } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "CancelOrderRequestReceived"); } }