when I use initialize function without parameters the connection is established correctly. but when I add any parameter like the 'login' it is not working
account=#account_number
authorized=mt5.initialize()
if authorized:
print("connected to account #{}".format(mt5.account_info()))
else:
print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))
using the above code will connect correctly
but when I edit it like that authorized=mt5.initialize(login=account)
it won't connect and give me this error and I am sure of my account number and all the other details failed to connect at account #53895161, error code: (-2, 'Terminal: Invalid params')
mt5.initialize() Establish a connection with the MetaTrader 5 terminal.
use mt5.login() for login:
authorized = mt5.login(1234, password = "password", server="server")
Mt5 - Under the hood is C++, and requires the correct typed parameters. The login parameter is expecting an int, so if you're reading it as a string you'll need to type cast it.
# Notice the int typecast.
account = int(keyring.get_password("MyMT5","AccountId"))
password = keyring.get_password("MyMT5","Password")
if not mt5.initialize(login=account, password=password, server="MyServer" ):
print("initialize() failed, error code =", mt5.last_error())
quit()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.