PyMtApi5: implemented function ChartFirst

This commit is contained in:
Vyacheslav Demidyuk
2025-02-21 12:23:42 +02:00
parent 6a9739ff1e
commit f3360cf6d6
2 changed files with 18 additions and 6 deletions
+13 -4
View File
@@ -65,6 +65,7 @@ class Mt5ApiApp:
"ChartTimePriceToXY": self.process_chart_time_price_to_xy,
"ChartXYToTimePrice": self.process_chart_xy_to_time_price,
"ChartOpen": self.process_chart_open,
"ChartFirst": self.process_chart_first,
}
def on_disconnect(self, error_msg=None):
@@ -96,15 +97,19 @@ class Mt5ApiApp:
def process_command(self, mtapi, command):
pieces = command.split(" ", 1)
if len(pieces) != 2 or not pieces[0] or not pieces[1]:
print(f"pieces count: {len(pieces)}")
if len(pieces) == 0 or len(pieces) > 2:
print(f"! Invalid command format: {command.rstrip()}")
return
if pieces[0] not in self.cmd_functions:
print(f"! Unknown command: {pieces[0]}")
command_name = pieces[0].rstrip()
if command_name not in self.cmd_functions:
print(f"! Unknown command: '{command_name}'")
return
if len(pieces) == 1:
pieces.append("")
params = pieces[1].rstrip()
try:
self.cmd_functions[pieces[0]](mtapi, params)
self.cmd_functions[command_name](mtapi, params)
except Exception as e:
print(f"Failed to process command {command.rstrip()}: {e}")
@@ -487,6 +492,10 @@ class Mt5ApiApp:
result = mtapi.chart_open(pieces[0], period)
print(f"> ChartOpen: response = {result}")
def process_chart_first(self, mtapi, _):
result = mtapi.chart_first()
print(f"> ChartFirst: response = {result}")
def mtapi_command_thread(self, mtapi):
while mtapi.is_connected():
filename = "client.cmd"
+5 -2
View File
@@ -498,8 +498,11 @@ class Mt5ApiClient:
# ChartOpen
def chart_open(self, symbol: str, period: ENUM_TIMEFRAMES):
cmd_params = {"Symbol": symbol, "Timeframe": period};
res = self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartOpen, cmd_params)
return res
return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartOpen, cmd_params)
# ChartFirst
def chart_first(self):
return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartFirst)
# Private methods