diff --git a/PyMtApi5/client.py b/PyMtApi5/client.py index a7be34e2..342f8753 100644 --- a/PyMtApi5/client.py +++ b/PyMtApi5/client.py @@ -40,6 +40,7 @@ class Mt5ApiApp: "SymbolInfoInteger": self.process_symbol_info_integer, "SymbolInfoString": self.process_symbol_info_string, "SymbolInfoTick": self.process_symbol_info_tick, + "SymbolInfoSessionQuote": self.process_symbol_info_session_quote, } def on_disconnect(self, error_msg=None): @@ -224,6 +225,17 @@ class Mt5ApiApp: result = mtapi.symbol_info_tick(symbol) print(f"> SymbolInfoTick: response = {result}") + def process_symbol_info_session_quote(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 SymbolInfoSessionQuote: {parameters}") + return + symbol = pieces[0] + day_of_week = mt5enums.ENUM_DAY_OF_WEEK(int(pieces[1])) + session_index = int(pieces[2]) + result = mtapi.symbol_info_session_quote(symbol, day_of_week, session_index) + print(f"> SymbolInfoSessionQuote: 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 64abbcd9..82e3836f 100644 --- a/PyMtApi5/mt5apiclient.py +++ b/PyMtApi5/mt5apiclient.py @@ -39,6 +39,7 @@ class Mql5Tick: def __repr__(self): return f"Bid = {self.bid}, Ask = {self.ask}, Last = {self.last}, Volume = {self.volume}" + class MqlRates: def __init__(self, mql_rates_json): self.time = mql_rates_json["mt_time"] @@ -344,11 +345,19 @@ class Mt5ApiClient: # SymbolInoTick def symbol_info_tick(self, symbol_name: str): cmd_params = {"Symbol": symbol_name} - res = self.__send_command(self.__get_default_expert(), Mt5CommandType.SymbolInfoTick, cmd_params) + res = self.__send_command(self.__get_default_expert(), Mt5CommandType.SymbolInfoTick, cmd_params) if res is not None and res["RetVal"] == True: return Mql5Tick(res["Result"]) return None + # SymbolInfoSessionQuote + def symbol_info_session_quote(self, name: str, day_of_week: ENUM_DAY_OF_WEEK, session_index: int): + cmd_params = {"Symbol": name, "DayOfWeek": day_of_week, "SessionIndex": session_index} + res = self.__send_command(self.__get_default_expert(), Mt5CommandType.SymbolInfoSessionQuote, cmd_params) + if res is not None and res["RetVal"] == True: + return (res["Result"]["From"], res["Result"]["To"]) + return None + # Private methods def __event_thread_func(self): @@ -374,6 +383,7 @@ class Mt5ApiClient: if response is None: self.__logger.warning("Failed to send commad. Result is None") raise Exception("Failed to send commad. Result is None") + print(f"response = {response}") response_json = json.loads(response) error_code = int(response_json["ErrorCode"]) if error_code != 0: