import MetaTrader5 as mt5
import pandas as pd
# Datenanzeige des Pakets von MetaTrader 5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# Verbindung zum MetaTrader 5 Terminal herstellen
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
# Verbindung mit dem Handelskonto unter Angabe von Passwort und Server herstellen
authorized=mt5.login(25115284, password="gqz0343lbdm")
if authorized:
account_info=mt5.account_info()
if account_info!=None:
# Anzeige der Daten des Handelskontos 'as is'
print(account_info)
# Anzeige der Daten des Handelskontos als Liste
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]))
print()
# Konvertieren und Ausdrucken der Liste als DataFrame
df=pd.DataFrame(list(account_info_dict.items()),columns=['property','value'])
print("account_info() as dataframe:")
print(df)
else:
print("failed to connect to trade account 25115284 with password=gqz0343lbdm, error code =",mt5.last_error())
# Schließen der Verbindung zum MetaTrader 5
mt5.shutdown()
Ergebnis:
MetaTrader5 package author: MetaQuotes Software Corp.
MetaTrader5 package version: 5.0.29
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
server=MetaQuotes-Demo
currency=USD
company=MetaQuotes Software Corp.
account_info() as dataframe
property value
0 login 25115284
1 trade_mode 0
2 leverage 100
3 limit_orders 200
4 margin_so_mode 0
5 trade_allowed True
6 trade_expert True
7 margin_mode 2
8 currency_digits 2
9 fifo_close False
10 balance 99588.3
11 credit 0
12 profit -45.13
13 equity 99543.2
14 margin 54.37
15 margin_free 99488.8
16 margin_level 183085
17 margin_so_call 50
18 margin_so_so 30
19 margin_initial 0
20 margin_maintenance 0
21 assets 0
22 liabilities 0
23 commission_blocked 0
24 name James Smith
25 server MetaQuotes-Demo
26 currency USD
27 company MetaQuotes Software Corp.
|