From a7fb15e5038a629d6ef2478e8154fee33c5cc500 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Mon, 25 Dec 2023 22:28:20 +0900 Subject: [PATCH] fix next-market-open for fx (#47) --- pythclient/calendar.py | 4 +++- setup.py | 2 +- tests/test_calendar.py | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pythclient/calendar.py b/pythclient/calendar.py index ec4eb66..63be202 100644 --- a/pythclient/calendar.py +++ b/pythclient/calendar.py @@ -134,7 +134,9 @@ def get_next_market_open(asset_type: str, dt: datetime.datetime) -> int: ) next_market_open += datetime.timedelta(days=1) elif asset_type in ["fx", "metal"]: - if dt.weekday() == 6 and time < FX_METAL_OPEN_CLOSE_TIME: + if (dt.weekday() == 6 and time < FX_METAL_OPEN_CLOSE_TIME) or ( + dt.date() in FX_METAL_HOLIDAYS and time < FX_METAL_OPEN_CLOSE_TIME + ): next_market_open = dt.replace( hour=FX_METAL_OPEN_CLOSE_TIME.hour, minute=FX_METAL_OPEN_CLOSE_TIME.minute, diff --git a/setup.py b/setup.py index 5ad57fc..51e0a81 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='pythclient', - version='0.1.18', + version='0.1.19', packages=['pythclient'], author='Pyth Developers', author_email='contact@pyth.network', diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 11603dd..e149975 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -175,7 +175,7 @@ def test_get_next_market_open(): == format_datetime_to_unix_timestamp(datetime.datetime(2023, 6, 18, 17, 0, 0, tzinfo=NY_TZ)) ) - # fx & metal out of market hours on Sunday Dec 24 2024 after 10pm UTC + # fx & metal out of market hours on Sunday Dec 24 2023 after 5pm ET assert ( get_next_market_open("fx", FX_METAL_HOLIDAY_SUN_2023_12_24_17) == format_datetime_to_unix_timestamp(datetime.datetime(2023, 12, 25, 17, 0, 0, tzinfo=NY_TZ)) @@ -185,6 +185,12 @@ def test_get_next_market_open(): == format_datetime_to_unix_timestamp(datetime.datetime(2023, 12, 25, 17, 0, 0, tzinfo=NY_TZ)) ) + # fx & metal out of market hours on holiday Dec 25 2023 before 5pm ET + assert ( + get_next_market_open("fx", datetime.datetime(2023, 12, 25, 8, 15, 0, tzinfo=NY_TZ)) + == format_datetime_to_unix_timestamp(datetime.datetime(2023, 12, 25, 17, 0, 0, tzinfo=NY_TZ)) + ) + # fx & metal holiday assert ( get_next_market_open("fx", FX_METAL_HOLIDAY_SUN_2023_1_1)