Skip to content

Commit

Permalink
fix next-market-open for fx (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel authored Dec 25, 2023
1 parent 06d45fa commit a7fb15e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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='contact@pyth.network',
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

0 comments on commit a7fb15e

Please sign in to comment.