Skip to content

HistoryRequestFactory

QuantConnect.Data.HistoryRequestFactory

HistoryRequestFactory(algorithm: IAlgorithm)

Bases: Object

Helper class used to create new HistoryRequest

Creates a new instance

Parameters:

Name Type Description Default
algorithm IAlgorithm

The algorithm instance to use

required

get_start_time_algo_tz

get_start_time_algo_tz(
    symbol: Union[Symbol, str, BaseContract],
    periods: int,
    resolution: Resolution,
    exchange: SecurityExchangeHours,
    data_time_zone: Any,
    data_type: Type,
    extended_market_hours: Optional[bool] = None,
) -> datetime
get_start_time_algo_tz(
    reference_utc_time: Union[datetime, date],
    symbol: Union[Symbol, str, BaseContract],
    periods: int,
    resolution: Resolution,
    exchange: SecurityExchangeHours,
    data_time_zone: Any,
    data_type: Type,
    extended_market_hours: Optional[bool] = None,
) -> datetime

Gets the start time required for the specified bar count in terms of the algorithm's time zone

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol to select proper SubscriptionDataConfig config

required
periods int

The number of bars requested

required
resolution Resolution

The length of each bar

required
exchange SecurityExchangeHours

The exchange hours used for market open hours

required
data_time_zone Any

The time zone in which data are stored

required
data_type Type

The data type to request

required
extended_market_hours Optional[bool]

True to include extended market hours data, false otherwise.

None
reference_utc_time Optional[Union[datetime, date]]

The end time in utc

None

Returns:

Type Description
datetime

The start time that would provide the specified number of bars ending at the algorithm's current time.

create_history_request

create_history_request(
    subscription: SubscriptionDataConfig,
    start_algo_tz: Union[datetime, date],
    end_algo_tz: Union[datetime, date],
    exchange_hours: SecurityExchangeHours,
    resolution: Optional[Resolution],
    fill_forward: Optional[bool] = None,
    extended_market_hours: Optional[bool] = None,
    data_mapping_mode: Optional[DataMappingMode] = None,
    data_normalization_mode: Optional[
        DataNormalizationMode
    ] = None,
    contract_depth_offset: Optional[int] = None,
) -> HistoryRequest

Creates a new history request

Parameters:

Name Type Description Default
subscription SubscriptionDataConfig

The config

required
start_algo_tz Union[datetime, date]

History request start time in algorithm time zone

required
end_algo_tz Union[datetime, date]

History request end time in algorithm time zone

required
exchange_hours SecurityExchangeHours

Security exchange hours

required
resolution Optional[Resolution]

The resolution to use. If null will use SubscriptionDataConfig.resolution

required
fill_forward Optional[bool]

True to fill forward missing data, false otherwise

None
extended_market_hours Optional[bool]

True to include extended market hours data, false otherwise

None
data_mapping_mode Optional[DataMappingMode]

The contract mapping mode to use for the security history request

None
data_normalization_mode Optional[DataNormalizationMode]

The price scaling mode to use for the securities history

None
contract_depth_offset Optional[int]

The continuous contract desired offset from the current front month. For example, 0 will use the front month, 1 will use the back month contract

None

Returns:

Type Description
HistoryRequest

The new HistoryRequest.