Ejemplo n.º 1
0
        /// <summary>
        /// Gets the historical data for the specified symbols. The exact number of bars will be returned for
        /// each symbol. This may result in some data start earlier/later than others due to when various
        /// exchanges are open. The symbols must exist in the Securities collection.
        /// </summary>
        /// <param name="type">The data type of the symbols</param>
        /// <param name="tickers">The symbols to retrieve historical data for</param>
        /// <param name="periods">The number of bars to request</param>
        /// <param name="resolution">The resolution to request</param>
        /// <returns>pandas.DataFrame containing the requested historical data</returns>
        public PyObject History(PyObject type, PyObject tickers, int periods, Resolution?resolution = null)
        {
            var symbols = GetSymbolsFromPyObject(tickers);

            if (symbols == null)
            {
                return(null);
            }

            var requests = symbols.Select(x =>
            {
                var security = Securities[x];
                var config   = security.Subscriptions.OrderByDescending(s => s.Resolution)
                               .FirstOrDefault(s => s.Type.BaseType == CreateType(type).BaseType);
                if (config == null)
                {
                    return(null);
                }

                Resolution?res = resolution ?? security.Resolution;
                var start      = GetStartTimeAlgoTz(x, periods, resolution).ConvertToUtc(TimeZone);
                return(CreateHistoryRequest(config, start, UtcTime.RoundDown(res.Value.ToTimeSpan()), resolution));
            });

            return(PandasConverter.GetDataFrame(History(requests.Where(x => x != null)).Memoize()));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Helper methods to create a history request for the specified symbols and bar count
 /// </summary>
 private IEnumerable <HistoryRequest> CreateBarCountHistoryRequests(IEnumerable <Symbol> symbols, int periods, Resolution?resolution = null)
 {
     return(symbols.Select(x =>
     {
         var security = Securities[x];
         Resolution?res = resolution ?? security.Resolution;
         var start = GetStartTimeAlgoTz(x, periods, res).ConvertToUtc(security.Exchange.TimeZone);
         return CreateHistoryRequest(security, start, UtcTime.RoundDown(res.Value.ToTimeSpan()), resolution);
     }));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the historical data for the specified symbols. The exact number of bars will be returned for
        /// each symbol. This may result in some data start earlier/later than others due to when various
        /// exchanges are open. The symbols must exist in the Securities collection.
        /// </summary>
        /// <typeparam name="T">The data type of the symbols</typeparam>
        /// <param name="symbols">The symbols to retrieve historical data for</param>
        /// <param name="periods">The number of bars to request</param>
        /// <param name="resolution">The resolution to request</param>
        /// <returns>An enumerable of slice containing the requested historical data</returns>
        public IEnumerable <DataDictionary <T> > History <T>(IEnumerable <Symbol> symbols, int periods, Resolution?resolution = null)
            where T : IBaseData
        {
            var requests = symbols.Select(x =>
            {
                var config = GetMatchingSubscription(x, typeof(T));
                if (config == null)
                {
                    return(null);
                }

                var res   = GetResolution(x, resolution);
                var start = GetStartTimeAlgoTz(x, periods, res).ConvertToUtc(TimeZone);
                return(CreateHistoryRequest(config, start, UtcTime.RoundDown(res.Value.ToTimeSpan()), res));
            });

            return(History(requests.Where(x => x != null)).Get <T>().Memoize());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the historical data for the specified symbols. The exact number of bars will be returned for
        /// each symbol. This may result in some data start earlier/later than others due to when various
        /// exchanges are open. The symbols must exist in the Securities collection.
        /// </summary>
        /// <typeparam name="T">The data type of the symbols</typeparam>
        /// <param name="symbols">The symbols to retrieve historical data for</param>
        /// <param name="periods">The number of bars to request</param>
        /// <param name="resolution">The resolution to request</param>
        /// <returns>An enumerable of slice containing the requested historical data</returns>
        public IEnumerable <DataDictionary <T> > History <T>(IEnumerable <Symbol> symbols, int periods, Resolution?resolution = null)
            where T : BaseData
        {
            var requests = symbols.Select(x =>
            {
                var security = Securities[x];
                // don't make requests for symbols of the wrong type
                if (!typeof(T).IsAssignableFrom(security.SubscriptionDataConfig.Type))
                {
                    return(null);
                }

                Resolution?res = resolution ?? security.Resolution;
                var start      = GetStartTimeAlgoTz(x, periods, resolution).ConvertToUtc(TimeZone);
                return(CreateHistoryRequest(security, start, UtcTime.RoundDown(res.Value.ToTimeSpan()), resolution));
            });

            return(History(requests.Where(x => x != null)).Get <T>());
        }