import json
from datetime import datetime, timezone

def iso_to_ts(iso_str):
    return datetime.fromisoformat(iso_str.replace('Z', '+00:00')).timestamp()

def get_bars(file, start_ts, end_ts):
    with open(file) as f:
        data = json.load(f)
    if 'bars' in data:
        bars = data['bars']
    else:
        bars = data
    return [b for b in bars if start_ts <= iso_to_ts(b['time']) <= end_ts]

start_ts = iso_to_ts("2026-06-05T00:00:00Z")
end_ts = iso_to_ts("2026-06-10T00:00:00Z")
h4_bars = get_bars("hybrid/data/ohlcv_H4.json", start_ts, end_ts)
for b in h4_bars:
    print(f"H4 {b['time']}: O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")
