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) { if (!IsInitialised) { return; } DateTime niffleTimeStamp = DateTime.FromBinary(e.Message.Timestamp); RoutingKey routingKey = new RoutingKey(e.EventArgs.RoutingKey); string source = routingKey.GetSource(); string action = routingKey.GetAction(); string _event = routingKey.GetEvent(); //Service messages received will be notify if (e.Message.Type == Niffle.Types.Type.Service) { if (e.Message.Service != null) { if (e.Message.Service.Success) { ReportExecution(source, action, _event, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } } //Positions messages will be for Position Opened, Closed or Modified. if (e.Message.Type == Niffle.Types.Type.Positions) { if (e.Message.Positions != null) { Messaging.Protobuf.Positions positions = e.Message.Positions; for (int count = 0; count < positions.Count; count++) { if (routingKey.GetEventAsEnum() == Event.ONPOSITIONCLOSED) { if (positions.Position[count].StateChange == Messaging.Protobuf.Position.Types.StateChange.Closed) { ReportPositionClosed(positions.Position[count]); } } if (routingKey.GetEventAsEnum() == Event.ONPOSITIONOPENED) { if (positions.Position[count].StateChange == Messaging.Protobuf.Position.Types.StateChange.Opened) { ReportPositionOpened(positions.Position[count]); } } if (routingKey.GetEventAsEnum() == Event.ONPOSITIONMODIFIED) { if (positions.Position[count].StateChange == Messaging.Protobuf.Position.Types.StateChange.Modified) { ReportPositionModified(positions.Position[count], Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } } } } //Orders messages will be for Orders Placed, Cancelled or Modified if (e.Message.Type == Niffle.Types.Type.Orders) { if (e.Message.Orders != null) { Messaging.Protobuf.Orders orders = e.Message.Orders; for (int count = 0; count < orders.Count; count++) { if (routingKey.GetEventAsEnum() == Event.ONORDERPLACED) { if (orders.Order[count].StateChange == Messaging.Protobuf.Order.Types.StateChange.Placed) { ReportOrderPlaced(orders.Order[count]); } } if (routingKey.GetEventAsEnum() == Event.ONORDERCANCELLED) { if (orders.Order[count].StateChange == Messaging.Protobuf.Order.Types.StateChange.Cancelled) { ReportOrderCancelled(orders.Order[count], Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } if (routingKey.GetEventAsEnum() == Event.ONORDERMODIFIED) { if (orders.Order[count].StateChange == Messaging.Protobuf.Order.Types.StateChange.Modified) { ReportOrderModified(orders.Order[count], Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } } } } //Error messages if (e.Message.Type == Niffle.Types.Type.Orders) { if (e.Message.Error != null) { ReportError(source, e.Message.Error, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } }
protected override void OnMessageReceived(object sender, MessageReceivedEventArgs e) { if (!IsInitialised) { return; } DateTime niffleTimeStamp = DateTime.FromBinary(e.Message.TimeStamp); RoutingKey routingKey = new RoutingKey(e.EventArgs.RoutingKey); string source = routingKey.GetSource(); string action = routingKey.GetAction(); string _event = routingKey.GetEvent(); //Service messages received will be notify if (e.Message.Type == Niffle.Types.Type.Service) { if (e.Message.Service != null) { if (e.Message.Service.Success) { ReportExecution(source, action, _event, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); //If Strategy ended then report. if (source == nameof(OnTerminateTime)) { Report(); //Reset(); } } } } //Position message will be for Position Opened or Closed if (e.Message.Type == Niffle.Types.Type.Position) { if (e.Message.Position != null) { if (routingKey.GetEventAsEnum() == Event.ONPOSITIONCLOSED) { if (e.Message.Position.StateChange == Messaging.Protobuf.Position.Types.StateChange.Closed) { ReportPositionClosed(e.Message.Position); } } if (routingKey.GetEventAsEnum() == Event.ONPOSITIONOPENED) { if (e.Message.Position.StateChange == Messaging.Protobuf.Position.Types.StateChange.Opened) { ReportPositionOpened(e.Message.Position); } } if (routingKey.GetEventAsEnum() == Event.ONPOSITIONMODIFIED) { if (e.Message.Position.StateChange == Messaging.Protobuf.Position.Types.StateChange.Modified) { ReportPositionModified(e.Message.Position, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } } } //Orders messages will be for Orders Placed, Cancelled or Modified if (e.Message.Type == Niffle.Types.Type.Order) { if (e.Message.Order != null) { if (routingKey.GetEventAsEnum() == Event.ONORDERPLACED) { if (e.Message.Order.StateChange == Messaging.Protobuf.Order.Types.StateChange.Filled) { ReportOrderPlaced(e.Message.Order); } } if (routingKey.GetEventAsEnum() == Event.ONORDERCANCELLED) { if (e.Message.Order.StateChange == Messaging.Protobuf.Order.Types.StateChange.Canceled) { ReportOrderCancelled(e.Message.Order, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } //Need to work out how to determine if order has been modified if (routingKey.GetEventAsEnum() == Event.ONORDERMODIFIED) { if (e.Message.Order.StateChange == Messaging.Protobuf.Order.Types.StateChange.Filled) { ReportOrderModified(e.Message.Order, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } } } //Error messages if (e.Message.Type == Niffle.Types.Type.Error) { if (e.Message.Error != null) { ReportError(source, e.Message.Error, Utils.FormatDateTimeWithSeparators(niffleTimeStamp)); } } }
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; } ; }