How to work with cluster addresses in MT5 API
To connect MT5 account for the first time you need server ip address. You can get it with Broker.Search or MT5API.LoadServersDat methods.
Each MT5 server its cluster with several IP addresses, if you cannot connect to one IP address, need to try others.
After each successful connection we recommend to save field api.ClusterMembers that contains fresh cluster IP addresses or DNS names.
- var api = new MT5API(1000686, "PaSs2572", "89.30.124.55", 443);
- api.Connect();
- foreach (var item in api.ClusterMembers)
- {
- Console.WriteLine(item.Key.ServerName);
- foreach (var addr in item.Value)
- Console.WriteLine(addr.Address);
- }
Later you can you can use that addresses to connect to MT5 account again. Keep in mind that some addresses from this list could be non responsive, in this case just need to try next member from the list.
If all members in that saved list failed to connect you can try to call Broker.Search method again. If you cannot find required server with Broker.Search but can connect with MT5 Terminal please use MT5API.LoadServersDat to extract data from servers.dat file (http://mtapi.online/2018/09/20/how-to-find-servers-dat/).