Пример #1
0
        internal Resource(XmlReader reader)
        {
            ulong size;
            TimeSpan duration;
            Resolution resolution;
            uint bitrate, sample_frequency, bits_per_sample, nr_audio_channels, color_depth;

            if (ulong.TryParse (reader["size"], out size))
                this.size = size;

            if (TimeSpan.TryParse (reader["duration"], out duration)) // TODO our own parsing
                this.duration = duration;

            if (uint.TryParse (reader["bitrate"], out bitrate))
                this.bitrate = bitrate;

            if (uint.TryParse (reader["sampleFrequency"], out sample_frequency))
                this.sample_frequency = sample_frequency;

            if (uint.TryParse (reader["bitsPerSecond"], out bits_per_sample))
                this.bits_per_sample = bits_per_sample;

            if (uint.TryParse (reader["nrAudioChannels"], out nr_audio_channels))
                this.nr_audio_channels = nr_audio_channels;

            // FIXME I shouldn't have to qualify this
            if (Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Resolution.TryParse (reader["resolution"], out resolution))
                this.resolution = resolution;

            if (uint.TryParse (reader["colorDepth"], out color_depth))
                this.color_depth = color_depth;

            protocol_info = reader["protocolInfo"];

            protection = reader["protection"];

            var import_uri = reader["importUri"];
            if (Uri.IsWellFormedUriString (import_uri, UriKind.Absolute)) {
                this.import_uri = new Uri (import_uri);
            }

            uri = new Uri (reader.ReadString ());
        }
Пример #2
0
 /// <summary>
 /// Creates a new AroonOscillator indicator which will compute the AroonUp and AroonDown (as well as the delta)
 /// </summary>
 /// <param name="symbol">The symbol whose Aroon we seek</param>
 /// <param name="period">The look back period for computing number of periods since maximum and minimum</param>
 /// <param name="resolution">The resolution</param>
 /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to casting the input value to a TradeBar</param>
 /// <returns>An AroonOscillator configured with the specied periods</returns>
 public AroonOscillator AROON(string symbol, int period, Resolution?resolution = null, Func <BaseData, TradeBar> selector = null)
 {
     return(AROON(symbol, period, period, resolution, selector));
 }
Пример #3
0
        /// <summary>
        /// Creates a new AverageTrueRange indicator for the symbol. The indicator will be automatically
        /// updated on the given resolution.
        /// </summary>
        /// <param name="symbol">The symbol whose ATR we want</param>
        /// <param name="period">The smoothing period used to smooth the computed TrueRange values</param>
        /// <param name="type">The type of smoothing to use</param>
        /// <param name="resolution">The resolution</param>
        /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to casting the input value to a TradeBar</param>
        /// <returns>A new AverageTrueRange indicator with the specified smoothing type and period</returns>
        public AverageTrueRange ATR(string symbol, int period, MovingAverageType type = MovingAverageType.Simple, Resolution?resolution = null, Func <BaseData, TradeBar> selector = null)
        {
            string name = CreateIndicatorName(symbol, "ATR" + period, resolution);
            var    atr  = new AverageTrueRange(name, period, type);

            RegisterIndicator(symbol, atr, resolution, selector);
            return(atr);
        }
Пример #4
0
 public Security AddSecurity(SecurityType securityType, string symbol, Resolution?resolution, string market, bool fillDataForward, decimal leverage, bool extendedMarketHours)
 {
     return(Algo.AddSecurity(securityType, symbol, resolution, market, fillDataForward, leverage, extendedMarketHours));
 }
Пример #5
0
 /////////////////////////////////////////////////////////////////////////////////////////////////
 ///
 ///
 public Forex AddForex(string ticker, Resolution?resolution = null, string market = null, bool fillDataForward = true, decimal leverage = Security.NullLeverage)
 {
     return(Algo.AddForex(ticker, resolution, market, fillDataForward, leverage));
 }
