TimeRules
QuantConnect.Scheduling.TimeRules
TimeRules(
algorithm: IAlgorithm,
securities: SecurityManager,
time_zone: Any,
market_hours_database: MarketHoursDatabase,
)
Bases: BaseScheduleRules
Helper class used to provide better syntax when defining time rules
Initializes a new instance of the TimeRules helper class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
IAlgorithm
|
The algorithm instance |
required |
securities
|
SecurityManager
|
The security manager |
required |
time_zone
|
Any
|
The algorithm's default time zone |
required |
market_hours_database
|
MarketHoursDatabase
|
The market hours database instance to use |
required |
midnight
midnight: ITimeRule
Convenience property for running a scheduled event at midnight in the algorithm time zone
noon
noon: ITimeRule
Convenience property for running a scheduled event at noon in the algorithm time zone
time_zone
time_zone: Any
The algorithm's default time zone
This codeEntityType is protected.
market_hours_database
market_hours_database: MarketHoursDatabase
The market hours database instance to use
This codeEntityType is protected.
after_market_close
after_market_close(
symbol: str,
minutes_after_close: float = 0,
extended_market_close: bool = False,
) -> ITimeRule
after_market_close(
symbol: Union[Symbol, str, BaseContract],
minutes_after_close: float = 0,
extended_market_close: bool = False,
) -> ITimeRule
Specifies an event should fire at the market close +- minutes_after_close
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | Union[Symbol, str, BaseContract]
|
The symbol whose market close we want an event for |
required |
minutes_after_close
|
float
|
The time after market close that the event should fire |
0
|
extended_market_close
|
bool
|
True to use extended market close, false to use regular market close |
False
|
Returns:
| Type | Description |
|---|---|
ITimeRule
|
A time rule that fires the specified number of minutes after the symbol's market close. |
after_market_open
after_market_open(
symbol: str,
minutes_after_open: float = 0,
extended_market_open: bool = False,
) -> ITimeRule
after_market_open(
symbol: Union[Symbol, str, BaseContract],
minutes_after_open: float = 0,
extended_market_open: bool = False,
) -> ITimeRule
Specifies an event should fire at market open +- minutes_after_open
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | Union[Symbol, str, BaseContract]
|
The symbol whose market open we want an event for |
required |
minutes_after_open
|
float
|
The minutes after market open that the event should fire |
0
|
extended_market_open
|
bool
|
True to use extended market open, false to use regular market open |
False
|
Returns:
| Type | Description |
|---|---|
ITimeRule
|
A time rule that fires the specified number of minutes after the symbol's market open. |
at
at(hour: int, minute: int, time_zone: Any) -> ITimeRule
at(
hour: int, minute: int, second: int, time_zone: Any
) -> ITimeRule
at(time_of_day: timedelta, time_zone: Any) -> ITimeRule
at(time_of_day: timedelta) -> ITimeRule
at(hour: int, minute: int, second: int = 0) -> ITimeRule
Signature descriptions:
-
Specifies an event should fire at the specified time of day in the specified time zone
-
Specifies an event should fire at the specified time of day in the algorithm's time zone
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hour
|
Optional[int]
|
The hour |
None
|
minute
|
Optional[int]
|
The minute |
None
|
time_zone
|
Optional[Any]
|
The time zone the event time is represented in |
None
|
second
|
Optional[int]
|
The second |
0
|
time_of_day
|
Optional[timedelta]
|
The time of day in the algorithm's time zone the event should fire |
None
|
Returns:
| Type | Description |
|---|---|
ITimeRule
|
A time rule that fires at the specified time in the algorithm's time zone. |
before_market_close
before_market_close(
symbol: str,
minutes_before_close: float = 0,
extended_market_close: bool = False,
) -> ITimeRule
before_market_close(
symbol: Union[Symbol, str, BaseContract],
minutes_before_close: float = 0,
extended_market_close: bool = False,
) -> ITimeRule
Specifies an event should fire at the market close +- minutes_before_close
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | Union[Symbol, str, BaseContract]
|
The symbol whose market close we want an event for |
required |
minutes_before_close
|
float
|
The time before market close that the event should fire |
0
|
extended_market_close
|
bool
|
True to use extended market close, false to use regular market close |
False
|
Returns:
| Type | Description |
|---|---|
ITimeRule
|
A time rule that fires the specified number of minutes before the symbol's market close. |
before_market_open
before_market_open(
symbol: str,
minutes_before_open: float = 0,
extended_market_open: bool = False,
) -> ITimeRule
before_market_open(
symbol: Union[Symbol, str, BaseContract],
minutes_before_open: float = 0,
extended_market_open: bool = False,
) -> ITimeRule
Specifies an event should fire at market open +- minutes_before_open
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | Union[Symbol, str, BaseContract]
|
The symbol whose market open we want an event for |
required |
minutes_before_open
|
float
|
The minutes before market open that the event should fire |
0
|
extended_market_open
|
bool
|
True to use extended market open, false to use regular market open |
False
|
Returns:
| Type | Description |
|---|---|
ITimeRule
|
A time rule that fires the specified number of minutes before the symbol's market open. |
every
every(interval: timedelta) -> ITimeRule
Specifies an event should fire periodically on the requested interval
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
timedelta
|
The frequency with which the event should fire, can not be zero or less |
required |
Returns:
| Type | Description |
|---|---|
ITimeRule
|
A time rule that fires after each interval passes. |
set_default_time_zone
set_default_time_zone(time_zone: Any) -> None
Sets the default time zone
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_zone
|
Any
|
The time zone to use for helper methods that can't resolve a time zone |
required |
get_security_exchange_hours
get_security_exchange_hours(
symbol: Union[Symbol, str, BaseContract],
) -> SecurityExchangeHours
Helper method to fetch the security exchange hours
This codeEntityType is protected.