From 3eba06a73be87823cd58ded27f76ced85d6794aa Mon Sep 17 00:00:00 2001 From: Vyacheslav Demidyuk Date: Sat, 8 Feb 2025 12:41:41 +0200 Subject: [PATCH] PyMtApi5: implemented function ChartApplyTemplate --- PyMtApi5/client.py | 9 +++++++++ PyMtApi5/mt5apiclient.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index 93c20bcf..39df98cc 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -59,6 +59,7 @@ class Mt5ApiApp: "CopyTicks": self.process_copy_ticks, "ChartId": self.process_chart_id, "ChartRedraw": self.process_chart_redraw, + "ChartApplyTemplate": self.process_chart_apply_template, } def on_disconnect(self, error_msg=None): @@ -432,6 +433,14 @@ class Mt5ApiApp: mtapi.chart_redraw(int(parameters)) print(f"> ChartRedraw: success") + def process_chart_apply_template(self, mtapi, parameters): + pieces = parameters.split(" ", 1) + if len(pieces) != 2 or not pieces[0] or not pieces[1]: + print(f"! Invalid parameters for command ChartApplyTemplate: {parameters}") + return + result = mtapi.chart_apply_template(int(pieces[0]), pieces[1]) + print(f"> ChartApplyTemplate: 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 912ae338..581feb79 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -452,16 +452,23 @@ class Mt5ApiClient: cmd_params = {"Symbol": symbol} return self.__send_command(self.__get_default_expert(), Mt5CommandType.MarketBookGet, cmd_params) + # ChartId def chart_id(self, expert_handle = 0): if expert_handle == 0: return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartId) else: return self.__send_command(expert_handle, Mt5CommandType.ChartId) + # ChartRedraw def chart_redraw(self, chart_id = 0): cmd_params = {"ChartId": chart_id} self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartRedraw, cmd_params) + # ChartApplyTemplate + def chart_apply_template(self, chart_id, filename: str): + cmd_params = { "ChartId": chart_id, "TemplateFileName": filename}; + return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartApplyTemplate, cmd_params) + # Private methods def __event_thread_func(self):