import json

with open('hybrid/data/ohlcv_M15.json', 'r') as f:
    m15 = json.load(f)['bars']

with open('hybrid/data/ohlcv_H4.json', 'r') as f:
    h4 = json.load(f)['bars']

with open('hybrid/data/ohlcv_M30.json', 'r') as f:
    m30 = json.load(f)['bars']

for t in ["2026-04-07T11:45:00Z", "2026-04-07T13:15:00Z", "2026-04-07T13:30:00Z"]:
    print(f"\n=================== {t} ===================")
    
    # H4 context around target
    print("--- H4 Context ---")
    for c in h4:
        if c['time'] >= "2026-04-06T00:00:00Z" and c['time'] <= "2026-04-07T16:00:00Z":
            print(f"H4 {c['time']} O:{c['open']} H:{c['high']} L:{c['low']} C:{c['close']}")

    # M30 context
    print("--- M30 Context ---")
    for c in m30:
        if c['time'] >= "2026-04-07T08:00:00Z" and c['time'] <= "2026-04-07T15:00:00Z":
            mark = "*" if c['time'] == t else " "
            print(f"{mark} M30 {c['time']} O:{c['open']} H:{c['high']} L:{c['low']} C:{c['close']}")

    # M15 context around target
    print("--- M15 Context ---")
    idx = -1
    for i, candle in enumerate(m15):
        if candle['time'] == t:
            idx = i
            break
    if idx != -1:
        for i in range(max(0, idx-6), min(len(m15), idx+6)):
            c = m15[i]
            mark = "*" if i == idx else " "
            print(f"{mark} M15 {c['time']} O:{c['open']} H:{c['high']} L:{c['low']} C:{c['close']}")
    else:
        print("M15 candle exact match not found")
