import MetaTrader5 as mt5
# MetaTrader 5パッケージについてのデータを表示する
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# MetaTrader 5ターミナルとの接続を確立する
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
# MetaTrader 5バージョンについてのデータを表示する
print(mt5.version())
# パスワードとサーバを指定して取引口座に接続する
account=17221085
authorized=mt5.login(account) # ターミナルデータベースのパスワードは、接続データが保存されるように設定されている場合に適用される
if authorized:
print("connected to account #{}".format(account))
else:
print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))
# 次に、パスワードを指定して別の取引口座に接続する
account=25115284
authorized=mt5.login(account, password="gqrtz0lbdm")
if authorized:
# 取引口座データを「そのまま」表示する
print(mt5.account_info())
# 取引口座データをリスト形式で表示する
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]))
else:
print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))
# MetaTrader 5ターミナルへの接続をシャットダウンする
mt5.shutdown()
Result:
MetaTrader5 package author: MetaQuotes Software Corp.
MetaTrader5 package version: 5.0.29
[500, 2367, '23 Mar 2020']
connected to account #17221085
connected to account #25115284
AccountInfo(login=25115284, trade_mode=0, leverage=100, limit_orders=200, margin_so_mode=0, ...
account properties:
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=99588.33
credit=0.0
profit=-45.23
equity=99543.1
margin=54.37
margin_free=99488.73
margin_level=183084.6054809638
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=James Smith
server=MetaQuotes-Demo
currency=USD
company=MetaQuotes Software Corp.
|