gmag11 / MetaTrader5-Docker-Image

Docker image that runs Metatrader 5 with VNC web server
MIT License
107 stars 51 forks source link

Can't get historic prices from mt5linux #12

Closed thmmcoelho closed 2 months ago

thmmcoelho commented 2 months ago

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

2024-09-02 20:50:06 DEBUG:SLAVE/8001:Exception caught
2024-09-02 20:50:06 Traceback (most recent call last):
2024-09-02 20:50:06   File "C:\Program Files (x86)\Python39-32\lib\site-packages\rpyc\core\protocol.py", line 324, in _dispatch_request
2024-09-02 20:50:06     res = self._HANDLERS[handler](self, *args)
2024-09-02 20:50:06   File "C:\Program Files (x86)\Python39-32\lib\site-packages\rpyc\core\protocol.py", line 592, in _handle_call
2024-09-02 20:50:06     return obj(*args, **dict(kwargs))
2024-09-02 20:50:06   File "C:\Program Files (x86)\Python39-32\lib\site-packages\rpyc\core\service.py", line 156, in eval
2024-09-02 20:50:06     return eval(text, self.namespace)
2024-09-02 20:50:06   File "<string>", line 1
2024-09-02 20:50:06     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)
2024-09-02 20:50:06                                                                                                                                                               ^
2024-09-02 20:50:06 SyntaxError: 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
rates = mt5.copy_rates_range(symbol, mt5.TIMEFRAME_M2, range_start, time_finish)
thmmcoelho commented 2 months ago

It's actually a problem with mt5linux. I apologize for posting it here.