Skip to content

Commit

Permalink
fix fx/metal get_next_market_close (#44)
Browse files Browse the repository at this point in the history
* fix fx/metal get_next_market_close

* bump
  • Loading branch information
cctdaniel authored Nov 11, 2023
1 parent fd7f08b commit d657170
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pythclient/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit d657170

Please sign in to comment.