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

add test for full 2024 interval for is_market_open #48

Merged
merged 4 commits into from
Jan 9, 2024
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
13 changes: 6 additions & 7 deletions pythclient/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
datetime.datetime(2023, 11, 24, tzinfo=NY_TZ).date(),
datetime.datetime(2024, 7, 3, tzinfo=NY_TZ).date(),
datetime.datetime(2024, 11, 29, tzinfo=NY_TZ).date(),
datetime.datetime(2024, 12, 24, tzinfo=NY_TZ).date(),
]

FX_METAL_OPEN_CLOSE_TIME = datetime.time(17, 0, 0, tzinfo=NY_TZ)
Expand Down Expand Up @@ -76,6 +77,11 @@ def is_market_open(asset_type: str, dt: datetime.datetime) -> bool:
if asset_type in ["fx", "metal"]:
if date in FX_METAL_HOLIDAYS and time < FX_METAL_OPEN_CLOSE_TIME:
return False
# If the next day is a holiday, the market is closed at 5pm ET
if (
date + datetime.timedelta(days=1) in FX_METAL_HOLIDAYS
) and time >= FX_METAL_OPEN_CLOSE_TIME:
return False
# On Friday the market is closed after 5pm
if day == 4 and time >= FX_METAL_OPEN_CLOSE_TIME:
return False
Expand All @@ -85,13 +91,6 @@ def is_market_open(asset_type: str, dt: datetime.datetime) -> bool:
# On Sunday the market is closed before 5pm
if day == 6 and time < FX_METAL_OPEN_CLOSE_TIME:
return False
# On Sunday the market is closed after 5pm if the next day is a holiday
if (
day == 6
and time >= FX_METAL_OPEN_CLOSE_TIME
and (date + datetime.timedelta(days=1) in FX_METAL_HOLIDAYS)
):
return False

return True

Expand Down
Loading
Loading