mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-16 12:18:09 +00:00
PyMtApi5: implemented function ChartFirst
This commit is contained in:
+13
-4
@@ -65,6 +65,7 @@ class Mt5ApiApp:
|
|||||||
"ChartTimePriceToXY": self.process_chart_time_price_to_xy,
|
"ChartTimePriceToXY": self.process_chart_time_price_to_xy,
|
||||||
"ChartXYToTimePrice": self.process_chart_xy_to_time_price,
|
"ChartXYToTimePrice": self.process_chart_xy_to_time_price,
|
||||||
"ChartOpen": self.process_chart_open,
|
"ChartOpen": self.process_chart_open,
|
||||||
|
"ChartFirst": self.process_chart_first,
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_disconnect(self, error_msg=None):
|
def on_disconnect(self, error_msg=None):
|
||||||
@@ -96,15 +97,19 @@ class Mt5ApiApp:
|
|||||||
|
|
||||||
def process_command(self, mtapi, command):
|
def process_command(self, mtapi, command):
|
||||||
pieces = command.split(" ", 1)
|
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()}")
|
print(f"! Invalid command format: {command.rstrip()}")
|
||||||
return
|
return
|
||||||
if pieces[0] not in self.cmd_functions:
|
command_name = pieces[0].rstrip()
|
||||||
print(f"! Unknown command: {pieces[0]}")
|
if command_name not in self.cmd_functions:
|
||||||
|
print(f"! Unknown command: '{command_name}'")
|
||||||
return
|
return
|
||||||
|
if len(pieces) == 1:
|
||||||
|
pieces.append("")
|
||||||
params = pieces[1].rstrip()
|
params = pieces[1].rstrip()
|
||||||
try:
|
try:
|
||||||
self.cmd_functions[pieces[0]](mtapi, params)
|
self.cmd_functions[command_name](mtapi, params)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to process command {command.rstrip()}: {e}")
|
print(f"Failed to process command {command.rstrip()}: {e}")
|
||||||
|
|
||||||
@@ -487,6 +492,10 @@ class Mt5ApiApp:
|
|||||||
result = mtapi.chart_open(pieces[0], period)
|
result = mtapi.chart_open(pieces[0], period)
|
||||||
print(f"> ChartOpen: response = {result}")
|
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):
|
def mtapi_command_thread(self, mtapi):
|
||||||
while mtapi.is_connected():
|
while mtapi.is_connected():
|
||||||
filename = "client.cmd"
|
filename = "client.cmd"
|
||||||
|
|||||||
@@ -498,8 +498,11 @@ class Mt5ApiClient:
|
|||||||
# ChartOpen
|
# ChartOpen
|
||||||
def chart_open(self, symbol: str, period: ENUM_TIMEFRAMES):
|
def chart_open(self, symbol: str, period: ENUM_TIMEFRAMES):
|
||||||
cmd_params = {"Symbol": symbol, "Timeframe": period};
|
cmd_params = {"Symbol": symbol, "Timeframe": period};
|
||||||
res = self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartOpen, cmd_params)
|
return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartOpen, cmd_params)
|
||||||
return res
|
|
||||||
|
# ChartFirst
|
||||||
|
def chart_first(self):
|
||||||
|
return self.__send_command(self.__get_default_expert(), Mt5CommandType.ChartFirst)
|
||||||
|
|
||||||
# Private methods
|
# Private methods
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user