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 next-market-open for fx #47

Merged
merged 1 commit into from
Dec 25, 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
4 changes: 3 additions & 1 deletion pythclient/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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.18',
version='0.1.19',
packages=['pythclient'],
author='Pyth Developers',
author_email='[email protected]',
Expand Down
8 changes: 7 additions & 1 deletion tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down