import json
from datetime import datetime, timezone

def iso_to_ts(iso_str):
    if isinstance(iso_str, int) or isinstance(iso_str, float):
        return 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]

print("C624 Long (2026-06-09T00:30) M5")
c1_start = iso_to_ts("2026-06-08T23:30:00Z")
c1_end = iso_to_ts("2026-06-09T01:30:00Z")
for b in get_bars("hybrid/data/ohlcv_M5.json", c1_start, c1_end):
    ts = iso_to_ts(b['time'])
    print(f"M5 {datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()}: O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")

print("\nC625 Short (2026-06-09T03:15) M5")
c2_start = iso_to_ts("2026-06-09T02:15:00Z")
c2_end = iso_to_ts("2026-06-09T04:15:00Z")
for b in get_bars("hybrid/data/ohlcv_M5.json", c2_start, c2_end):
    ts = iso_to_ts(b['time'])
    print(f"M5 {datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()}: O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")

print("\nC626 Long (2026-06-09T05:15) M5")
c3_start = iso_to_ts("2026-06-09T04:15:00Z")
c3_end = iso_to_ts("2026-06-09T06:15:00Z")
for b in get_bars("hybrid/data/ohlcv_M5.json", c3_start, c3_end):
    ts = iso_to_ts(b['time'])
    print(f"M5 {datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()}: O:{b['open']} H:{b['high']} L:{b['low']} C:{b['close']}")
