protected override void OnMessageReceived(object sender, MessageReceivedEventArgs e) { DateTime niffleTimeStamp = DateTime.FromBinary(e.Message.Timestamp); RoutingKey routingKey = new RoutingKey(e.EventArgs.RoutingKey); string action = routingKey.GetAction(); string _event = routingKey.GetEvent(); //Check it is a trade operation if (routingKey.GetActionAsEnum() != Messaging.RabbitMQ.Action.TRADEOPERATION) { return; } //Single Trade operation messages if (e.Message.Type == Niffle.Types.Type.Trade) { if (e.Message.Trade != null) { ExecuteTradeOperation(e.Message.Trade); } } //Multiple Trades operation messages if (e.Message.Type == Niffle.Types.Type.Trades) { if (e.Message.Trades != null) { foreach (Trade trade in e.Message.Trades.Trade) { ExecuteTradeOperation(trade); } } } }
protected override void OnMessageReceived(object sender, MessageReceivedEventArgs e) { DateTime niffleTimeStamp = DateTime.FromBinary(e.Message.TimeStamp); RoutingKey routingKey = new RoutingKey(e.EventArgs.RoutingKey); string action = routingKey.GetAction(); string _event = routingKey.GetEvent(); switch (routingKey.GetActionAsEnum()) { case Messaging.RabbitMQ.Action.TRADEMANAGEMENT: // Add order labels and action required on filled to State in order to listen for them and take action break; case Messaging.RabbitMQ.Action.TRADEOPERATION: // Check State for order labels of filled orders and place Stop loss or Take Profit orders. break; default: return; } ; //Single Trade operation messages if (e.Message.Type == Niffle.Types.Type.Trade) { if (e.Message.Trade != null) { ExecuteTradeOperation(e.Message.Trade); } } //Multiple Trades operation messages //if (e.Message.Type == Niffle.Types.Type.Trades) //{ // if (e.Message.Trades != null) // { // foreach (Trade trade in e.Message.Trades.Trade) // { // ExecuteTradeOperation(trade); // } // } //} }
protected override void OnMessageReceived(object sender, MessageReceivedEventArgs e) { DateTime niffleTimeStamp = DateTime.FromBinary(e.Message.TimeStamp); RoutingKey routingKey = new RoutingKey(e.EventArgs.RoutingKey); string action = routingKey.GetAction(); string _event = routingKey.GetEvent(); Trade trade = e.Message.Trade; switch (routingKey.GetActionAsEnum()) { case Messaging.RabbitMQ.Action.TRADEMANAGEMENT: //Save the trade to execute against the Linked Trade label StateManager.UpdateStateLinkedTradeAsync(trade.LinkedTradeLabel, trade.Order.Label, trade); break; } // Need to have another transforming service if FIX service only publishes raw messages // Need to have a service that listens for routing key FIXServiceName.*.* // This service will then have to unpack the FIX API message and construct the appropriate msg and routing key switch (routingKey.GetEventAsEnum()) { case Messaging.RabbitMQ.Event.ONPOSITIONCLOSED: switch (e.Message.Trade.Order.StateChange) { case Order.Types.StateChange.Filled: //The stateChange should be used to set the routing key and not needed here. //Check if this is a linked trade if (trade.IsLinkedTrade) { //Save the state of the filled linked trade StateManager.UpdateStateLinkedTradeAsync(trade.LinkedTradeLabel, trade.Order.Label, trade); //Find all other linked trades and cancel them StateManager.FindAllLinkedTradesExcludingAsync(trade.LinkedTradeLabel, trade.Order.Label, CancelTradeOperation); } //This is a masker trade therefore place any linked SL and TP trades else { //Find all linked trades and excute them StateManager.FindAllLinkedTradesAsync(trade.LinkedTradeLabel, trade.Order.PosMaintRptID, ExecuteTradeOperation); } break; case Order.Types.StateChange.Canceled: //If this is a masker trade then cancel any linked SL and TP trades if (!trade.IsLinkedTrade) { //Find all linked trades and cancel them StateManager.FindAllLinkedTradesAsync(trade.LinkedTradeLabel, trade.Order.PosMaintRptID, CancelTradeOperation); } break; } //Order filled if (e.Message.Trade.Order.StateChange == Order.Types.StateChange.Filled) { } break; default: return; } ; }