Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fx/metal get_next_market_close #44

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='[email protected]',
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