Lấy thông tin về tài khoản giao dịch
Hàm account_info
lấy toàn bộ thông tin về tài khoản giao dịch hiện tại.
namedtuple account_info()
Hàm trả về thông tin dưới dạng cấu trúc của các tuple đặt tên (namedtuple
). Trong trường hợp có lỗi, kết quả là None
.
Sử dụng hàm này, bạn có thể dùng một lệnh gọi để lấy tất cả thông tin được cung cấp bởi AccountInfoInteger
, AccountInfoDouble
, và AccountInfoString
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ố "ACCOUNT_", được giảm xuống chữ thường.
Tập lệnh sau MQL5/Scripts/MQL5Book/Python/accountinfo.py
được đính kèm với sách.
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()
account_info = mt5.account_info()
if account_info != None:
# display trading account data as is
print(account_info)
# display data about the trading account in the form of a dictionary
print("Show account_info()._asdict():")
account_info_dict = mt5.account_info()._asdict()
for prop in account_info_dict:
print(" {}={}".format(prop, account_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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Kết quả sẽ trông giống như sau.
sh
AccountInfo(login=25115284, trade_mode=0, leverage=100, limit_orders=200, margin_so_mode=0, ...
Show account_info()._asdict():
login=25115284
trade_mode=0
leverage=100
limit_orders=200
margin_so_mode=0
trade_allowed=True
trade_expert=True
margin_mode=2
currency_digits=2
fifo_close=False
balance=99511.4
credit=0.0
profit=41.82
equity=99553.22
margin=98.18
margin_free=99455.04
margin_level=101398.67590140559
margin_so_call=50.0
margin_so_so=30.0
margin_initial=0.0
margin_maintenance=0.0
assets=0.0
liabilities=0.0
commission_blocked=0.0
name=MetaQuotes Dev Demo
server=MetaQuotes-Demo
currency=USD
company=MetaQuotes Software Corp.
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
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30