Пример #6
0
 /// <summary>
 /// Set a required SecurityType-symbol and resolution for algorithm
 /// </summary>
 /// <param name="securityType">SecurityType Enum: Equity, Commodity, FOREX or Future</param>
 /// <param name="symbol">Symbol Representation of the MarketType, e.g. AAPL</param>
 /// <param name="resolution">The <see cref="Resolution"/> of market data, Tick, Second, Minute, Hour, or Daily.</param>
 /// <param name="market">The market the requested security belongs to, such as 'usa' or 'fxcm'</param>
 /// <param name="fillDataForward">If true, returns the last available data even if none in that timeslice.</param>
 /// <param name="leverage">leverage for this security</param>
 /// <param name="extendedMarketHours">ExtendedMarketHours send in data from 4am - 8pm, not used for FOREX</param>
 /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
 /// <param name="dataNormalizationMode">The price scaling mode to use for the security</param>
 public Security AddSecurity(SecurityType securityType, string symbol, Resolution?resolution, string market, bool fillDataForward, decimal leverage, bool extendedMarketHours,
                             DataMappingMode?dataMappingMode = null, DataNormalizationMode?dataNormalizationMode = null)
 => _baseAlgorithm.AddSecurity(securityType, symbol, resolution, market, fillDataForward, leverage, extendedMarketHours, dataMappingMode, dataNormalizationMode);
Пример #7
0
 /// <summary>
 /// Creates and registers a new consolidator to receive automatic at the specified resolution as well as configures
 /// the indicator to receive updates from the consolidator.
 /// </summary>
 /// <param name="symbol">The symbol to register against</param>
 /// <param name="indicator">The indicator to receive data from the consolidator</param>
 /// <param name="resolution">The resolution at which to send data to the indicator, null to use the same resolution as the subscription</param>
 /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to the Value property of BaseData (x => x.Value)</param>
 public void RegisterIndicator(string symbol, IndicatorBase <IndicatorDataPoint> indicator, Resolution?resolution = null, Func <BaseData, decimal> selector = null)
 {
     RegisterIndicator(symbol, indicator, ResolveConsolidator(symbol, resolution), selector ?? (x => x.Value));
 }
Пример #8
0
        /// <summary>
        /// Creates a new RelativeStrengthIndex indicator. This will produce an oscillator that ranges from 0 to 100 based
        /// on the ratio of average gains to average losses over the specified period.
        /// </summary>
        /// <param name="symbol">The symbol whose RSI we want</param>
        /// <param name="period">The period over which to compute the RSI</param>
        /// <param name="movingAverageType">The type of moving average to use in computing the average gain/loss values</param>
        /// <param name="resolution">The resolution</param>
        /// <returns>The RelativeStrengthIndex indicator for the requested symbol over the speified period</returns>
        public RelativeStrengthIndex RSI(string symbol, int period, MovingAverageType movingAverageType = MovingAverageType.Simple, Resolution?resolution = null)
        {
            var name = CreateIndicatorName(symbol, "RSI" + period, resolution);
            var rsi  = new RelativeStrengthIndex(name, period, movingAverageType);

            RegisterIndicator(symbol, rsi, resolution, x => x.Value);
            return(rsi);
        }
Пример #9
0
 /// <summary>
 /// Gets the historical data for the specified symbol over the request span. The symbol must exist in the Securities collection.
 /// </summary>
 /// <param name="symbol">The symbol to retrieve historical data for</param>
 /// <param name="span">The span over which to retrieve recent historical data</param>
 /// <param name="resolution">The resolution to request</param>
 /// <returns>An enumerable of slice containing the requested historical data</returns>
 public IEnumerable <TradeBar> History(Symbol symbol, TimeSpan span, Resolution?resolution = null)
 {
     return(History(new[] { symbol }, span, resolution).Get(symbol));
 }
Пример #10
0
        /// <summary>
        /// Gets the historical data for the specified symbol between the specified dates. The symbol must exist in the Securities collection.
        /// </summary>
        /// <param name="symbol">The symbol to retrieve historical data for</param>
        /// <param name="start">The start time in the algorithm's time zone</param>
        /// <param name="end">The end time in the algorithm's time zone</param>
        /// <param name="resolution">The resolution to request</param>
        /// <returns>An enumerable of slice containing the requested historical data</returns>
        public IEnumerable <T> History <T>(Symbol symbol, DateTime start, DateTime end, Resolution?resolution = null)
            where T : BaseData
        {
            var security = Securities[symbol];

            // verify the types match
            var actualType    = security.SubscriptionDataConfig.Type;
            var requestedType = typeof(T);

            if (!requestedType.IsAssignableFrom(actualType))
            {
                throw new ArgumentException("The specified security is not of the requested type. Symbol: " + symbol + " Requested Type: " + requestedType.Name + " Actual Type: " + actualType);
            }

            var request = CreateHistoryRequest(security, start, end, resolution);

            return(History(request).Get <T>(symbol));
        }
