turtle_quant_1.data_processing.datetimes¶
turtle_quant_1.data_processing.datetimes
¶
get_expected_market_hours_bounds
¶
get_expected_market_hours_bounds(
symbol: str, start_date: datetime, end_date: datetime
) -> tuple[datetime, datetime]
Get the expected market hours boundaries for a symbol between start and end dates.
TODO: Cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol |
required |
start_date
|
datetime
|
Timezone-aware start date |
required |
end_date
|
datetime
|
Timezone-aware end date |
required |
Returns:
| Type | Description |
|---|---|
tuple[datetime, datetime]
|
Tuple of timezone-aware datetime objects representing the start and end of the expected market hours |
Source code in src/turtle_quant_1/data_processing/datetimes.py
get_expected_market_hours_index
¶
get_expected_market_hours_index(
symbol: str, start_date: datetime, end_date: datetime
) -> List[datetime]
Generate a list of all expected market hours for a symbol between start and end dates.
TODO: Cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to get market hours for |
required |
start_date
|
datetime
|
Timezone-aware start date |
required |
end_date
|
datetime
|
Timezone-aware end date |
required |
Returns:
| Type | Description |
|---|---|
List[datetime]
|
List of timezone-aware datetime objects representing each expected market hour for this symbol |
Source code in src/turtle_quant_1/data_processing/datetimes.py
get_symbol_closing_time
¶
Get market close time for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol |
required |
Returns:
| Type | Description |
|---|---|
str
|
Close time string in "HH:MM" format (UTC) |
Source code in src/turtle_quant_1/data_processing/datetimes.py
get_symbol_market_hours
¶
Get market hours for a specific symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol (e.g., 'AAPL') |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with 'open', 'close', and 'timezone' keys |
Source code in src/turtle_quant_1/data_processing/datetimes.py
get_symbol_opening_time
¶
Get market open time for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol |
required |
Returns:
| Type | Description |
|---|---|
str
|
Open time string in "HH:MM" format (UTC) |
Source code in src/turtle_quant_1/data_processing/datetimes.py
get_symbol_timezone
¶
Get timezone for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol |
required |
Returns:
| Type | Description |
|---|---|
str
|
Timezone string |
is_holiday_date
¶
Check if a date is a bank holiday.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
datetime
|
Date to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if date is a bank holiday, False otherwise |
Source code in src/turtle_quant_1/data_processing/datetimes.py
is_weekend_date
¶
Check if a date is a weekend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
datetime
|
Date to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if date is a weekend, False otherwise |
is_within_market_hours
¶
Check if the given timestamp is within trading hours for the symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Symbol to check trading hours for. |
required |
timestamp
|
datetime
|
Timestamp to check. Timezone-aware. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if within trading hours (including 2-hour grace period after close), False otherwise. |