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]

def summarize(bars):
    if not bars: return "No data"
    o = bars[0]['open']
    h = max(b['high'] for b in bars)
    l = min(b['low'] for b in bars)
    c = bars[-1]['close']
    return f"O:{o:.2f} H:{h:.2f} L:{l:.2f} C:{c:.2f} (from {bars[0]['time']} to {bars[-1]['time']})"

start_ts = iso_to_ts("2026-06-03T00:00:00Z")
end_ts = iso_to_ts("2026-06-11T00:00:00Z")

print("HTF (H4):")
print(summarize(get_bars("hybrid/data/ohlcv_H4.json", start_ts, end_ts)))

c1_start = iso_to_ts("2026-06-08T22:30:00Z")
c1_end = iso_to_ts("2026-06-09T03:30:00Z")
print("\nC624 Long (2026-06-09T00:30): M15 context")
print(summarize(get_bars("hybrid/data/ohlcv_M15.json", c1_start, c1_end)))

c2_start = iso_to_ts("2026-06-09T01:15:00Z")
c2_end = iso_to_ts("2026-06-09T06:15:00Z")
print("\nC625 Short (2026-06-09T03:15): M15 context")
print(summarize(get_bars("hybrid/data/ohlcv_M15.json", c2_start, c2_end)))

c3_start = iso_to_ts("2026-06-09T03:15:00Z")
c3_end = iso_to_ts("2026-06-09T08:15:00Z")
print("\nC626 Long (2026-06-09T05:15): M15 context")
print(summarize(get_bars("hybrid/data/ohlcv_M15.json", c3_start, c3_end)))