Пример #11
0
 /// <summary>
 /// Gets the historical data for the specified symbol over the request span. The symbol must exist in the Securities collection.
 /// </summary>
 /// <typeparam name="T">The data type of the symbol</typeparam>
 /// <param name="symbol">The symbol to retrieve historical data for</param>
 /// <param name="span">The span over which to retrieve recent historical data</param>
 /// <param name="resolution">The resolution to request</param>
 /// <returns>An enumerable of slice containing the requested historical data</returns>
 public IEnumerable <T> History <T>(Symbol symbol, TimeSpan span, Resolution?resolution = null)
     where T : BaseData
 {
     return(History <T>(symbol, Time - span, Time, resolution));
 }
Пример #12
0
        /// <summary>
        /// Gets the historical data for the specified symbols between the specified dates. 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="start">The start time in the algorithm's time zone</param>
        /// <param name="end">The end time in the algorithm's time zone</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, DateTime start, DateTime end, 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);
                }
                return(CreateHistoryRequest(security, start, end, resolution));
            });

            return(History(requests.Where(x => x != null)).Get <T>());
        }
Пример #13
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>());
        }
Пример #14
0
 /// <summary>
 /// Gets the historical data for the specified symbols over the requested span.
 /// 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="span">The span over which to retrieve recent historical data</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, TimeSpan span, Resolution?resolution = null)
     where T : BaseData
 {
     return(History <T>(symbols, Time - span, Time, resolution));
 }
Пример #15
0
 /// <summary>
 /// Gets the historical data for all symbols of the requested type over the requested span.
 /// The symbol's configured values for resolution and fill forward behavior will be used
 /// The symbols must exist in the Securities collection.
 /// </summary>
 /// <param name="span">The span over which to retrieve recent historical data</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>(TimeSpan span, Resolution?resolution = null)
     where T : BaseData
 {
     return(History <T>(Securities.Keys, span, resolution));
 }
Пример #16
0
 /// <summary>
 /// Creates a new AroonOscillator indicator which will compute the AroonUp and AroonDown (as well as the delta)
 /// </summary>
 /// <param name="symbol">The symbol whose Aroon we seek</param>
 /// <param name="period">The look back period for computing number of periods since maximum and minimum</param>
 /// <param name="resolution">The resolution</param>
 /// <returns>An AroonOscillator configured with the specied periods</returns>
 public AroonOscillator AROON(string symbol, int period, Resolution?resolution = null)
 {
     return(AROON(symbol, period, period, resolution));
 }
Пример #17
0
 /// <summary>
 /// Gets the historical data for the specified symbol over the request span. The symbol must exist in the Securities collection.
 /// </summary>
 /// <param name="symbol">The symbol to retrieve historical data for</param>
 /// <param name="start">The start time in the algorithm's time zone</param>
 /// <param name="end">The end time in the algorithm's time zone</param>
 /// <param name="resolution">The resolution to request</param>
 /// <returns>An enumerable of slice containing the requested historical data</returns>
 public IEnumerable <TradeBar> History(Symbol symbol, DateTime start, DateTime end, Resolution?resolution = null)
 {
     return(History(new[] { symbol }, start, end, resolution).Get(symbol));
 }
