09月22日, 2014 2125次
import MetaTrader5 as mt5
# 显示有关MetaTrader 5程序包的数据
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# 建立与MetaTrader 5程序端的连接
#if not mt5.initialize("E:\\mt5_mut\\2\\terminal64.exe"):
if not mt5.initialize(login=333333, server="CudraniaCapital-Real", password="eeeee"):
print("initialize() failed, error cod1e =",mt5.last_error())
quit()
# 显示有关MetaTrader 5版本的数据
print(mt5.version())
print(mt5.account_info())
# 获取交易品种的数量
symbols=mt5.symbols_total()
if symbols>0:
print("Total symbols =",symbols)
else:
print("symbols not found")
# 获取所有交易品种
symbols=mt5.symbols_get()
print('Symbols: ', len(symbols))
count=0
# 显示前五个交易品种
for s in symbols:
count+=1
print("{}. {}".format(count,s.name))
if count==500: break
print()
# 现在连接到指定密码的另一个交易账户
server_name="CudraniaCapital-Real"
password="3333333"
account=3333333
authorized=mt5.login(account, password=password,server="CudraniaCapital-Real")
if authorized:
# display trading account data 'as is'
print(mt5.account_info())
# display trading account data in the form of a list
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()
暂无留言,赶快评论吧