public static List <string> ServersDat() { List <string> list = new List <string>(); Server[] servers = MT5API.LoadServersDat("servers.dat"); foreach (Server server in servers) { if (server.ServerInfo != null) { list.Add(server.ServerInfo.ServerName); } if (server.ServerInfoEx != null) { list.Add(server.ServerInfoEx.ServerName); } foreach (var access in server.Accesses) { foreach (var addr in access.Addresses) { list.Add(addr.Address); } } } return(list); }
void Api_OnQuote(MT5API api, Quote args) { try { Balance = (decimal)api.Account.Balance; } catch { } TickEventArgs tick = null; lock (symbolToTick) { if (symbolToTick.ContainsKey(args.Symbol)) { tick = symbolToTick[args.Symbol]; } } if (tick != null) { tick.Bid = (decimal)args.Bid; tick.Ask = (decimal)args.Ask; tick.BrokerTime = args.Time; CurrentTime = args.Time; Tick?.Invoke(this, tick); } }
public void Api_OnQuote(MT5API api, Quote args) { //if(connectStatus.ToString() == "Disconnect" || connectStatus.ToString() == "Exception") // Start(ulong.Parse(connectionModel.Username), connectionModel.Password, connectionModel.Address, port); System.Threading.Thread.Sleep(delay); if (delay != 0) { SMTP.SendEmail(api.Account.Email, api.Account.UserName, $"Fin Instrument - '{args.Symbol}'\nDelay starts for the '{delay}' seconds!!!"); } Bid = args.Bid; Ask = args.Ask; Time = args.Time; }
public void Start(ulong login, string password, string address, int port) { try { api = new MT5API(login, password, address, port); //api.ConnectTimeout = 10000; api.OnConnectProgress += Api_OnConnectProgress; api.OnQuote += Api_OnQuote; api.Connect(); } catch (Exception e) { //logger.LogError(ViewId + " " + e.Message); } Logger.OnMsg += Logger_OnMsg; }
public void Stop() { if (api != null) { try { api.OnConnectProgress -= Api_OnConnectProgress; api.OnQuote -= Api_OnQuote; api.Disconnect(); } catch (Exception e) { //logger.LogError(ViewId + " " + e.Message); } api = null; } }
void Api_OnConnectProgress(MT5API sender, ConnectEventArgs args) { bool loggedIn = connectStatus == ConnectProgress.AcceptAuthorized; connectStatus = args.Progress; if (args.Progress == ConnectProgress.AcceptAuthorized) { // if (!loggedIn) LoggedIn?.Invoke(this, EventArgs.Empty); } else { if (loggedIn) { // LoggedOut?.Invoke(this, EventArgs.Empty); symbolToTick.Clear(); } } }
public string Connect_MT5(ConnectionModel model) { int cnt = 1; string address, msg_res = ""; connectionModel = model; string[] h = model.Address.Split(new char[] { ':' }); if (h.Length == 1 && !model.Connected) { return(""); } else { address = h[0]; port = int.Parse(h[1]); } if (model.Connected) { Start(ulong.Parse(model.Username), model.Password, address, port); Subscribe(symbol); //while (api.GetQuote(symbol) == null) //{ // SMTP.SendEmail(api.Account.Email, api.Account.UserName, $"Delay starts for the '{delay}' seconds!!!"); //} } Start(ulong.Parse(model.Username), model.Password, address, port); try { Subscribe(symbol); //while (api.GetQuote(symbol) == null) //{ // cnt++; // if (cnt == delay) // SMTP.SendEmail(api.Account.Email, api.Account.UserName, $"Delay starts for the '{delay}' seconds!!!"); //} model.Connected = api.Connected; Api = api; } catch (ServerException sex) { serverMsg = sex.Message; } return(msg_res); }