Пример #18
0
        /// <summary>
        /// Creates a new BollingerBands indicator which will compute the MiddleBand, UpperBand, LowerBand, and StandardDeviation
        /// </summary>
        /// <param name="symbol">The symbol whose BollingerBands we seek</param>
        /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
        /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param>
        /// <param name="movingAverageType">The type of moving average to be used</param>
        /// <param name="resolution">The resolution</param>
        /// <returns>A BollingerBands configured with the specied period</returns>
        public BollingerBands BB(string symbol, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple, Resolution?resolution = null)
        {
            var name = CreateIndicatorName(symbol, string.Format("BB({0},{1})", period, k), resolution);
            var bb   = new BollingerBands(name, period, k, movingAverageType);

            RegisterIndicator(symbol, bb, resolution, x => x.Value);
            return(bb);
        }
Пример #19
0
 /// <summary>
 /// Gets the historical data for the specified symbols over the requested span.
 /// The symbol's configured values for resolution and fill forward behavior will be used
 /// The symbols must exist in the Securities collection.
 /// </summary>
 /// <param name="symbols">The symbols to retrieve historical data for</param>
 /// <param name="span">The span over which to retrieve recent historical data</param>
 /// <param name="resolution">The resolution to request</param>
 /// <returns>An enumerable of slice containing the requested historical data</returns>
 public IEnumerable <Slice> History(IEnumerable <Symbol> symbols, TimeSpan span, Resolution?resolution = null)
 {
     return(History(symbols, Time - span, Time, resolution));
 }
Пример #20
0
 /// <summary>
 /// Registers the consolidator to receive automatic updates as well as configures the indicator to receive updates
 /// from the consolidator.
 /// </summary>
 /// <param name="symbol">The symbol to register against</param>
 /// <param name="indicator">The indicator to receive data from the consolidator</param>
 /// <param name="resolution">The resolution at which to send data to the indicator, null to use the same resolution as the subscription</param>
 public void RegisterIndicator <T>(string symbol, IndicatorBase <T> indicator, Resolution?resolution = null)
     where T : BaseData
 {
     RegisterIndicator(symbol, indicator, ResolveConsolidator(symbol, resolution));
 }
Пример #21
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="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 <Slice> History(IEnumerable <Symbol> symbols, int periods, Resolution?resolution = null)
 {
     if (resolution == Resolution.Tick)
     {
         throw new ArgumentException("History functions that accept a 'periods' parameter can not be used with Resolution.Tick");
     }
     return(History(CreateBarCountHistoryRequests(symbols, periods, resolution)));
 }
Пример #22
0
 /// <summary>
 /// Creates and adds a new single <see cref="Option"/> contract to the algorithm
 /// </summary>
 /// <param name="symbol">The option contract symbol</param>
 /// <param name="resolution">The <see cref="Resolution"/> of market data, Tick, Second, Minute, Hour, or Daily. Default is <see cref="Resolution.Minute"/></param>
 /// <param name="fillDataForward">If true, returns the last available data even if none in that timeslice. Default is <value>true</value></param>
 /// <param name="leverage">The requested leverage for this equity. Default is set by <see cref="SecurityInitializer"/></param>
 /// <returns>The new <see cref="Option"/> security</returns>
 public Option AddOptionContract(Symbol symbol, Resolution?resolution = null, bool fillDataForward = true, decimal leverage = 0m)
 => _baseAlgorithm.AddOptionContract(symbol, resolution, fillDataForward, leverage);
Пример #23
0
 /// <summary>
 /// Gets the historical data for the specified symbols between the specified dates. The symbols must exist in the Securities collection.
 /// </summary>
 /// <param name="symbols">The symbols to retrieve historical data for</param>
 /// <param name="start">The start time in the algorithm's time zone</param>
 /// <param name="end">The end time in the algorithm's time zone</param>
 /// <param name="resolution">The resolution to request</param>
 /// <param name="fillForward">True to fill forward missing data, false otherwise</param>
 /// <param name="extendedMarket">True to include extended market hours data, false otherwise</param>
 /// <returns>An enumerable of slice containing the requested historical data</returns>
 public IEnumerable <Slice> History(IEnumerable <Symbol> symbols, DateTime start, DateTime end, Resolution?resolution = null, bool?fillForward = null, bool?extendedMarket = null)
 {
     return(History(CreateDateRangeHistoryRequests(symbols, start, end, resolution, fillForward, extendedMarket)));
 }
