import json

def get_bars(file_path, start_time, count=10):
    try:
        with open(file_path) as f:
            data = json.load(f)
            
        bars = data.get('bars', [])
            
        for i, bar in enumerate(bars):
            if bar['time'] >= start_time:
                # get some bars before and after
                start_idx = max(0, i - count)
                end_idx = min(len(bars), i + count)
                return bars[start_idx:end_idx]
    except Exception as e:
        print(f"Error loading {file_path}: {e}")
    return []

times = [
    "2026-06-16T11:15:00Z",
    "2026-06-16T11:30:00Z", 
    "2026-06-16T15:45:00Z"
]

print("HTF Data (H4) around 2026-06-16:")
h4_bars = get_bars('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_H4.json', "2026-06-14T00:00:00Z", 15)
for b in h4_bars:
    print(f"{b['time']} O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")
    
print("\nH1 Data around 2026-06-16:")
h1_bars = get_bars('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_H1.json', "2026-06-16T04:00:00Z", 12)
for b in h1_bars:
    print(f"{b['time']} O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")

for t in times:
    print(f"\nM15 Data for {t}:")
    m15_bars = get_bars('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_M15.json', t, 6)
    for b in m15_bars:
        prefix = "-> " if b['time'] == t else "   "
        print(f"{prefix}{b['time']} O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")
