Example #1
0
        /// <summary>
        ///     Called ona reply to a historical data request
        /// </summary>
        private void HandleHistoricalDataRequestReply()
        {
            using (var ms = new MemoryStream())
            {
                // 2nd message part: the HistoricalDataRequest object that was used to make the request
                bool hasMore;
                var  requestBuffer = _historicalDataSocket.ReceiveFrameBytes(out hasMore);
                if (!hasMore)
                {
                    return;
                }

                var request = MyUtils.ProtoBufDeserialize <HistoricalDataRequest>(requestBuffer, ms);
                // 3rd message part: the size of the uncompressed, serialized data. Necessary for decompression.
                var sizeBuffer = _historicalDataSocket.ReceiveFrameBytes(out hasMore);
                if (!hasMore)
                {
                    return;
                }

                var outputSize = BitConverter.ToInt32(sizeBuffer, 0);
                // 4th message part: the compressed serialized data.
                var dataBuffer   = _historicalDataSocket.ReceiveFrameBytes();
                var decompressed = LZ4Codec.Decode(dataBuffer, 0, dataBuffer.Length, outputSize);
                var data         = MyUtils.ProtoBufDeserialize <List <OHLCBar> >(decompressed, ms);
                // Remove from pending requests
                lock (_pendingHistoricalRequestsLock)
                {
                    PendingHistoricalRequests.RemoveAll(x => x.RequestID == request.RequestID);
                }

                RaiseEvent(HistoricalDataReceived, this, new HistoricalDataEventArgs(request, data));
            }
        }
Example #2
0
        /// <summary>
        ///     Called when we get some sort of error reply
        /// </summary>
        private void HandleErrorReply()
        {
            // The request ID
            byte[] buffer = historicalDataSocket.ReceiveFrameBytes(out bool hasMore);
            if (!hasMore)
            {
                return;
            }
            int requestId = BitConverter.ToInt32(buffer, 0);

            // Remove from pending requests
            lock (pendingHistoricalRequestsLock)
            {
                PendingHistoricalRequests.RemoveAll(x => x.RequestID == requestId);
            }
            // Finally the error message
            string message = historicalDataSocket.ReceiveFrameString();

            // Raise the error event
            RaiseEvent(Error, this, new ErrorArgs(-1, message, requestId));
        }
Example #3
0
        /// <summary>
        /// Called when we get some sort of error reply
        /// </summary>
        private void HandleErrorReply()
        {
            //the request ID
            bool hasMore;

            byte[] buffer = _dealerSocket.Receive(out hasMore);
            if (!hasMore)
            {
                return;
            }
            int requestID = BitConverter.ToInt32(buffer, 0);

            //remove from pending requests
            lock (_pendingHistoricalRequestsLock)
            {
                PendingHistoricalRequests.RemoveAll(x => x.RequestID == requestID);
            }

            //finally the error message
            string message = _dealerSocket.ReceiveString();

            //raise the error event
            RaiseEvent(Error, this, new ErrorArgs(-1, message, requestID));
        }