From d6571704433f044dfa6881e7b76f629f6e194482 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Sat, 11 Nov 2023 19:52:46 +0900 Subject: [PATCH] fix fx/metal get_next_market_close (#44) * fix fx/metal get_next_market_close * bump --- pythclient/calendar.py | 9 +++++---- setup.py | 2 +- tests/test_calendar.py | 7 +++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pythclient/calendar.py b/pythclient/calendar.py index 9fbf7df..99f554f 100644 --- a/pythclient/calendar.py +++ b/pythclient/calendar.py @@ -229,10 +229,11 @@ def get_next_market_close(asset_type: str, dt: datetime.datetime) -> int: second=0, microsecond=0, ) - while not is_market_open(asset_type, next_market_close): - next_market_close += datetime.timedelta(days=1) - while is_market_open(asset_type, next_market_close): - next_market_close += datetime.timedelta(days=1) + if dt.weekday() != 4: + while not is_market_open(asset_type, next_market_close): + next_market_close += datetime.timedelta(days=1) + while is_market_open(asset_type, next_market_close): + next_market_close += datetime.timedelta(days=1) elif asset_type == "rates": if dt.date() in NYSE_EARLY_HOLIDAYS: if time < NYSE_EARLY_CLOSE: diff --git a/setup.py b/setup.py index 29350c8..04064a7 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='pythclient', - version='0.1.16', + version='0.1.17', packages=['pythclient'], author='Pyth Developers', author_email='contact@pyth.network', diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 413bbc0..d5757ae 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -284,6 +284,12 @@ def test_get_next_market_close(): == format_datetime_to_unix_timestamp(datetime.datetime(2023, 6, 23, 17, 0, 0, tzinfo=NY_TZ)) ) + # fx & metal within market hours on a friday (before 10pm UTC) + assert ( + get_next_market_close("fx", datetime.datetime(2023, 11, 10, 7, 0, 0, tzinfo=NY_TZ)) + == format_datetime_to_unix_timestamp(datetime.datetime(2023, 11, 10, 17, 0, 0, tzinfo=NY_TZ)) + ) + # fx & metal out of market hours assert ( get_next_market_close("fx", FX_METAL_CLOSE_SUN_2023_6_18_16) @@ -347,3 +353,4 @@ def test_get_next_market_close(): # crypto assert get_next_market_close("crypto", CRYPTO_OPEN_WED_2023_6_21_12) == None assert get_next_market_close("crypto", CRYPTO_OPEN_SUN_2023_6_18_12) == None +