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 get_next_market_open/close #33

Merged
merged 6 commits into from
Jun 22, 2023
Merged

fix get_next_market_open/close #33

merged 6 commits into from
Jun 22, 2023

Conversation

cctdaniel
Copy link
Contributor

  • fix get_next_market_open/close logic
  • bump

Copy link
Contributor

@ali-bahjati ali-bahjati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think it would be good to have a single test to make sure that these methods convert time zones as well. (please don't change the current ones because it's easier to understand them with ny timezone)

@cctdaniel cctdaniel merged commit 17005ee into main Jun 22, 2023
@cctdaniel cctdaniel deleted the calendar branch June 22, 2023 09:40
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. I left a couple comments that I think would improve this code.

return next_market_close.astimezone(UTC_TZ).strftime("%Y-%m-%dT%H:%M:%S") + "Z"

print(get_next_market_close("equity", datetime.datetime.now()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add some unit tests for this



@pytest.fixture
def equity_open_weekday_datetime():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can declare these as constants instead of using pytest.fixture, and that will save you some code.

):
# equity within market hours
assert (
get_next_market_open("equity", equity_open_weekday_datetime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of seems like get_next_market_open should return a datetime?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at a minimum extract a test method that does the formatting & comparison so you don't have to repeat this code.


# equity out of market hours
assert (
get_next_market_open("equity", equity_close_weekday_datetime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's hard for me to understand how good these tests are because I have to keep scrolling back and forth between the variable definitions and the results. I suggest naming the input variables something like monday_june_6_23 instead, so that the reader can check that the output makes sense without scrolling up.

return True
return False

if asset_type in ["fx", "metal"]:
if date in FX_METAL_HOLIDAYS:
return False
# On Friday the market is closed after 5pm
if day == 4 and time > FX_METAL_OPEN_CLOSE_TIME:
if day == 4 and time >= FX_METAL_OPEN_CLOSE_TIME:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what's the semantics if you query exactly at the close time? is the market closed then or open? (I ask because it's worth documenting that)

@cctdaniel cctdaniel mentioned this pull request Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants