From 7a7d1f33d95244b0e6d639e4c8115187b8424f62 Mon Sep 17 00:00:00 2001 From: Vyacheslav Demidyuk Date: Thu, 23 Jan 2025 23:28:55 +0200 Subject: [PATCH] PyMtApi5: implemented function MarketBookAdd, MarketBookRelease --- PyMtApi5/client.py | 18 ++++++++++++++++++ PyMtApi5/mt5apiclient.py | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index 559a9f5c..79bcef99 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -42,6 +42,8 @@ class Mt5ApiApp: "SymbolInfoTick": self.process_symbol_info_tick, "SymbolInfoSessionQuote": self.process_symbol_info_session_quote, "SymbolInfoSessionTrade": self.process_symbol_info_session_trade, + "MarketBookAdd": self.process_market_book_add, + "MarketBookRelease": self.process_market_book_release, } def on_disconnect(self, error_msg=None): @@ -248,6 +250,22 @@ class Mt5ApiApp: result = mtapi.symbol_info_session_trade(symbol, day_of_week, session_index) print(f"> SymbolInfoSessionTrade: response = {result}") + def process_market_book_add(self, mtapi, parameters): + if len(parameters) == 0: + print(f"! Invalid parameters for command MarketBookAdd: {parameters} - {len(parameters)}") + return + symbol = parameters + result = mtapi.market_book_add(symbol) + print(f"> MarketBookAdd: response = {result}") + + def process_market_book_release(self, mtapi, parameters): + if len(parameters) == 0: + print(f"! Invalid parameters for command MarketBookRelease: {parameters} - {len(parameters)}") + return + symbol = parameters + result = mtapi.market_book_release(symbol) + print(f"> MarketBookRelease: 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 306fd18c..31f49918 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -366,6 +366,16 @@ class Mt5ApiClient: return (res["Result"]["From"], res["Result"]["To"]) return None + # MarketBookAdd + def market_book_add(self, symbol: str): + cmd_params = {"Symbol": symbol} + return self.__send_command(self.__get_default_expert(), Mt5CommandType.MarketBookAdd, cmd_params) + + # MarketBookRelease + def market_book_release(self, symbol: str): + cmd_params = {"Symbol": symbol} + return self.__send_command(self.__get_default_expert(), Mt5CommandType.MarketBookRelease, cmd_params) + # Private methods def __event_thread_func(self):