public void LeanData_CanDetermineTheCorrectCommonDataTypes() { Assert.IsTrue(LeanData.IsCommonLeanDataType(typeof(OpenInterest))); Assert.IsTrue(LeanData.IsCommonLeanDataType(typeof(TradeBar))); Assert.IsTrue(LeanData.IsCommonLeanDataType(typeof(QuoteBar))); Assert.IsFalse(LeanData.IsCommonLeanDataType(typeof(Bitcoin))); }
/// <summary> /// Creates a new history request /// </summary> /// <param name="subscription">The config </param> /// <param name="startAlgoTz">History request start time in algorithm time zone</param> /// <param name="endAlgoTz">History request end time in algorithm time zone</param> /// <param name="exchangeHours">Security exchange hours</param> /// <param name="resolution">The resolution to use. If null will use <see cref="SubscriptionDataConfig.Resolution"/></param> /// <returns>The new <see cref="HistoryRequest"/></returns> public HistoryRequest CreateHistoryRequest(SubscriptionDataConfig subscription, DateTime startAlgoTz, DateTime endAlgoTz, SecurityExchangeHours exchangeHours, Resolution?resolution) { resolution ??= subscription.Resolution; var dataType = subscription.Type; // if we change resolution the data type can change, for example subscription being Tick type and resolution daily // data type here won't be Tick anymore, but TradeBar/QuoteBar if (resolution.Value != subscription.Resolution && LeanData.IsCommonLeanDataType(dataType)) { dataType = LeanData.GetDataType(resolution.Value, subscription.TickType); } var request = new HistoryRequest(subscription, exchangeHours, startAlgoTz.ConvertToUtc(_algorithm.TimeZone), endAlgoTz.ConvertToUtc(_algorithm.TimeZone)) { DataType = dataType, Resolution = resolution.Value, FillForwardResolution = subscription.FillDataForward ? resolution : null, TickType = subscription.TickType }; return(request); }
/// <summary> /// Checks if the subscription is valid for the consolidator /// </summary> /// <param name="subscription">The subscription configuration</param> /// <param name="consolidator">The consolidator</param> /// <returns>true if the subscription is valid for the consolidator</returns> public static bool IsSubscriptionValidForConsolidator(SubscriptionDataConfig subscription, IDataConsolidator consolidator) { if (subscription.Type == typeof(Tick) && LeanData.IsCommonLeanDataType(consolidator.OutputType)) { var tickType = LeanData.GetCommonTickTypeForCommonDataTypes( consolidator.OutputType, subscription.Symbol.SecurityType); return(subscription.TickType == tickType); } return(consolidator.InputType.IsAssignableFrom(subscription.Type)); }
/// <summary> /// Will determine if price scaling should be used for this subscription configuration /// </summary> /// <param name="config">The subscription data configuration we are processing</param> /// <remarks>One of the objectives of this method is to normalize the 'use price scale' /// check and void code duplication and related issues</remarks> /// <param name="liveMode">True, is this is a live mode data stream</param> /// <returns>True if ticker prices should be scaled</returns> public static bool PricesShouldBeScaled(this SubscriptionDataConfig config, bool liveMode = false) { if (config.IsCustomData || config.Symbol.Value.Contains("UNIVERSE")) { return(false); } if (config.SecurityType == SecurityType.Equity && !liveMode) { return(true); } if (config.SecurityType == SecurityType.Future && config.Symbol.IsCanonical()) { return(LeanData.IsCommonLeanDataType(config.Type)); } return(false); }