PyMtApi5: implemented function MarketBookAdd, MarketBookRelease

This commit is contained in:
Vyacheslav Demidyuk
2025-01-23 23:28:55 +02:00
parent 9f4a247048
commit 7a7d1f33d9
2 changed files with 28 additions and 0 deletions
+18
View File
@@ -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"
+10
View File
@@ -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):