Skip to content

Commit a7fb15e

Browse files
authored
fix next-market-open for fx (#47)
1 parent 06d45fa commit a7fb15e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

pythclient/calendar.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def get_next_market_open(asset_type: str, dt: datetime.datetime) -> int:
134134
)
135135
next_market_open += datetime.timedelta(days=1)
136136
elif asset_type in ["fx", "metal"]:
137-
if dt.weekday() == 6 and time < FX_METAL_OPEN_CLOSE_TIME:
137+
if (dt.weekday() == 6 and time < FX_METAL_OPEN_CLOSE_TIME) or (
138+
dt.date() in FX_METAL_HOLIDAYS and time < FX_METAL_OPEN_CLOSE_TIME
139+
):
138140
next_market_open = dt.replace(
139141
hour=FX_METAL_OPEN_CLOSE_TIME.hour,
140142
minute=FX_METAL_OPEN_CLOSE_TIME.minute,

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.18',
10+
version='0.1.19',
1111
packages=['pythclient'],
1212
author='Pyth Developers',
1313
author_email='[email protected]',

tests/test_calendar.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_get_next_market_open():
175175
== format_datetime_to_unix_timestamp(datetime.datetime(2023, 6, 18, 17, 0, 0, tzinfo=NY_TZ))
176176
)
177177

178-
# fx & metal out of market hours on Sunday Dec 24 2024 after 10pm UTC
178+
# fx & metal out of market hours on Sunday Dec 24 2023 after 5pm ET
179179
assert (
180180
get_next_market_open("fx", FX_METAL_HOLIDAY_SUN_2023_12_24_17)
181181
== format_datetime_to_unix_timestamp(datetime.datetime(2023, 12, 25, 17, 0, 0, tzinfo=NY_TZ))
@@ -185,6 +185,12 @@ def test_get_next_market_open():
185185
== format_datetime_to_unix_timestamp(datetime.datetime(2023, 12, 25, 17, 0, 0, tzinfo=NY_TZ))
186186
)
187187

188+
# fx & metal out of market hours on holiday Dec 25 2023 before 5pm ET
189+
assert (
190+
get_next_market_open("fx", datetime.datetime(2023, 12, 25, 8, 15, 0, tzinfo=NY_TZ))
191+
== format_datetime_to_unix_timestamp(datetime.datetime(2023, 12, 25, 17, 0, 0, tzinfo=NY_TZ))
192+
)
193+
188194
# fx & metal holiday
189195
assert (
190196
get_next_market_open("fx", FX_METAL_HOLIDAY_SUN_2023_1_1)

0 commit comments

Comments
 (0)