PyMtApi5: implemented function ChartOpen

This commit is contained in:
Vyacheslav Demidyuk
2025-02-19 16:14:41 +02:00
parent a3ded61946
commit 6a9739ff1e
2 changed files with 16 additions and 0 deletions
+10
View File
@@ -64,6 +64,7 @@ class Mt5ApiApp:
"ChartWindowFind": self.process_chart_window_find,
"ChartTimePriceToXY": self.process_chart_time_price_to_xy,
"ChartXYToTimePrice": self.process_chart_xy_to_time_price,
"ChartOpen": self.process_chart_open,
}
def on_disconnect(self, error_msg=None):
@@ -477,6 +478,15 @@ class Mt5ApiApp:
result = mtapi.chart_xy_to_time_price(int(pieces[0]), int(pieces[1]), int(pieces[2]))
print(f"> ChartXYToTimePrice: response = {result}")
def process_chart_open(self, mtapi, parameters):
pieces = parameters.split(" ", 1)
if len(pieces) != 2 or not pieces[0] or not pieces[1]:
print(f"! Invalid parameters for command ChartOpen: {parameters}")
return
period = mt5enums.ENUM_TIMEFRAMES(int(pieces[1]))
result = mtapi.chart_open(pieces[0], period)
print(f"> ChartOpen: response = {result}")
def mtapi_command_thread(self, mtapi):
while mtapi.is_connected():
filename = "client.cmd"
+6
View File
@@ -495,6 +495,12 @@ class Mt5ApiClient:
return (res["Result"]["SubWindow"], res["Result"]["Time"], res["Result"]["Price"])
return None
# 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
# Private methods
def __event_thread_func(self):