47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""
|
|
Helper functions for the trading GNN project.
|
|
"""
|
|
|
|
from datetime import datetime, timedelta
|
|
from typing import List
|
|
|
|
from config import config
|
|
|
|
|
|
def generate_intraday_timestamps(date: str) -> List[str]:
|
|
"""
|
|
Generate all intraday timestamps for a given trading date.
|
|
|
|
Parameters:
|
|
date: Trading date string (YYYY-MM-DD).
|
|
|
|
Returns:
|
|
List of timestamp strings for the trading day.
|
|
"""
|
|
market_open = datetime.strptime(config.TRADING_HOURS["start"], "%H:%M").time()
|
|
market_close = datetime.strptime(config.TRADING_HOURS["end"], "%H:%M").time()
|
|
|
|
open_dt = datetime.strptime(f"{date} {market_open}", "%Y-%m-%d %H:%M:%S")
|
|
close_dt = datetime.strptime(f"{date} {market_close}", "%Y-%m-%d %H:%M:%S")
|
|
|
|
if config.TRADING_FREQUENCY == "1min":
|
|
delta = timedelta(minutes=1)
|
|
elif config.TRADING_FREQUENCY == "5min":
|
|
delta = timedelta(minutes=5)
|
|
elif config.TRADING_FREQUENCY == "15min":
|
|
delta = timedelta(minutes=15)
|
|
elif config.TRADING_FREQUENCY == "30min":
|
|
delta = timedelta(minutes=30)
|
|
elif config.TRADING_FREQUENCY == "1h":
|
|
delta = timedelta(hours=1)
|
|
else:
|
|
delta = timedelta(minutes=1)
|
|
|
|
timestamps = []
|
|
current = open_dt
|
|
while current <= close_dt:
|
|
timestamps.append(current.strftime("%Y-%m-%d %H:%M:%S"))
|
|
current += delta
|
|
|
|
return timestamps
|