import json

def get_bars(file_path, start_time_str, end_time_str=None):
    with open(file_path, 'r') as f:
        data = json.load(f)
    
    bars_data = data.get("bars", [])
        
    if end_time_str:
        return [b for b in bars_data if str(b['time']) >= start_time_str and str(b['time']) <= end_time_str]
    else:
        bars = [b for b in bars_data if str(b['time']) <= start_time_str]
        return bars[-10:] if len(bars) > 0 else []

data_dir = "/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/"
htf = get_bars(data_dir + "ohlcv_H4.json", "2026-04-29T11:00:00Z")
m30 = get_bars(data_dir + "ohlcv_M30.json", "2026-04-29T11:00:00Z")

print("H4 context leading to 11:00:")
for b in htf: print(b['time'], b['open'], b['high'], b['low'], b['close'])

print("\nM30 context leading to 11:00:")
for b in m30: print(b['time'], b['open'], b['high'], b['low'], b['close'])

print("\nM5 Execution Data (11:00 to 14:00):")
m5_exec = get_bars(data_dir + "ohlcv_M5.json", "2026-04-29T11:00:00Z", "2026-04-29T14:00:00Z")
for b in m5_exec: print(b['time'], b['open'], b['high'], b['low'], b['close'])

print("\nM15 Execution Data (11:00 to 14:00):")
m15_exec = get_bars(data_dir + "ohlcv_M15.json", "2026-04-29T11:00:00Z", "2026-04-29T14:00:00Z")
for b in m15_exec: print(b['time'], b['open'], b['high'], b['low'], b['close'])

