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

Check if market is closed #37

Open
mateusscheper opened this issue Mar 13, 2023 · 3 comments
Open

Check if market is closed #37

mateusscheper opened this issue Mar 13, 2023 · 3 comments

Comments

@mateusscheper
Copy link

Hi!

Any way to check if market is closed at a given date and time? Like holydays and weekends.

Thanks!

@AminHP
Copy link
Owner

AminHP commented Mar 13, 2023

Hi @mateusscheper ,
I'm not sure, but you might find some clues here. Please let me know if you found something.

@wayneadams
Copy link

@mateusscheper , on the object returned from symbol_info() there's a trade_mode member that seems to give this information. See docs for ENUM_SYMBOL_TRADE_MODE here. It only works real-time. Does that break your "given date and time" requirement?

@mateusscheper
Copy link
Author

I'm not sure how MT5's API works.
Currently I'm using this workaround to skip the price if it's in a time when the market is usually closed or if it's the same as the last price I got:

def get_state_sequence(sim, current_time):
    state_sequence = []
    i = 0
    time_multiplier = 0
    while i < 21:
        time = current_time - timedelta(minutes=15 * time_multiplier)
        time_multiplier += 1
        if is_not_weekday(time):
            continue

        state = get_state(sim, time)
        if state_sequence and state == state_sequence[-1]:
            continue
        state_sequence.append(state)
        i += 1
    state_sequence.reverse()
    state_sequence = np.reshape(state_sequence, (1, 21, 5))
    return state_sequence


def is_not_weekday(current_time):
    return current_time.weekday() > 4 \
        or (current_time.weekday() == 0 and current_time.hour < 7) \
        or (current_time.weekday() == 4 and current_time.hour > 23 and current_time.minute > 45)

It doesn't get 100% right but it helps. Still, it would be better to have a builtin function to check if the market is open/closed.

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

No branches or pull requests

3 participants