Ejemplo n.º 1
0
        public static MdpMessage GetMessage(byte[] data)
        {
            MessageType type = GetType(data);

            MdpMessage mes = null;

            if (type == MessageType.SecurityDefinition)
            {
                mes = new SecurityDefinition();
            }
            else if (type == MessageType.SecurityStatus)
            {
                mes = new StatusUpdate();
            }
            else if (type == MessageType.MarketDataSnapshotFullRefresh)
            {
                mes = new SnapshotUpdate();
            }
            else if (type == MessageType.MarketDataIncrementalRefresh)
            {
                mes = new IncrementalUpdate();
            }

            mes.Decode(data);

            return(mes);
        }
Ejemplo n.º 2
0
        private void HandleMessage(MdpMessage message)
        {
            if (message is MdpHeartbeat && HeartbeatReceived != null)
            {
                HeartbeatReceived(this, (MdpHeartbeat)message);
            }
            else if (message is SecurityDefinition && SecurityDefinitionReceived != null)
            {
                SecurityDefinitionReceived(this, (SecurityDefinition)message);
            }
            else if (message is StatusUpdate && StatusUpdateReceived != null)
            {
                StatusUpdateReceived(this, (StatusUpdate)message);
            }
            else if (message is SnapshotUpdate && SnapshotUpdateReceived != null)
            {
                SnapshotUpdateReceived(this, (SnapshotUpdate)message);
            }
            else if (message is IncrementalUpdate && IncrementalUpdateReceived != null)
            {
                IncrementalUpdateReceived(this, (IncrementalUpdate)message);
            }

            //lastSequenceNumberProcessed = message.Header.SequenceNumber;
        }
Ejemplo n.º 3
0
        public async void Send(MdpMessage message)
        {
            //message.Header.SequenceNumber = nextSequenceNumberToSend;
            nextSequenceNumberToSend++;

            message.Validate();
            byte[] data = message.Encode();

            Console.WriteLine($"S -> {message.GetType().Name} {message}");
            Console.WriteLine(message.ToRawString());

            await udpClient.SendAsync(data, data.Length, ipEndPoint);

            lastMessageSent = DateTime.UtcNow;
        }
Ejemplo n.º 4
0
        private bool ValidateHeader(MdpMessage message)
        {
            //if (message.Header.SequenceNumber < nextSequenceNumberToReceive)
            //	return false;

            //if (message.Header.SequenceNumber > nextSequenceNumberToReceive)
            {
                // TODO: Handle skipped incoming message
                //return false;
            }

            nextSequenceNumberToReceive++;

            return(true);
        }
Ejemplo n.º 5
0
        private void Process(byte[] data)
        {
            var message = MdpMessage.GetMessage(data);

            if (message == null)
            {
                // error
                return;
            }

            message.Validate();

            Console.WriteLine($"C <- {message.GetType().Name} {message}");
            lastMessageReceived = DateTime.UtcNow;

            if (!ValidateHeader(message))
            {
                return;
            }

            HandleMessage(message);
        }