Beispiel #1
0
        /// <summary>
        /// Process replies on the request socket.
        /// Heartbeats, errors, and subscribing to real time data streams.
        /// </summary>
        private void _reqSocket_ReceiveReady(object sender, NetMQSocketEventArgs e)
        {
            using (var ms = new MemoryStream())
            {
                lock (_reqSocketLock)
                {
                    string reply = _reqSocket.ReceiveString();

                    if (reply == null)
                    {
                        return;
                    }

                    reply = _reqSocket.ReceiveString();

                    switch (reply)
                    {
                    case "PONG":     //reply to heartbeat message
                        _lastHeartBeat = DateTime.Now;
                        break;

                    case "ERROR":     //something went wrong
                    {
                        //first the message
                        string error = _reqSocket.ReceiveString();

                        //then the request
                        byte[] buffer  = _reqSocket.Receive();
                        var    request = MyUtils.ProtoBufDeserialize <RealTimeDataRequest>(buffer, ms);

                        //error event
                        RaiseEvent(Error, this, new ErrorArgs(-1, "Real time data request error: " + error, request.RequestID));
                        return;
                    }

                    case "SUCCESS":     //successful request to start a new real time data stream
                    {
                        //receive the request
                        byte[] buffer  = _reqSocket.Receive();
                        var    request = MyUtils.ProtoBufDeserialize <RealTimeDataRequest>(buffer, ms);

                        //Add it to the active streams
                        lock (_realTimeDataStreamsLock)
                        {
                            RealTimeDataStreams.Add(request);
                        }

                        //request worked, so we subscribe to the stream
                        _subSocket.Subscribe(BitConverter.GetBytes(request.Instrument.ID.Value));
                    }
                    break;

                    case "CANCELED":     //successful cancelation of a real time data stream
                    {
                        //also receive the symbol
                        string symbol = _reqSocket.ReceiveString();

                        //nothing to do?
                    }
                    break;
                    }
                }
            }
        }