from datetime import datetime, timezone from app.services.macro.fetchers import ( _drop_in_progress_daily_klines, _latest_closed_daily_point, _parse_farside_latest_total, ) def test_drop_in_progress_daily_klines_removes_today_open_bar(): now = datetime(2026, 5, 25, 8, 0, tzinfo=timezone.utc) rows = [ [1779494400000, 0, 0, 0, "76715.20"], [1779580800000, 0, 0, 0, "77030.30"], [1779667200000, 0, 0, 0, "77404.80"], # 2026-05-25 00:00 UTC, still open ] filtered = _drop_in_progress_daily_klines(rows, now=now) assert [row[0] for row in filtered] == [1779494400000, 1779580800000] def test_latest_closed_daily_point_skips_today_point(): now = datetime(2026, 5, 25, 8, 0, tzinfo=timezone.utc) rows = [ {"timestamp": 1779494400000, "sumOpenInterestValue": "1"}, {"timestamp": 1779580800000, "sumOpenInterestValue": "2"}, {"timestamp": 1779667200000, "sumOpenInterestValue": "3"}, ] latest = _latest_closed_daily_point(rows, now=now) assert latest == rows[1] def test_parse_farside_latest_total_uses_newest_date_not_first_row(): html = """
| 11 Jan 2024 | 0.0 | 655.3 |
| 24 May 2026 | 0.0 | (12.5) |
| 25 May 2026 | 0.0 | 321.0 |