From 6a9739ff1ed64fa795a9eea3fbba392fd5ed9de6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Demidyuk Date: Wed, 19 Feb 2025 16:14:41 +0200 Subject: [PATCH] PyMtApi5: implemented function ChartOpen --- PyMtApi5/client.py | 10 ++++++++++ PyMtApi5/mt5apiclient.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index d3a8876c..cef4479a 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -64,6 +64,7 @@ class Mt5ApiApp: "ChartWindowFind": self.process_chart_window_find, "ChartTimePriceToXY": self.process_chart_time_price_to_xy, "ChartXYToTimePrice": self.process_chart_xy_to_time_price, + "ChartOpen": self.process_chart_open, } def on_disconnect(self, error_msg=None): @@ -477,6 +478,15 @@ class Mt5ApiApp: result = mtapi.chart_xy_to_time_price(int(pieces[0]), int(pieces[1]), int(pieces[2])) print(f"> ChartXYToTimePrice: response = {result}") + def process_chart_open(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 ChartOpen: {parameters}") + return + period = mt5enums.ENUM_TIMEFRAMES(int(pieces[1])) + result = mtapi.chart_open(pieces[0], period) + print(f"> ChartOpen: 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 e2a434d7..4a75b19d 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -495,6 +495,12 @@ class Mt5ApiClient: return (res["Result"]["SubWindow"], res["Result"]["Time"], res["Result"]["Price"]) return None + # ChartOpen + def chart_open(self, symbol: str, period: ENUM_TIMEFRAMES): + cmd_params = {"Symbol": symbol, "Timeframe": period}; + res = self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartOpen, cmd_params) + return res + # Private methods def __event_thread_func(self):