diff --git a/MtApi/MtApiClient.cs b/MtApi/MtApiClient.cs index 2065c0ed..f52a7b00 100755 --- a/MtApi/MtApiClient.cs +++ b/MtApi/MtApiClient.cs @@ -786,7 +786,7 @@ namespace MtApi #endregion - #region Account Information + #region Account functions public double AccountBalance() { @@ -869,6 +869,12 @@ namespace MtApi return SendCommand(MtCommandType.AccountStopoutMode, null); } + public bool ChangeAccount(string login, string password, string host) + { + var commandParameters = new ArrayList { login, password, host}; + return SendCommand(MtCommandType.ChangeAccount, commandParameters); + } + #endregion #region Common Function diff --git a/MtApi/MtCommandType.cs b/MtApi/MtCommandType.cs index 3b3b5492..a7309983 100755 --- a/MtApi/MtCommandType.cs +++ b/MtApi/MtCommandType.cs @@ -229,6 +229,7 @@ ObjectSetText = 233, ObjectType = 234, - UnlockTicks = 235 + UnlockTicks = 235, + ChangeAccount = 280 } } diff --git a/TestClients/TestApiClientUI/Form1.Designer.cs b/TestClients/TestApiClientUI/Form1.Designer.cs index 8ee5b895..93bc038c 100644 --- a/TestClients/TestApiClientUI/Form1.Designer.cs +++ b/TestClients/TestApiClientUI/Form1.Designer.cs @@ -202,6 +202,13 @@ this.button4 = new System.Windows.Forms.Button(); this.tabPage11 = new System.Windows.Forms.TabPage(); this.button69 = new System.Windows.Forms.Button(); + this.textBoxAccountLogin = new System.Windows.Forms.TextBox(); + this.textBoxAccountPassword = new System.Windows.Forms.TextBox(); + this.label31 = new System.Windows.Forms.Label(); + this.label32 = new System.Windows.Forms.Label(); + this.textBoxAccountHost = new System.Windows.Forms.TextBox(); + this.label33 = new System.Windows.Forms.Label(); + this.button70 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -1110,6 +1117,13 @@ // // tabPage3 // + this.tabPage3.Controls.Add(this.button70); + this.tabPage3.Controls.Add(this.label33); + this.tabPage3.Controls.Add(this.label32); + this.tabPage3.Controls.Add(this.label31); + this.tabPage3.Controls.Add(this.textBoxAccountHost); + this.tabPage3.Controls.Add(this.textBoxAccountPassword); + this.tabPage3.Controls.Add(this.textBoxAccountLogin); this.tabPage3.Controls.Add(this.button67); this.tabPage3.Controls.Add(this.button66); this.tabPage3.Controls.Add(this.button65); @@ -2062,6 +2076,64 @@ this.button69.UseVisualStyleBackColor = true; this.button69.Click += new System.EventHandler(this.button69_Click); // + // textBoxAccountLogin + // + this.textBoxAccountLogin.Location = new System.Drawing.Point(232, 212); + this.textBoxAccountLogin.Name = "textBoxAccountLogin"; + this.textBoxAccountLogin.Size = new System.Drawing.Size(238, 20); + this.textBoxAccountLogin.TabIndex = 15; + // + // textBoxAccountPassword + // + this.textBoxAccountPassword.Location = new System.Drawing.Point(234, 238); + this.textBoxAccountPassword.Name = "textBoxAccountPassword"; + this.textBoxAccountPassword.Size = new System.Drawing.Size(238, 20); + this.textBoxAccountPassword.TabIndex = 16; + // + // label31 + // + this.label31.AutoSize = true; + this.label31.Location = new System.Drawing.Point(168, 214); + this.label31.Name = "label31"; + this.label31.Size = new System.Drawing.Size(36, 13); + this.label31.TabIndex = 17; + this.label31.Text = "Login:"; + // + // label32 + // + this.label32.AutoSize = true; + this.label32.Location = new System.Drawing.Point(168, 241); + this.label32.Name = "label32"; + this.label32.Size = new System.Drawing.Size(56, 13); + this.label32.TabIndex = 17; + this.label32.Text = "Password:"; + // + // textBoxAccountHost + // + this.textBoxAccountHost.Location = new System.Drawing.Point(234, 266); + this.textBoxAccountHost.Name = "textBoxAccountHost"; + this.textBoxAccountHost.Size = new System.Drawing.Size(238, 20); + this.textBoxAccountHost.TabIndex = 17; + // + // label33 + // + this.label33.AutoSize = true; + this.label33.Location = new System.Drawing.Point(168, 269); + this.label33.Name = "label33"; + this.label33.Size = new System.Drawing.Size(66, 13); + this.label33.TabIndex = 17; + this.label33.Text = "MT4 Server:"; + // + // button70 + // + this.button70.Location = new System.Drawing.Point(371, 292); + this.button70.Name = "button70"; + this.button70.Size = new System.Drawing.Size(97, 23); + this.button70.TabIndex = 18; + this.button70.Text = "ChangeAccount"; + this.button70.UseVisualStyleBackColor = true; + this.button70.Click += new System.EventHandler(this.button70_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2287,6 +2359,13 @@ private System.Windows.Forms.Button button68; private System.Windows.Forms.TabPage tabPage11; private System.Windows.Forms.Button button69; + private System.Windows.Forms.Label label33; + private System.Windows.Forms.Label label32; + private System.Windows.Forms.Label label31; + private System.Windows.Forms.TextBox textBoxAccountHost; + private System.Windows.Forms.TextBox textBoxAccountPassword; + private System.Windows.Forms.TextBox textBoxAccountLogin; + private System.Windows.Forms.Button button70; } } diff --git a/TestClients/TestApiClientUI/Form1.cs b/TestClients/TestApiClientUI/Form1.cs index f096bc42..b2b4b819 100644 --- a/TestClients/TestApiClientUI/Form1.cs +++ b/TestClients/TestApiClientUI/Form1.cs @@ -1424,5 +1424,34 @@ namespace TestApiClientUI { _apiClient.UnlockTicks(); } + + private async void button70_Click(object sender, EventArgs e) + { + var login = textBoxAccountLogin.Text; + var password = textBoxAccountPassword.Text; + var host = textBoxAccountHost.Text; + + if (string.IsNullOrEmpty(login)) + { + MessageBox.Show(@"Login is not defined!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + textBoxAccountLogin.Focus(); + return; + } + if (string.IsNullOrEmpty(password)) + { + MessageBox.Show(@"Password is not defined!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + textBoxAccountPassword.Focus(); + return; + } + if (string.IsNullOrEmpty(host)) + { + MessageBox.Show(@"Host is not defined!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + textBoxAccountHost.Focus(); + return; + } + + var result = await Execute(() => _apiClient.ChangeAccount(login, password, host)); + PrintLog($"ChangeAccount result: {result}"); + } } } diff --git a/mq4/MtApi.ex4 b/mq4/MtApi.ex4 index 2e4629a8..a351cdda 100755 Binary files a/mq4/MtApi.ex4 and b/mq4/MtApi.ex4 differ diff --git a/mq4/MtApi.mq4 b/mq4/MtApi.mq4 index 49ab717e..023aded9 100755 Binary files a/mq4/MtApi.mq4 and b/mq4/MtApi.mq4 differ diff --git a/mq4/mql4-auth.mqh b/mq4/mql4-auth.mqh new file mode 100644 index 00000000..1499c3ba --- /dev/null +++ b/mq4/mql4-auth.mqh @@ -0,0 +1,163 @@ +//+----------------------------------------------------------------------------+ +//| mql4-auth.mqh | +//+----------------------------------------------------------------------------+ +//| Built by Sergey Lukin | +//| contact@sergeylukin.com | +//+----------------------------------------------------------------------------+ + +#include + +#import "user32.dll" +int GetAncestor(int,int); +int GetLastActivePopup(int); +int GetDlgItem(int,int); +int GetParent(int hWnd); +#import +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +bool loginDialogIsOpen() + { + int hwnd=WindowHandle(Symbol(),Period()); + int hMetaTrader,hLoginDialog=0; + +// Retrieve Terminal Window Handler + while(!IsStopped()) + { + hwnd=GetParent(hwnd); + if(hwnd==0) break; + hMetaTrader=hwnd; + } + + hLoginDialog=GetLastActivePopup(hMetaTrader); + if(hLoginDialog!=0) + { + return(true); + } else { + return(false); + } + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void closeLoginDialog() + { + int hwnd=WindowHandle(Symbol(),Period()); + int hMetaTrader,hLoginDialog=0,hCancelButton=0; + +// Retrieve Terminal Window Handler + while(!IsStopped()) + { + hwnd=GetParent(hwnd); + if(hwnd==0) break; + hMetaTrader=hwnd; + } + + Sleep(60); + + hLoginDialog=GetLastActivePopup(hMetaTrader); + if(hLoginDialog!=0) + { + hCancelButton=GetDlgItem(hLoginDialog,0x2); + if(hCancelButton!=0) + { + // Click "Cancel" button in Login Dialog + PostMessageA(hCancelButton,0x00F5,0,0); + } + } + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +bool auth(string login,string passwd,string server) + { + datetime s=TimeLocal(); + int h = 0, e = 0, a = GetAncestor(WindowHandle(Symbol(), NULL), 2); + int i = 0; + + PostMessageA(a,WM_COMMAND,35429,0); + + while(e==0) + { + // Give us up to a minute to find the Login dialog + if(TimeLocal()-s>60) + { + return(false); + } + + h=GetLastActivePopup(a); + + // Select login field + e=GetDlgItem(h,0x49d); + + Sleep(1); + } + +// Press DELETE key many times in login field to remove current value + for(i=1; i<=100; i++) + { + PostMessageA(e,WM_KEYDOWN,0x2E,1); + } +// Iterate over characters in "login" string and pass them to login field one by one + char login_chars[]; + string2CharsArray(login,login_chars); + for(i=0; i