/// <summary>
            /// Populate request data
            /// </summary>
            public IEnumerable<Slice> ProcessHistoryRequests(HistoryRequest request)
            {                
                // we can only process equity/forex types here
                if (request.SecurityType != SecurityType.Forex && request.SecurityType != SecurityType.Equity)
                {
                    yield break;
                }

                // Set this process status
                _inProgress = true;

                var symbol = request.Symbol.Value;
                if (request.SecurityType == SecurityType.Forex)
                {
                    symbol = symbol + ".FXCM";
                }

                var start = request.StartTimeUtc.ConvertFromUtc(TimeZones.NewYork);
                DateTime? end = request.EndTimeUtc.ConvertFromUtc(TimeZones.NewYork);
                // if we're within a minute of now, don't set the end time
                if (request.EndTimeUtc >= DateTime.UtcNow.AddMinutes(-1))
                {
                    end = null;
                }

                Log.Trace(string.Format("HistoryPort.ProcessHistoryJob(): Submitting request: {0}-{1}: {2} {3}->{4}", request.SecurityType, symbol, request.Resolution, start, end ?? DateTime.UtcNow.AddMinutes(-1)));

                int id;
                var reqid = string.Empty;

                switch (request.Resolution)
                {
                    case Resolution.Tick:
                        id = RequestTickData(symbol, start, end, true);
                        reqid = CreateRequestID(LookupType.REQ_HST_TCK, id);
                        break;
                    case Resolution.Daily:
                        id = RequestDailyData(symbol, start, end, true);
                        reqid = CreateRequestID(LookupType.REQ_HST_DWM, id);
                        break;
                    default:
                        var interval = new Interval(GetPeriodType(request.Resolution), 1);
                        id = RequestIntervalData(symbol, interval, start, end, true);
                        reqid = CreateRequestID(LookupType.REQ_HST_INT, id);
                        break;
                }

                _requestDataByRequestId[reqid] = request;

                while (_inProgress)
                {
                    continue;
                }

                // After all data arrive, we pass it to the algorithm through memory and write to a file
                foreach (var key in _currentRequest.Keys)
                {
                    List<BaseData> tradeBars;
                    if (_currentRequest.TryRemove(key, out tradeBars))
                    {
                        foreach (var tradeBar in tradeBars)
                        {
                            // Returns IEnumerable<Slice> object
                            yield return new Slice(tradeBar.EndTime, new[] { tradeBar });
                        }
                    }
                }
            }
