Lấy thông tin về terminal
Hàm terminal_info
cho phép lấy trạng thái và các tham số của terminal MetaTrader 5 đã kết nối.
namedtuple terminal_info()
Khi thành công, hàm trả về thông tin dưới dạng cấu trúc của các tuple đặt tên (namedtuple
), và trong trường hợp có lỗi, nó trả về None
.
Trong một lệnh gọi của hàm này, bạn có thể lấy tất cả thông tin được cung cấp bởi TerminalInfoInteger
, TerminalInfoDouble
, và TerminalInfoDouble
trong MQL5, với tất cả các biến thể của các thuộc tính được hỗ trợ. Tên của các trường trong tuple tương ứng với tên của các phần tử liệt kê mà không có tiền tố "TERMINAL_", được giảm xuống chữ thường.
Ví dụ (xem MQL5/Scripts/MQL5Book/Python/terminalinfo.py
):
python
import MetaTrader5 as mt5
# let's establish a connection to the MetaTrader 5 terminal
if not mt5.initialize():
print("initialize() failed, error code =", mt5.last_error())
quit()
# display brief information about the MetaTrader 5 version
print(mt5.version())
# display full information about the settings and the state of the terminal
terminal_info = mt5.terminal_info()
if terminal_info != None:
# display terminal data as is
print(terminal_info)
# display the data as a dictionary
print("Show terminal_info()._asdict():")
terminal_info_dict = mt5.terminal_info()._asdict()
for prop in terminal_info_dict:
print(" {}={}".format(prop, terminal_info_dict[prop]))
# complete the connection to the MetaTrader 5 terminal
mt5.shutdown()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Kết quả sẽ trông giống như sau.
sh
[500, 3428, '14 Sep 2022']
TerminalInfo(community_account=True, community_connection=True, connected=True, ...
Show terminal_info()._asdict():
community_account=True
community_connection=True
connected=True
dlls_allowed=False
trade_allowed=False
tradeapi_disabled=False
email_enabled=False
ftp_enabled=False
notifications_enabled=False
mqid=False
build=2366
maxbars=5000
codepage=1251
ping_last=77850
community_balance=707.10668201585
retransmission=0.0
company=MetaQuotes Software Corp.
name=MetaTrader 5
language=Russian
path=E:\ProgramFiles\MetaTrader 5
data_path=E:\ProgramFiles\MetaTrader 5
commondata_path=C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\Common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25