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

Issue with the copy_rates_range function #21

Open
thmmcoelho opened this issue Sep 3, 2024 · 2 comments
Open

Issue with the copy_rates_range function #21

thmmcoelho opened this issue Sep 3, 2024 · 2 comments

Comments

@thmmcoelho
Copy link

When I try to use the mt5 copy_rates_range function, I get the following error log:

Traceback (most recent call last):
  File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/mt5linux/__init__.py", line 2290, in copy_rates_range
    return rpyc.utils.classic.obtain(self.__conn.eval(code))
  File "/usr/local/lib/python3.8/site-packages/rpyc/core/netref.py", line 240, in __call__
    return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
  File "/usr/local/lib/python3.8/site-packages/rpyc/core/netref.py", line 63, in syncreq
    return conn.sync_request(handler, proxy, *args)
  File "/usr/local/lib/python3.8/site-packages/rpyc/core/protocol.py", line 473, in sync_request
    return self.async_request(handler, *args, timeout=timeout).value
  File "/usr/local/lib/python3.8/site-packages/rpyc/core/async_.py", line 102, in value
    raise self._obj
  File "<string>", line 1
    mt5.copy_rates_range("WINV24", 2, datetime.datetime(2024, 9, 2, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=75600), '-03')), 2024-09-03 00:00:00)
                                                                                                                                                              ^
_get_exception_class.<locals>.Derived: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

This is my code:

start_date = '2024-09-02 00:00:00'
finish_date = '2024-09-03 00:00:00'
time_start = datetime.strptime(start_date, '%Y-%m-%d %H:%M:%S')
time_finish = datetime.strptime(finish_date, '%Y-%m-%d %H:%M:%S')
time_delta = time_finish - time_start
if time_delta.days <= 0:
    range_start = time_finish - timedelta(days=1)
else:
    range_start = time_start
mt5.execute('import datetime')
mt5.execute('import pytz')
rates = mt5.copy_rates_range(symbol, mt5.TIMEFRAME_M2, range_start, time_finish)

I tried to add mt5.execute('import pytz') and mt5.execute('import datetime'), as mentioned in #3, but this does not work.

@Masses3581
Copy link

@thmmcoelho:
I had the exact same problem. By chance, I saw that the author has implemented a fix for this in the mt5linux -> init.py.
Copy the file again into your IDE from the host, and then the retrieval with date_to will work.
I added 2 lines, and it worked. Hope this helps

@Akress-spec
Copy link

check this line and this file
File "/usr/local/lib/python3.8/site-packages/mt5linux/init.py", line 2290, in copy_rates_range

that should be like
code=f'mt5.copy_rates_range("{symbol}", {timeframe}, {repr(date_from.astimezone())}, {repr(date_to.astimezone())})'

in my case it was something like this
code=f'mt5.copy_rates_range("{symbol}", {timeframe}, {repr(date_from.astimezone())}, date_to)})'

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