示例#2
0
            /// <summary>
            /// Populate request data
            /// </summary>
            public IEnumerable <Slice> ProcessHistoryRequests(HistoryRequest request)
            {
                // skipping universe and canonical symbols
                if (!CanHandle(request.Symbol) ||
                    (request.Symbol.ID.SecurityType == SecurityType.Option && request.Symbol.IsCanonical()) ||
                    (request.Symbol.ID.SecurityType == SecurityType.Future && request.Symbol.IsCanonical()))
                {
                    yield break;
                }

                // Set this process status
                _inProgress = true;

                var      ticker = _symbolUniverse.GetBrokerageSymbol(request.Symbol);
                var      start  = request.StartTimeUtc.ConvertFromUtc(TimeZones.NewYork);
                DateTime?end    = request.EndTimeUtc.ConvertFromUtc(TimeZones.NewYork);

                // if we're within a minute of now, don't set the end time
                if (request.EndTimeUtc >= DateTime.UtcNow.AddMinutes(-1))
                {
                    end = null;
                }

                Log.Trace(string.Format("HistoryPort.ProcessHistoryJob(): Submitting request: {0}-{1}: {2} {3}->{4}", request.SecurityType, ticker, request.Resolution, start, end ?? DateTime.UtcNow.AddMinutes(-1)));

                int id;
                var reqid = string.Empty;

                switch (request.Resolution)
                {
                case Resolution.Tick:
                    id    = RequestTickData(ticker, start, end, true);
                    reqid = CreateRequestID(LookupType.REQ_HST_TCK, id);
                    break;

                case Resolution.Daily:
                    id    = RequestDailyData(ticker, start, end, true);
                    reqid = CreateRequestID(LookupType.REQ_HST_DWM, id);
                    break;

                default:
                    var interval = new Interval(GetPeriodType(request.Resolution), 1);
                    id    = RequestIntervalData(ticker, interval, start, end, true);
                    reqid = CreateRequestID(LookupType.REQ_HST_INT, id);
                    break;
                }

                _requestDataByRequestId[reqid] = request;

                while (_inProgress)
                {
                    continue;
                }

                // After all data arrive, we pass it to the algorithm through memory and write to a file
                foreach (var key in _currentRequest.Keys)
                {
                    List <BaseData> tradeBars;
                    if (_currentRequest.TryRemove(key, out tradeBars))
                    {
                        foreach (var tradeBar in tradeBars)
                        {
                            // Returns IEnumerable<Slice> object
                            yield return(new Slice(tradeBar.EndTime, new[] { tradeBar }));
                        }
                    }
                }
            }
        public int RequestIntervalData(string symbol, Interval interval, int days, bool oldToNew, Time timeStartInDay = null, Time timeEndInDay = null)
        {
            _lastRequestNumber++;
            var reqNo = LookupType.REQ_HST_INT.ToString() + _lastRequestNumber.ToString("0000000");
            if (timeStartInDay == null) timeStartInDay = _timeMarketOpen;
            if (timeEndInDay == null) timeEndInDay = _timeMarketClose;

            var reqString = string.Format("HID,{0},{1},{2},{3},{4},{5},{6},{7},{8}\r\n", symbol, interval.Seconds.ToString("0000000"),
                days.ToString("0000000"), _histMaxDataPoints.ToString("0000000"), timeStartInDay.IQFeedFormat, timeEndInDay.IQFeedFormat,
                oldToNew ? "1" : "0", reqNo, _histDataPointsPerSend.ToString("0000000"));
                 
            Send(reqString);
            OnLookupEvent(new LookupEventArgs(reqNo, LookupType.REQ_HST_INT, LookupSequence.MessageStart));

            return _lastRequestNumber;
        }
        public int RequestIntervalData(string symbol, Interval interval, DateTime start, DateTime? end, bool oldToNew, Time timeStartInDay = null, Time timeEndInDay = null)
        {
            _lastRequestNumber++;
            var reqNo = LookupType.REQ_HST_INT.ToString() + _lastRequestNumber.ToString("0000000");
            //if (timeStartInDay == null) timeStartInDay = _timeMarketOpen;
            //if (timeEndInDay == null) timeEndInDay = _timeMarketClose;

            var reqString = string.Format("HIT,{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}\r\n", symbol, interval.Seconds.ToString("0000000"),
                start.ToString("yyyyMMdd HHmmss"), end.HasValue ? end.Value.ToString("yyyyMMdd HHmmss") : "",
                "", timeStartInDay == null ? "" : timeStartInDay.IQFeedFormat, timeEndInDay == null ? "" : timeEndInDay.IQFeedFormat,  oldToNew ? "1" : "0",
                 reqNo, _histDataPointsPerSend.ToString("0000000"));

            Send(reqString);
            OnLookupEvent(new LookupEventArgs(reqNo, LookupType.REQ_HST_INT, LookupSequence.MessageStart));

            return _lastRequestNumber;
        }
        public int RequestIntervalData(string symbol, Interval interval, int dataPoints, bool oldToNew)
        {
            _lastRequestNumber++;
            var reqNo = LookupType.REQ_HST_INT.ToString() + _lastRequestNumber.ToString("0000000");
 
            var reqString = string.Format("HIX,{0},{1},{2},{3},{4},{5}\r\n", symbol, interval.Seconds.ToString("0000000"),
                dataPoints.ToString("0000000"), oldToNew ? "1" : "0", reqNo, _histDataPointsPerSend.ToString("0000000"));
            Send(reqString);
            OnLookupEvent(new LookupEventArgs(reqNo, LookupType.REQ_HST_INT, LookupSequence.MessageStart));

            return _lastRequestNumber;
        }