Skip to content

Commit d657170

Browse files
authored
fix fx/metal get_next_market_close (#44)
* fix fx/metal get_next_market_close * bump
1 parent fd7f08b commit d657170

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pythclient/calendar.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ def get_next_market_close(asset_type: str, dt: datetime.datetime) -> int:
229229
second=0,
230230
microsecond=0,
231231
)
232-
while not is_market_open(asset_type, next_market_close):
233-
next_market_close += datetime.timedelta(days=1)
234-
while is_market_open(asset_type, next_market_close):
235-
next_market_close += datetime.timedelta(days=1)
232+
if dt.weekday() != 4:
233+
while not is_market_open(asset_type, next_market_close):
234+
next_market_close += datetime.timedelta(days=1)
235+
while is_market_open(asset_type, next_market_close):
236+
next_market_close += datetime.timedelta(days=1)
236237
elif asset_type == "rates":
237238
if dt.date() in NYSE_EARLY_HOLIDAYS:
238239
if time < NYSE_EARLY_CLOSE:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='pythclient',
10-
version='0.1.16',
10+
version='0.1.17',
1111
packages=['pythclient'],
1212
author='Pyth Developers',
1313
author_email='[email protected]',

tests/test_calendar.py

+7
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ def test_get_next_market_close():
284284
== format_datetime_to_unix_timestamp(datetime.datetime(2023, 6, 23, 17, 0, 0, tzinfo=NY_TZ))
285285
)
286286

287+
# fx & metal within market hours on a friday (before 10pm UTC)
288+
assert (
289+
get_next_market_close("fx", datetime.datetime(2023, 11, 10, 7, 0, 0, tzinfo=NY_TZ))
290+
== format_datetime_to_unix_timestamp(datetime.datetime(2023, 11, 10, 17, 0, 0, tzinfo=NY_TZ))
291+
)
292+
287293
# fx & metal out of market hours
288294
assert (
289295
get_next_market_close("fx", FX_METAL_CLOSE_SUN_2023_6_18_16)
@@ -347,3 +353,4 @@ def test_get_next_market_close():
347353
# crypto
348354
assert get_next_market_close("crypto", CRYPTO_OPEN_WED_2023_6_21_12) == None
349355
assert get_next_market_close("crypto", CRYPTO_OPEN_SUN_2023_6_18_12) == None
356+

0 commit comments

Comments
 (0)