Пример #24
0
 public Equity AddEquity(string ticker, Resolution?resolution = null, string market = null, bool fillDataForward = true, decimal leverage = Security.NullLeverage, bool extendedMarketHours = false)
 {
     return(Algo.AddEquity(ticker, resolution, market, fillDataForward, leverage, extendedMarketHours));
 }
Пример #25
0
        /// <summary>
        /// Helper method to create history requests from a date range
        /// </summary>
        private IEnumerable <HistoryRequest> CreateDateRangeHistoryRequests(IEnumerable <Symbol> symbols, DateTime startAlgoTz, DateTime endAlgoTz, Resolution?resolution = null, bool?fillForward = null, bool?extendedMarket = null)
        {
            return(symbols.Select(x =>
            {
                var security = Securities[x];
                var request = CreateHistoryRequest(security, startAlgoTz, endAlgoTz, resolution);

                // apply overrides
                Resolution?res = resolution ?? security.Resolution;
                if (fillForward.HasValue)
                {
                    request.FillForwardResolution = fillForward.Value ? res : null;
                }
                if (extendedMarket.HasValue)
                {
                    request.IncludeExtendedMarketHours = extendedMarket.Value;
                }
                return request;
            }));
        }
Пример #26
0
 public Option AddOptionContract(Symbol symbol, Resolution?resolution = null, bool fillDataForward = true, decimal leverage = 0)
 {
     return(Algo.AddOptionContract(symbol, resolution, fillDataForward, leverage));
 }
Пример #27
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);
         return CreateHistoryRequest(security, start, Time.RoundDown(res.Value.ToTimeSpan()), resolution);
     }));
 }
Пример #28
0
        /// <summary>
        /// Creates a MACD indicator for the symbol. The indicator will be automatically updated on the given resolution.
        /// </summary>
        /// <param name="symbol">The symbol whose MACD we want</param>
        /// <param name="fastPeriod">The period for the fast moving average</param>
        /// <param name="slowPeriod">The period for the slow moving average</param>
        /// <param name="signalPeriod">The period for the signal moving average</param>
        /// <param name="type">The type of moving average to use for the MACD</param>
        /// <param name="resolution">The resolution</param>
        /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to the Value property of BaseData (x => x.Value)</param>
        /// <returns>The moving average convergence divergence between the fast and slow averages</returns>
        public MovingAverageConvergenceDivergence MACD(string symbol, int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = MovingAverageType.Simple, Resolution?resolution = null, Func <BaseData, decimal> selector = null)
        {
            var name = CreateIndicatorName(symbol, string.Format("MACD({0},{1})", fastPeriod, slowPeriod), resolution);
            var macd = new MovingAverageConvergenceDivergence(name, fastPeriod, slowPeriod, signalPeriod, type);

            RegisterIndicator(symbol, macd, resolution, selector);
            return(macd);
        }
Пример #29
0
        private HistoryRequest CreateHistoryRequest(Security security, DateTime startAlgoTz, DateTime endAlgoTz, Resolution?resolution)
        {
            resolution = resolution ?? security.Resolution;
            var request = new HistoryRequest(security, startAlgoTz.ConvertToUtc(TimeZone), endAlgoTz.ConvertToUtc(TimeZone))
            {
                Resolution            = resolution.Value,
                FillForwardResolution = security.IsFillDataForward ? resolution : null
            };

            return(request);
        }
