From c61c773fb943c2d5ec5406eb02032c26eaffe612 Mon Sep 17 00:00:00 2001 From: Vyacheslav Demidyuk Date: Sun, 26 Jan 2025 00:09:24 +0200 Subject: [PATCH] PyMtApi5: implemented function CopyTime --- PyMtApi5/client.py | 13 +++++++++++++ PyMtApi5/mt5apiclient.py | 11 ++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index f45ae6f4..afc59be3 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -47,6 +47,7 @@ class Mt5ApiApp: "MarketBookGet": self.process_market_book_get, "CopyBuffer": self.process_copy_buffer, "CopyRates": self.process_copy_rates, + "CopyTime": self.process_copy_time, } def on_disconnect(self, error_msg=None): @@ -304,6 +305,18 @@ class Mt5ApiApp: result = mtapi.copy_rates(symbol_name, timeframe, start_pos, count) print(f"> CopyRates: response = {result}") + def process_copy_time(self, mtapi, parameters): + pieces = parameters.split(" ", 3) + if len(pieces) != 4 or not pieces[0] or not pieces[1] or not pieces[2] or not pieces[3]: + print(f"! Invalid parameters for command CopyTime: {parameters}") + return + symbol_name = pieces[0] + timeframe = mt5enums.ENUM_TIMEFRAMES(int(pieces[1])) + start_pos = int(pieces[2]) + count = int(pieces[3]) + result = mtapi.copy_time(symbol_name, timeframe, start_pos, count) + print(f"> CopyTime: response = {result}") + def mtapi_command_thread(self, mtapi): while mtapi.is_connected(): filename = "client.cmd" diff --git a/PyMtApi5/mt5apiclient.py b/PyMtApi5/mt5apiclient.py index dfe0a05a..e75dd453 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -285,9 +285,14 @@ class Mt5ApiClient: return rates # CopyTime - def copy_time(self): - # TODO - pass + def copy_time(self, symbol_name: str, timeframe: ENUM_TIMEFRAMES, start_pos: int, count: int): + cmdParams = { + "Symbol": symbol_name, + "Timeframe": timeframe, + "StartPos": start_pos, + "Count": count, + } + return self.__send_command(self.__get_default_expert(), Mt5CommandType.CopyTime, cmdParams) # Copy Open def copy_open(self):