PyMtApi5: implemented function SymbolInfoTick

This commit is contained in:
Vyacheslav Demidyuk
2025-01-22 13:57:19 +02:00
parent 33bff44b39
commit fdb9ebb5de
2 changed files with 27 additions and 0 deletions
+9
View File
@@ -39,6 +39,7 @@ class Mt5ApiApp:
"SymbolInfoDouble": self.process_symbol_info_double,
"SymbolInfoInteger": self.process_symbol_info_integer,
"SymbolInfoString": self.process_symbol_info_string,
"SymbolInfoTick": self.process_symbol_info_tick,
}
def on_disconnect(self, error_msg=None):
@@ -215,6 +216,14 @@ class Mt5ApiApp:
result = mtapi.symbol_info_string(symbol, prop_id)
print(f"> SymbolInfoString: response = {result}")
def process_symbol_info_tick(self, mtapi, parameters):
if len(parameters) == 0:
print(f"! Invalid parameters for command SymbolInfoTick: {parameters} - {len(parameters)}")
return
symbol = parameters
result = mtapi.symbol_info_tick(symbol)
print(f"> SymbolInfoTick: response = {result}")
def mtapi_command_thread(self, mtapi):
while mtapi.is_connected():
filename = "client.cmd"
+18
View File
@@ -29,6 +29,16 @@ class Mt5Quote:
return f"{self.expert_handle}-{self.instrument}: Bid = {self.bid}, Ask = {self.ask}, Volume = {self.volume}"
class Mql5Tick:
def __init__(self, tick_json):
self.bid = tick_json["Bid"]
self.ask = tick_json["Ask"]
self.last = tick_json["Last"]
self.volume = tick_json["Volume"]
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"]
@@ -331,6 +341,14 @@ class Mt5ApiClient:
cmd_params = {"Symbol": symbol_name, "PropId": prop_id}
return self.__send_command(self.__get_default_expert(), Mt5CommandType.SymbolInfoString, cmd_params)
# 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)
if res is not None and res["RetVal"] == True:
return Mql5Tick(res["Result"])
return None
# Private methods
def __event_thread_func(self):