Пример #30
0
        /// <summary>
        /// Creates and adds a list of <see cref="SubscriptionDataConfig" /> for a given symbol and configuration.
        /// Can optionally pass in desired subscription data types to use.
        ///  If the config already existed will return existing instance instead
        /// </summary>
        public List <SubscriptionDataConfig> Add(
            Symbol symbol,
            Resolution?resolution       = null,
            bool fillForward            = true,
            bool extendedMarketHours    = false,
            bool isFilteredSubscription = true,
            bool isInternalFeed         = false,
            bool isCustomData           = false,
            List <Tuple <Type, TickType> > subscriptionDataTypes = null,
            DataNormalizationMode dataNormalizationMode          = DataNormalizationMode.Adjusted
            )
        {
            var dataTypes = subscriptionDataTypes ??
                            LookupSubscriptionConfigDataTypes(symbol.SecurityType, resolution ?? Resolution.Minute, symbol.IsCanonical());

            if (!dataTypes.Any())
            {
                throw new ArgumentNullException(nameof(dataTypes), "At least one type needed to create new subscriptions");
            }

            var resolutionWasProvided = resolution.HasValue;

            foreach (var typeTuple in dataTypes)
            {
                var baseInstance = typeTuple.Item1.GetBaseDataInstance();
                baseInstance.Symbol = symbol;
                if (!resolutionWasProvided)
                {
                    var defaultResolution = baseInstance.DefaultResolution();
                    if (resolution.HasValue && resolution != defaultResolution)
                    {
                        // we are here because there are multiple 'dataTypes'.
                        // if we get different default resolutions lets throw, this shouldn't happen
                        throw new InvalidOperationException(
                                  $"Different data types ({string.Join(",", dataTypes.Select(tuple => tuple.Item1))})" +
                                  $" provided different default resolutions {defaultResolution} and {resolution}, this is an unexpected invalid operation.");
                    }
                    resolution = defaultResolution;
                }
                else
                {
                    // only assert resolution in backtesting, live can use other data source
                    // for example daily data for options
                    if (!_liveMode)
                    {
                        var supportedResolutions = baseInstance.SupportedResolutions();
                        if (supportedResolutions.Contains(resolution.Value))
                        {
                            continue;
                        }

                        throw new ArgumentException($"Sorry {resolution.ToStringInvariant()} is not a supported resolution for {typeTuple.Item1.Name}" +
                                                    $" and SecurityType.{symbol.SecurityType.ToStringInvariant()}." +
                                                    $" Please change your AddData to use one of the supported resolutions ({string.Join(",", supportedResolutions)}).");
                    }
                }
            }

            var marketHoursDbEntry = _marketHoursDatabase.GetEntry(symbol.ID.Market, symbol, symbol.ID.SecurityType);
            var exchangeHours      = marketHoursDbEntry.ExchangeHours;

            if (symbol.ID.SecurityType == SecurityType.Option || symbol.ID.SecurityType == SecurityType.Future)
            {
                dataNormalizationMode = DataNormalizationMode.Raw;
            }

            if (marketHoursDbEntry.DataTimeZone == null)
            {
                throw new ArgumentNullException(nameof(marketHoursDbEntry.DataTimeZone),
                                                "DataTimeZone is a required parameter for new subscriptions. Set to the time zone the raw data is time stamped in.");
            }

            if (exchangeHours.TimeZone == null)
            {
                throw new ArgumentNullException(nameof(exchangeHours.TimeZone),
                                                "ExchangeTimeZone is a required parameter for new subscriptions. Set to the time zone the security exchange resides in.");
            }

            var result = (from subscriptionDataType in dataTypes
                          let dataType = subscriptionDataType.Item1
                                         let tickType = subscriptionDataType.Item2
                                                        select new SubscriptionDataConfig(
                              dataType,
                              symbol,
                              resolution.Value,
                              marketHoursDbEntry.DataTimeZone,
                              exchangeHours.TimeZone,
                              fillForward,
                              extendedMarketHours,
                              isInternalFeed,
                              isCustomData,
                              isFilteredSubscription: isFilteredSubscription,
                              tickType: tickType,
                              dataNormalizationMode: dataNormalizationMode)).ToList();

            for (int i = 0; i < result.Count; i++)
            {
                result[i] = SubscriptionManagerGetOrAdd(result[i]);

                // track all registered data types
                _registeredTypesProvider.RegisterType(result[i].Type);
            }
            return(result);
        }
Пример #31
0
 /// <summary>
 /// Get the history for all configured securities over the requested span.
 /// This will use the resolution and other subscription settings for each security.
 /// The symbols must exist in the Securities collection.
 /// </summary>
 /// <param name="periods">The number of bars to request</param>
 /// <param name="resolution">The resolution to request</param>
 /// <returns>An enumerable of slice containing data over the most recent span for all configured securities</returns>
 public IEnumerable <Slice> History(int periods, Resolution?resolution = null)
 {
     return(History(Securities.Keys, periods, resolution));
 }