From a3ded619460d56d71444d72ebc30d14f9e4ee5a4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Demidyuk Date: Fri, 14 Feb 2025 23:26:46 +0200 Subject: [PATCH] PyMtApi5: implemented function ChartXYToTimePrice --- PyMtApi5/client.py | 9 +++++++++ PyMtApi5/mt5apiclient.py | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index c7a11375..d3a8876c 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -63,6 +63,7 @@ class Mt5ApiApp: "ChartSaveTemplate": self.process_chart_save_template, "ChartWindowFind": self.process_chart_window_find, "ChartTimePriceToXY": self.process_chart_time_price_to_xy, + "ChartXYToTimePrice": self.process_chart_xy_to_time_price, } def on_disconnect(self, error_msg=None): @@ -468,6 +469,14 @@ class Mt5ApiApp: result = mtapi.chart_time_price_to_xy(int(pieces[0]), int(pieces[1]), int(pieces[2]), float(pieces[3])) print(f"> ChartTimePriceToXY: response = {result}") + def process_chart_xy_to_time_price(self, mtapi, parameters): + pieces = parameters.split(" ", 2) + if len(pieces) != 3 or not pieces[0] or not pieces[1] or not pieces[2]: + print(f"! Invalid parameters for command ChartXYToTimePrice: {parameters}") + return + result = mtapi.chart_xy_to_time_price(int(pieces[0]), int(pieces[1]), int(pieces[2])) + print(f"> ChartXYToTimePrice: 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 8522005c..e2a434d7 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -476,7 +476,7 @@ class Mt5ApiClient: # ChartWindowFind def chart_window_find(self, chart_id, indicator_short_name: str): - cmd_params = {"ChartId": chart_id, "IndicatorShortname": indicator_short_name}; + cmd_params = {"ChartId": chart_id, "IndicatorShortname": indicator_short_name} return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartWindowFind, cmd_params) # ChartTimePriceToXY @@ -487,6 +487,14 @@ class Mt5ApiClient: return (res["Result"]["X"], res["Result"]["Y"]) return None + # ChartXYToTimePrice + def chart_xy_to_time_price(self, chart_id, x, y): + cmd_params = {"ChartId": chart_id, "X": x, "Y": y} + res = self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartXYToTimePrice, cmd_params) + if res is not None and res["RetVal"] == True: + return (res["Result"]["SubWindow"], res["Result"]["Time"], res["Result"]["Price"]) + return None + # Private methods def __event_thread_func(self):