Example #1
0
        public void FromOrders(IEnumerable <Order> orders)
        {
            foreach (var symbol in orders.Select(x => x.Symbol).Distinct())
            {
                Resolution resolution;
                switch (symbol.SecurityType)
                {
                case SecurityType.Option:
                case SecurityType.Future:
                    resolution = Resolution.Minute;
                    break;

                default:
                    resolution = Resolution.Daily;
                    break;
                }

                var configs  = SubscriptionManager.SubscriptionDataConfigService.Add(symbol, resolution, false, false);
                var security = Securities.CreateSecurity(symbol, configs, 0m);
                if (symbol.SecurityType == SecurityType.Crypto)
                {
                    security.BuyingPowerModel = new SecurityMarginModel();
                }

                // Set leverage to 10000 to account for unknown leverage values in user algorithms
                security.SetLeverage(10000m);

                var method = typeof(QCAlgorithm).GetMethod("AddToUserDefinedUniverse", BindingFlags.NonPublic | BindingFlags.Instance);
                method.Invoke(this, new object[] { security, configs });
            }
        }
        public void FromOrders(IEnumerable <Order> orders)
        {
            foreach (var symbol in orders.Select(x => x.Symbol).Distinct())
            {
                var configs  = SubscriptionManager.SubscriptionDataConfigService.Add(symbol, Resolution.Daily, false, false);
                var security = Securities.CreateSecurity(symbol, configs, 10000m);

                var method = typeof(QCAlgorithm).GetMethod("AddToUserDefinedUniverse", BindingFlags.NonPublic | BindingFlags.Instance);
                method.Invoke(this, new object[] { security, configs });
            }
        }
Example #3
0
        /// <summary>
        /// Get all fundamental data for given symbols
        /// </summary>
        /// <param name="symbols">The symbols to retrieve fundamental data for</param>
        /// <param name="start">The start date of selected data</param>
        /// <param name="end">The end date of selected data</param>
        /// <returns>DataDictionary of Enumerable IBaseData</returns>
        private Dictionary <DateTime, DataDictionary <dynamic> > GetAllFundamental(IEnumerable <Symbol> symbols, string selector, DateTime?start = null, DateTime?end = null)
        {
            //SubscriptionRequest does not except nullable DateTimes, so set a startTime and endTime
            var startTime = start.HasValue ? (DateTime)start : QuantConnect.Time.BeginningOfTime;
            var endTime   = end.HasValue ? (DateTime)end : DateTime.UtcNow.Date;

            //Collection to store our results
            var data = new Dictionary <DateTime, DataDictionary <dynamic> >();

            //Build factory
            var factory = new FineFundamentalSubscriptionEnumeratorFactory(false);

            //Get all data for each symbol and fill our dictionary
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            Parallel.ForEach(symbols, options, symbol =>
            {
                var config = new SubscriptionDataConfig(
                    typeof(FineFundamental),
                    symbol,
                    Resolution.Daily,
                    TimeZones.NewYork,
                    TimeZones.NewYork,
                    false,
                    false,
                    false
                    );
                var security = Securities.CreateSecurity(symbol, config);
                var request  = new SubscriptionRequest(false, null, security, config, startTime.ConvertToUtc(TimeZones.NewYork), endTime.ConvertToUtc(TimeZones.NewYork));
                using (var enumerator = factory.CreateEnumerator(request, _dataProvider))
                {
                    while (enumerator.MoveNext())
                    {
                        var dataPoint = string.IsNullOrWhiteSpace(selector)
                            ? enumerator.Current
                            : GetPropertyValue(enumerator.Current, selector);

                        lock (data)
                        {
                            if (!data.ContainsKey(enumerator.Current.Time))
                            {
                                data[enumerator.Current.Time] = new DataDictionary <dynamic>(enumerator.Current.Time);
                            }
                            data[enumerator.Current.Time].Add(enumerator.Current.Symbol, dataPoint);
                        }
                    }
                }
            });
            return(data);
        }