示例#1
0
        /// <summary>
        /// </summary>
        /// <param name="compare"></param>
        /// <returns></returns>
        public bool Equals(RealTimeStreamInfo compare)
        {
            bool equal =
                compare.RequestID == RequestID &&
                compare.Datasource == Datasource &&
                compare.Instrument.ID == Instrument.ID &&
                compare.Frequency == Frequency &&
                compare.RTHOnly == RTHOnly;

            return(equal);
        }
示例#2
0
        /// <summary>
        /// Sends a real time data request to the correct data source, logs it, and updates subscriber counts
        /// </summary>
        /// <param name="request"></param>
        private void ForwardRTDRequest(RealTimeDataRequest request)
        {
            //send the request to the correct data source
            try
            {
                DataSources[request.Instrument.Datasource.Name].RequestRealTimeData(request);
            }
            catch (Exception ex)
            {
                Log(LogLevel.Error, "Error requesting real time data: " + ex.Message);
                return;
            }

            //log the request
            Log(LogLevel.Info,
                string.Format("RTD Request: {0} from {1} @ {2} ID:{3}",
                              request.Instrument.Symbol,
                              request.Instrument.Datasource.Name,
                              Enum.GetName(typeof(BarSize), request.Frequency),
                              request.AssignedID));

            //add the request to the active streams, though it's not necessarily active yet
            var streamInfo = new RealTimeStreamInfo(
                request.Instrument,
                request.AssignedID,
                request.Instrument.Datasource.Name,
                request.Frequency,
                request.RTHOnly);

            lock (_activeStreamsLock)
            {
                ActiveStreams.TryAdd(streamInfo);
            }

            lock (_subscriberCountLock)
            {
                StreamSubscribersCount.Add(streamInfo, 1);
            }
        }
示例#3
0
        /// <summary>
        /// This method is called when the continuous futures broker returns the results of a request for the "front"
        /// contract of a continuous futures instrument.
        /// </summary>
        private void _cfBroker_FoundFrontContract(object sender, FoundFrontContractEventArgs e)
        {
            RealTimeDataRequest request;

            if (!e.Instrument.ID.HasValue)
            {
                Log(LogLevel.Error, "CF Broker returned front contract with no ID");
                return;
            }

            Log(LogLevel.Info, string.Format("Front contract received on request ID {0}, is: {1}", e.ID, e.Instrument.Symbol));

            //grab the original request
            lock (_cfRequestLock)
            {
                request = _pendingCFRealTimeRequests[e.ID];
                _pendingCFRealTimeRequests.Remove(e.ID);
            }

            //add the contract to the ID map
            if (request.Instrument.ID.HasValue &&
                !_continuousFuturesIDMap.ContainsKey(request.Instrument.ID.Value))
            {
                _continuousFuturesIDMap.Add(request.Instrument.ID.Value, e.Instrument.ID.Value);
            }

            //add the alias
            lock (_aliasLock)
            {
                int contractID = e.Instrument.ID.Value;
                if (!_aliases.ContainsKey(contractID))
                {
                    _aliases.Add(contractID, new List <int>());
                }

                if (request.Instrument.ID.HasValue)
                {
                    _aliases[contractID].Add(request.Instrument.ID.Value);
                }
            }

            //need to check if there's already a stream of the contract....
            bool streamExists;

            lock (_activeStreamsLock)
            {
                streamExists = ActiveStreams.Collection.Any(x => x.Instrument.ID == e.Instrument.ID);
            }

            if (streamExists)
            {
                //all we need to do in this case is increment the number of subscribers to this stream
                IncrementSubscriberCount(e.Instrument);

                //log it
                Log(LogLevel.Info,
                    string.Format("RTD Request for CF {0} @ {1} {2}, filled by existing stream of symbol {3}.",
                                  request.Instrument.Symbol,
                                  request.Instrument.Datasource.Name,
                                  Enum.GetName(typeof(BarSize), request.Frequency),
                                  e.Instrument.Symbol));
            }
            else //no current stream of this contract, add it
            {
                //make the request
                var contractRequest = (RealTimeDataRequest)request.Clone();
                contractRequest.Instrument = e.Instrument; //we take the original request, and substitute the CF for the front contract
                ForwardRTDRequest(contractRequest);

                //add the request to the active streams, though it's not necessarily active yet
                var streamInfo = new RealTimeStreamInfo(
                    request.Instrument,
                    -1,
                    request.Instrument.Datasource.Name,
                    request.Frequency,
                    request.RTHOnly);

                lock (_activeStreamsLock)
                {
                    ActiveStreams.TryAdd(streamInfo);
                }

                lock (_subscriberCountLock)
                {
                    StreamSubscribersCount.Add(streamInfo, 1);
                }

                //log it
                Log(LogLevel.Info,
                    string.Format("RTD Request for CF: {0} from {1} @ {2}, filled by contract: {3}",
                                  request.Instrument.Symbol,
                                  request.Instrument.Datasource.Name,
                                  Enum.GetName(typeof(BarSize), request.Frequency),
                                  e.Instrument.Symbol));
            }
        }