From 58acc52fa2ae0285acca01107540df8055e3579e Mon Sep 17 00:00:00 2001 From: Vyacheslav Demidyuk Date: Fri, 24 Jan 2025 23:33:38 +0200 Subject: [PATCH] PyMtApi5: implemented function CopyBuffer --- PyMtApi5/client.py | 13 +++++++++++++ PyMtApi5/mt5apiclient.py | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index 5ba34a4b..09f46272 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -45,6 +45,7 @@ class Mt5ApiApp: "MarketBookAdd": self.process_market_book_add, "MarketBookRelease": self.process_market_book_release, "MarketBookGet": self.process_market_book_get, + "CopyBuffer": self.process_copy_buffer, } def on_disconnect(self, error_msg=None): @@ -278,6 +279,18 @@ class Mt5ApiApp: result = mtapi.market_book_get(symbol) print(f"> MarketBookGet: response = {result}") + def process_copy_buffer(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 CopyBuffer: {parameters}") + return + indicator_handle = int(pieces[0]) + buffer_num = int(pieces[1]) + start_pos = int(pieces[2]) + count = int(pieces[3]) + result = mtapi.copy_buffer(indicator_handle, buffer_num, start_pos, count) + print(f"> CopyBuffer: 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 a4fd2e4e..4c2c0323 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -244,9 +244,9 @@ class Mt5ApiClient: return self.__send_command(self.__get_default_expert(), Mt5CommandType.BarsCalculated, cmd_params) # CopyBuffer - def copy_buffer(self): - # TODO - pass + def copy_buffer(self, indicator_handle: int, buffer_num: int, start_pos: int, count: int): + cmdParams = {"IndicatorHandle": indicator_handle , "BufferNum": buffer_num, "StartPos": start_pos , "Count": count}; + return self.__send_command(self.__get_default_expert(), Mt5CommandType.CopyBuffer, cmdParams) # CopyRates def copy_rates(self):