Compare commits

...

5 Commits

Author SHA1 Message Date
DW 515a12ab15 Added function ChangeAccount 2017-08-12 01:31:36 +03:00
DW 10e267d031 Fixed bug in function iBarShift 2017-07-20 17:55:29 +03:00
DW abcd489367 Started version 1.0.37 2017-06-21 17:41:10 +03:00
DW d630e61e3c Issue #52: Updated functions OrderSend to use request stucture 2017-05-11 17:26:46 +03:00
DW 280bab7faf Started version 1.0.36 2017-05-11 10:44:30 +03:00
8 changed files with 399 additions and 58 deletions
+58 -6
View File
@@ -271,31 +271,77 @@ namespace MtApi
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
, string comment, int magic, DateTime expiration) , string comment, int magic, DateTime expiration)
{ {
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, Color.Empty); var response = SendRequest<OrderSendResponse>(new OrderSendRequest
{
Symbol = symbol,
Cmd = (int)cmd,
Volume = volume,
Price = price,
Slippage = slippage,
Stoploss = stoploss,
Takeprofit = takeprofit,
Comment = comment,
Magic = magic,
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration)
});
return response?.Ticket ?? -1;
} }
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
, string comment, int magic) , string comment, int magic)
{ {
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, DateTime.MinValue, Color.Empty); var response = SendRequest<OrderSendResponse>(new OrderSendRequest
{
Symbol = symbol,
Cmd = (int)cmd,
Volume = volume,
Price = price,
Slippage = slippage,
Stoploss = stoploss,
Takeprofit = takeprofit,
Comment = comment,
Magic = magic
});
return response?.Ticket ?? -1;
} }
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
, string comment) , string comment)
{ {
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, 0, DateTime.MinValue, Color.Empty); var response = SendRequest<OrderSendResponse>(new OrderSendRequest
{
Symbol = symbol,
Cmd = (int)cmd,
Volume = volume,
Price = price,
Slippage = slippage,
Stoploss = stoploss,
Takeprofit = takeprofit,
Comment = comment
});
return response?.Ticket ?? -1;
} }
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit) public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit)
{ {
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, null, 0, DateTime.MinValue, Color.Empty); var response = SendRequest<OrderSendResponse>(new OrderSendRequest
{
Symbol = symbol,
Cmd = (int)cmd,
Volume = volume,
Price = price,
Slippage = slippage,
Stoploss = stoploss,
Takeprofit = takeprofit,
});
return response?.Ticket ?? -1;
} }
public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit) public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit)
{ {
double dPrice; double dPrice;
return double.TryParse(price, out dPrice) ? return double.TryParse(price, out dPrice) ?
OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit, null, 0, DateTime.MinValue, Color.Empty) : 0; OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit) : 0;
} }
public int OrderSendBuy(string symbol, double volume, int slippage) public int OrderSendBuy(string symbol, double volume, int slippage)
@@ -740,7 +786,7 @@ namespace MtApi
#endregion #endregion
#region Account Information #region Account functions
public double AccountBalance() public double AccountBalance()
{ {
@@ -823,6 +869,12 @@ namespace MtApi
return SendCommand<int>(MtCommandType.AccountStopoutMode, null); return SendCommand<int>(MtCommandType.AccountStopoutMode, null);
} }
public bool ChangeAccount(string login, string password, string host)
{
var commandParameters = new ArrayList { login, password, host};
return SendCommand<bool>(MtCommandType.ChangeAccount, commandParameters);
}
#endregion #endregion
#region Common Function #region Common Function
+2 -1
View File
@@ -229,6 +229,7 @@
ObjectSetText = 233, ObjectSetText = 233,
ObjectType = 234, ObjectType = 234,
UnlockTicks = 235 UnlockTicks = 235,
ChangeAccount = 280
} }
} }
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.35.0")] [assembly: AssemblyVersion("1.0.37.0")]
[assembly: AssemblyFileVersion("1.0.35.0")] [assembly: AssemblyFileVersion("1.0.37.0")]
+108 -29
View File
@@ -202,6 +202,13 @@
this.button4 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button();
this.tabPage11 = new System.Windows.Forms.TabPage(); this.tabPage11 = new System.Windows.Forms.TabPage();
this.button69 = new System.Windows.Forms.Button(); 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.groupBox1.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@@ -243,7 +250,7 @@
this.buttonConnect.Location = new System.Drawing.Point(17, 73); this.buttonConnect.Location = new System.Drawing.Point(17, 73);
this.buttonConnect.Name = "buttonConnect"; this.buttonConnect.Name = "buttonConnect";
this.buttonConnect.Size = new System.Drawing.Size(75, 23); this.buttonConnect.Size = new System.Drawing.Size(75, 23);
this.buttonConnect.TabIndex = 4; this.buttonConnect.TabIndex = 2;
this.buttonConnect.Text = "Connect"; this.buttonConnect.Text = "Connect";
this.buttonConnect.UseVisualStyleBackColor = true; this.buttonConnect.UseVisualStyleBackColor = true;
this.buttonConnect.Click += new System.EventHandler(this.buttonConnect_Click); this.buttonConnect.Click += new System.EventHandler(this.buttonConnect_Click);
@@ -325,7 +332,7 @@
this.checkBox2.Location = new System.Drawing.Point(6, 296); this.checkBox2.Location = new System.Drawing.Point(6, 296);
this.checkBox2.Name = "checkBox2"; this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(281, 17); this.checkBox2.Size = new System.Drawing.Size(281, 17);
this.checkBox2.TabIndex = 16; this.checkBox2.TabIndex = 5;
this.checkBox2.Text = "Use selected ExpertHandle (chart) as default executor"; this.checkBox2.Text = "Use selected ExpertHandle (chart) as default executor";
this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
@@ -346,7 +353,7 @@
this.listViewQuotes.MultiSelect = false; this.listViewQuotes.MultiSelect = false;
this.listViewQuotes.Name = "listViewQuotes"; this.listViewQuotes.Name = "listViewQuotes";
this.listViewQuotes.Size = new System.Drawing.Size(292, 271); this.listViewQuotes.Size = new System.Drawing.Size(292, 271);
this.listViewQuotes.TabIndex = 15; this.listViewQuotes.TabIndex = 4;
this.listViewQuotes.UseCompatibleStateImageBehavior = false; this.listViewQuotes.UseCompatibleStateImageBehavior = false;
this.listViewQuotes.View = System.Windows.Forms.View.Details; this.listViewQuotes.View = System.Windows.Forms.View.Details;
this.listViewQuotes.SelectedIndexChanged += new System.EventHandler(this.listViewQuotes_SelectedIndexChanged); this.listViewQuotes.SelectedIndexChanged += new System.EventHandler(this.listViewQuotes_SelectedIndexChanged);
@@ -446,7 +453,7 @@
this.button22.Location = new System.Drawing.Point(216, 293); this.button22.Location = new System.Drawing.Point(216, 293);
this.button22.Name = "button22"; this.button22.Name = "button22";
this.button22.Size = new System.Drawing.Size(75, 23); this.button22.Size = new System.Drawing.Size(75, 23);
this.button22.TabIndex = 19; this.button22.TabIndex = 31;
this.button22.Text = "OrderModify"; this.button22.Text = "OrderModify";
this.button22.UseVisualStyleBackColor = true; this.button22.UseVisualStyleBackColor = true;
this.button22.Click += new System.EventHandler(this.button22_Click); this.button22.Click += new System.EventHandler(this.button22_Click);
@@ -456,7 +463,7 @@
this.button21.Location = new System.Drawing.Point(216, 264); this.button21.Location = new System.Drawing.Point(216, 264);
this.button21.Name = "button21"; this.button21.Name = "button21";
this.button21.Size = new System.Drawing.Size(75, 23); this.button21.Size = new System.Drawing.Size(75, 23);
this.button21.TabIndex = 18; this.button21.TabIndex = 30;
this.button21.Text = "OrderDelete"; this.button21.Text = "OrderDelete";
this.button21.UseVisualStyleBackColor = true; this.button21.UseVisualStyleBackColor = true;
this.button21.Click += new System.EventHandler(this.button21_Click); this.button21.Click += new System.EventHandler(this.button21_Click);
@@ -475,7 +482,7 @@
this.textBoxOppositeTicket.Location = new System.Drawing.Point(303, 239); this.textBoxOppositeTicket.Location = new System.Drawing.Point(303, 239);
this.textBoxOppositeTicket.Name = "textBoxOppositeTicket"; this.textBoxOppositeTicket.Name = "textBoxOppositeTicket";
this.textBoxOppositeTicket.Size = new System.Drawing.Size(100, 20); this.textBoxOppositeTicket.Size = new System.Drawing.Size(100, 20);
this.textBoxOppositeTicket.TabIndex = 16; this.textBoxOppositeTicket.TabIndex = 28;
this.textBoxOppositeTicket.Text = "0"; this.textBoxOppositeTicket.Text = "0";
// //
// button15 // button15
@@ -483,7 +490,7 @@
this.button15.Location = new System.Drawing.Point(410, 237); this.button15.Location = new System.Drawing.Point(410, 237);
this.button15.Name = "button15"; this.button15.Name = "button15";
this.button15.Size = new System.Drawing.Size(92, 23); this.button15.Size = new System.Drawing.Size(92, 23);
this.button15.TabIndex = 15; this.button15.TabIndex = 29;
this.button15.Text = "OrderCloseBy"; this.button15.Text = "OrderCloseBy";
this.button15.UseVisualStyleBackColor = true; this.button15.UseVisualStyleBackColor = true;
this.button15.Click += new System.EventHandler(this.button15_Click); this.button15.Click += new System.EventHandler(this.button15_Click);
@@ -494,7 +501,7 @@
this.checkBox1.Location = new System.Drawing.Point(297, 208); this.checkBox1.Location = new System.Drawing.Point(297, 208);
this.checkBox1.Name = "checkBox1"; this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(205, 17); this.checkBox1.Size = new System.Drawing.Size(205, 17);
this.checkBox1.TabIndex = 14; this.checkBox1.TabIndex = 27;
this.checkBox1.Text = "Close order by current price on market"; this.checkBox1.Text = "Close order by current price on market";
this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.UseVisualStyleBackColor = true;
// //
@@ -503,7 +510,7 @@
this.button20.Location = new System.Drawing.Point(216, 202); this.button20.Location = new System.Drawing.Point(216, 202);
this.button20.Name = "button20"; this.button20.Name = "button20";
this.button20.Size = new System.Drawing.Size(75, 23); this.button20.Size = new System.Drawing.Size(75, 23);
this.button20.TabIndex = 13; this.button20.TabIndex = 26;
this.button20.Text = "OrderClose"; this.button20.Text = "OrderClose";
this.button20.UseVisualStyleBackColor = true; this.button20.UseVisualStyleBackColor = true;
this.button20.Click += new System.EventHandler(this.button20_Click); this.button20.Click += new System.EventHandler(this.button20_Click);
@@ -513,7 +520,7 @@
this.button17.Location = new System.Drawing.Point(558, 158); this.button17.Location = new System.Drawing.Point(558, 158);
this.button17.Name = "button17"; this.button17.Name = "button17";
this.button17.Size = new System.Drawing.Size(75, 23); this.button17.Size = new System.Drawing.Size(75, 23);
this.button17.TabIndex = 12; this.button17.TabIndex = 25;
this.button17.Text = "GetOrders"; this.button17.Text = "GetOrders";
this.button17.UseVisualStyleBackColor = true; this.button17.UseVisualStyleBackColor = true;
this.button17.Click += new System.EventHandler(this.button17_Click); this.button17.Click += new System.EventHandler(this.button17_Click);
@@ -528,7 +535,7 @@
this.comboBox2.Location = new System.Drawing.Point(341, 158); this.comboBox2.Location = new System.Drawing.Point(341, 158);
this.comboBox2.Name = "comboBox2"; this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(114, 21); this.comboBox2.Size = new System.Drawing.Size(114, 21);
this.comboBox2.TabIndex = 11; this.comboBox2.TabIndex = 23;
// //
// comboBox1 // comboBox1
// //
@@ -540,14 +547,14 @@
this.comboBox1.Location = new System.Drawing.Point(216, 158); this.comboBox1.Location = new System.Drawing.Point(216, 158);
this.comboBox1.Name = "comboBox1"; this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(119, 21); this.comboBox1.Size = new System.Drawing.Size(119, 21);
this.comboBox1.TabIndex = 10; this.comboBox1.TabIndex = 22;
// //
// button16 // button16
// //
this.button16.Location = new System.Drawing.Point(461, 158); this.button16.Location = new System.Drawing.Point(461, 158);
this.button16.Name = "button16"; this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(75, 23); this.button16.Size = new System.Drawing.Size(75, 23);
this.button16.TabIndex = 9; this.button16.TabIndex = 24;
this.button16.Text = "GetOrder"; this.button16.Text = "GetOrder";
this.button16.UseVisualStyleBackColor = true; this.button16.UseVisualStyleBackColor = true;
this.button16.Click += new System.EventHandler(this.button16_Click); this.button16.Click += new System.EventHandler(this.button16_Click);
@@ -566,7 +573,7 @@
this.textBoxIndexTicket.Location = new System.Drawing.Point(290, 132); this.textBoxIndexTicket.Location = new System.Drawing.Point(290, 132);
this.textBoxIndexTicket.Name = "textBoxIndexTicket"; this.textBoxIndexTicket.Name = "textBoxIndexTicket";
this.textBoxIndexTicket.Size = new System.Drawing.Size(109, 20); this.textBoxIndexTicket.Size = new System.Drawing.Size(109, 20);
this.textBoxIndexTicket.TabIndex = 7; this.textBoxIndexTicket.TabIndex = 21;
this.textBoxIndexTicket.Text = "0"; this.textBoxIndexTicket.Text = "0";
// //
// comboBoxSelectedCommand // comboBoxSelectedCommand
@@ -600,7 +607,7 @@
this.comboBoxSelectedCommand.Location = new System.Drawing.Point(213, 344); this.comboBoxSelectedCommand.Location = new System.Drawing.Point(213, 344);
this.comboBoxSelectedCommand.Name = "comboBoxSelectedCommand"; this.comboBoxSelectedCommand.Name = "comboBoxSelectedCommand";
this.comboBoxSelectedCommand.Size = new System.Drawing.Size(121, 21); this.comboBoxSelectedCommand.Size = new System.Drawing.Size(121, 21);
this.comboBoxSelectedCommand.TabIndex = 6; this.comboBoxSelectedCommand.TabIndex = 32;
// //
// label15 // label15
// //
@@ -628,14 +635,14 @@
this.listBoxClosedOrders.Location = new System.Drawing.Point(213, 85); this.listBoxClosedOrders.Location = new System.Drawing.Point(213, 85);
this.listBoxClosedOrders.Name = "listBoxClosedOrders"; this.listBoxClosedOrders.Name = "listBoxClosedOrders";
this.listBoxClosedOrders.Size = new System.Drawing.Size(419, 43); this.listBoxClosedOrders.Size = new System.Drawing.Size(419, 43);
this.listBoxClosedOrders.TabIndex = 5; this.listBoxClosedOrders.TabIndex = 20;
// //
// button2 // button2
// //
this.button2.Location = new System.Drawing.Point(356, 342); this.button2.Location = new System.Drawing.Point(356, 342);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(87, 23); this.button2.Size = new System.Drawing.Size(87, 23);
this.button2.TabIndex = 2; this.button2.TabIndex = 33;
this.button2.Text = "Execute"; this.button2.Text = "Execute";
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.Click += new System.EventHandler(this.button2_Click);
@@ -679,7 +686,7 @@
this.button19.Location = new System.Drawing.Point(87, 336); this.button19.Location = new System.Drawing.Point(87, 336);
this.button19.Name = "button19"; this.button19.Name = "button19";
this.button19.Size = new System.Drawing.Size(75, 23); this.button19.Size = new System.Drawing.Size(75, 23);
this.button19.TabIndex = 15; this.button19.TabIndex = 18;
this.button19.Text = "Sell"; this.button19.Text = "Sell";
this.button19.UseVisualStyleBackColor = true; this.button19.UseVisualStyleBackColor = true;
this.button19.Click += new System.EventHandler(this.button19_Click); this.button19.Click += new System.EventHandler(this.button19_Click);
@@ -689,7 +696,7 @@
this.button18.Location = new System.Drawing.Point(6, 336); this.button18.Location = new System.Drawing.Point(6, 336);
this.button18.Name = "button18"; this.button18.Name = "button18";
this.button18.Size = new System.Drawing.Size(75, 23); this.button18.Size = new System.Drawing.Size(75, 23);
this.button18.TabIndex = 14; this.button18.TabIndex = 17;
this.button18.Text = "Buy"; this.button18.Text = "Buy";
this.button18.UseVisualStyleBackColor = true; this.button18.UseVisualStyleBackColor = true;
this.button18.Click += new System.EventHandler(this.button18_Click); this.button18.Click += new System.EventHandler(this.button18_Click);
@@ -704,28 +711,28 @@
this.comboBoxOrderColor.Location = new System.Drawing.Point(69, 281); this.comboBoxOrderColor.Location = new System.Drawing.Point(69, 281);
this.comboBoxOrderColor.Name = "comboBoxOrderColor"; this.comboBoxOrderColor.Name = "comboBoxOrderColor";
this.comboBoxOrderColor.Size = new System.Drawing.Size(121, 21); this.comboBoxOrderColor.Size = new System.Drawing.Size(121, 21);
this.comboBoxOrderColor.TabIndex = 13; this.comboBoxOrderColor.TabIndex = 15;
// //
// textBox2 // textBox2
// //
this.textBox2.Location = new System.Drawing.Point(70, 255); this.textBox2.Location = new System.Drawing.Point(70, 255);
this.textBox2.Name = "textBox2"; this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(120, 20); this.textBox2.Size = new System.Drawing.Size(120, 20);
this.textBox2.TabIndex = 11; this.textBox2.TabIndex = 14;
// //
// textBoxOrderMagic // textBoxOrderMagic
// //
this.textBoxOrderMagic.Location = new System.Drawing.Point(70, 229); this.textBoxOrderMagic.Location = new System.Drawing.Point(70, 229);
this.textBoxOrderMagic.Name = "textBoxOrderMagic"; this.textBoxOrderMagic.Name = "textBoxOrderMagic";
this.textBoxOrderMagic.Size = new System.Drawing.Size(120, 20); this.textBoxOrderMagic.Size = new System.Drawing.Size(120, 20);
this.textBoxOrderMagic.TabIndex = 11; this.textBoxOrderMagic.TabIndex = 13;
// //
// textBoxOrderComment // textBoxOrderComment
// //
this.textBoxOrderComment.Location = new System.Drawing.Point(70, 203); this.textBoxOrderComment.Location = new System.Drawing.Point(70, 203);
this.textBoxOrderComment.Name = "textBoxOrderComment"; this.textBoxOrderComment.Name = "textBoxOrderComment";
this.textBoxOrderComment.Size = new System.Drawing.Size(120, 20); this.textBoxOrderComment.Size = new System.Drawing.Size(120, 20);
this.textBoxOrderComment.TabIndex = 11; this.textBoxOrderComment.TabIndex = 12;
// //
// textBoxOrderProffit // textBoxOrderProffit
// //
@@ -882,7 +889,7 @@
this.button1.Location = new System.Drawing.Point(120, 307); this.button1.Location = new System.Drawing.Point(120, 307);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23); this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 12; this.button1.TabIndex = 16;
this.button1.Text = "Send"; this.button1.Text = "Send";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); this.button1.Click += new System.EventHandler(this.button1_Click);
@@ -913,7 +920,7 @@
this.listBoxSendedOrders.Name = "listBoxSendedOrders"; this.listBoxSendedOrders.Name = "listBoxSendedOrders";
this.listBoxSendedOrders.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple; this.listBoxSendedOrders.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
this.listBoxSendedOrders.Size = new System.Drawing.Size(419, 43); this.listBoxSendedOrders.Size = new System.Drawing.Size(419, 43);
this.listBoxSendedOrders.TabIndex = 1; this.listBoxSendedOrders.TabIndex = 19;
// //
// tabPage1 // tabPage1
// //
@@ -1110,6 +1117,13 @@
// //
// tabPage3 // 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.button67);
this.tabPage3.Controls.Add(this.button66); this.tabPage3.Controls.Add(this.button66);
this.tabPage3.Controls.Add(this.button65); this.tabPage3.Controls.Add(this.button65);
@@ -1775,10 +1789,10 @@
this.tabPage6.Controls.Add(this.button27); this.tabPage6.Controls.Add(this.button27);
this.tabPage6.Controls.Add(this.button14); this.tabPage6.Controls.Add(this.button14);
this.tabPage6.Controls.Add(this.button13); this.tabPage6.Controls.Add(this.button13);
this.tabPage6.Location = new System.Drawing.Point(4, 22); this.tabPage6.Location = new System.Drawing.Point(4, 40);
this.tabPage6.Name = "tabPage6"; this.tabPage6.Name = "tabPage6";
this.tabPage6.Padding = new System.Windows.Forms.Padding(3); this.tabPage6.Padding = new System.Windows.Forms.Padding(3);
this.tabPage6.Size = new System.Drawing.Size(638, 401); this.tabPage6.Size = new System.Drawing.Size(638, 383);
this.tabPage6.TabIndex = 6; this.tabPage6.TabIndex = 6;
this.tabPage6.Text = "Client Terminal"; this.tabPage6.Text = "Client Terminal";
this.tabPage6.UseVisualStyleBackColor = true; this.tabPage6.UseVisualStyleBackColor = true;
@@ -1824,10 +1838,10 @@
// //
this.tabPage7.Controls.Add(this.button23); this.tabPage7.Controls.Add(this.button23);
this.tabPage7.Controls.Add(this.iCustomBtn); this.tabPage7.Controls.Add(this.iCustomBtn);
this.tabPage7.Location = new System.Drawing.Point(4, 22); this.tabPage7.Location = new System.Drawing.Point(4, 40);
this.tabPage7.Name = "tabPage7"; this.tabPage7.Name = "tabPage7";
this.tabPage7.Padding = new System.Windows.Forms.Padding(3); this.tabPage7.Padding = new System.Windows.Forms.Padding(3);
this.tabPage7.Size = new System.Drawing.Size(638, 401); this.tabPage7.Size = new System.Drawing.Size(638, 383);
this.tabPage7.TabIndex = 7; this.tabPage7.TabIndex = 7;
this.tabPage7.Text = "Technical Indicators"; this.tabPage7.Text = "Technical Indicators";
this.tabPage7.UseVisualStyleBackColor = true; this.tabPage7.UseVisualStyleBackColor = true;
@@ -2062,6 +2076,64 @@
this.button69.UseVisualStyleBackColor = true; this.button69.UseVisualStyleBackColor = true;
this.button69.Click += new System.EventHandler(this.button69_Click); 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -2287,6 +2359,13 @@
private System.Windows.Forms.Button button68; private System.Windows.Forms.Button button68;
private System.Windows.Forms.TabPage tabPage11; private System.Windows.Forms.TabPage tabPage11;
private System.Windows.Forms.Button button69; 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;
} }
} }
+66 -20
View File
@@ -673,6 +673,8 @@ namespace TestApiClientUI
//OrderSend //OrderSend
private async void button1_Click(object sender, EventArgs e) private async void button1_Click(object sender, EventArgs e)
{ {
var ticket = -1;
var symbol = textBoxOrderSymbol.Text; var symbol = textBoxOrderSymbol.Text;
var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex; var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex;
@@ -693,28 +695,43 @@ namespace TestApiClientUI
var comment = textBoxOrderComment.Text; var comment = textBoxOrderComment.Text;
int magic; if (string.IsNullOrEmpty(comment))
int.TryParse(textBoxOrderMagic.Text, out magic);
var expiration = DateTime.Now;
Color arrowColor;
switch (comboBoxOrderColor.SelectedIndex)
{ {
case 0: ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit));
arrowColor = Color.Green; }
break; else
case 1: {
arrowColor = Color.Blue; int magic;
break; if (!int.TryParse(textBoxOrderMagic.Text, out magic))
case 2: {
arrowColor = Color.Red; ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment));
break; }
default: else
return; {
if (comboBoxOrderColor.SelectedIndex < 0 || comboBoxOrderColor.SelectedIndex > 2)
{
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic));
}
else
{
var expiration = DateTime.Now.AddDays(1);
Color arrowColor = Color.White;
switch (comboBoxOrderColor.SelectedIndex)
{
case 0:
arrowColor = Color.Green;
break;
case 1:
arrowColor = Color.Blue;
break;
case 2:
arrowColor = Color.Red;
break;
}
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));
}
}
} }
var ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));
PrintLog($"Sended order result: ticket = {ticket}"); PrintLog($"Sended order result: ticket = {ticket}");
} }
@@ -1407,5 +1424,34 @@ namespace TestApiClientUI
{ {
_apiClient.UnlockTicks(); _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}");
}
} }
} }
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+163
View File
@@ -0,0 +1,163 @@
//+----------------------------------------------------------------------------+
//| mql4-auth.mqh |
//+----------------------------------------------------------------------------+
//| Built by Sergey Lukin |
//| contact@sergeylukin.com |
//+----------------------------------------------------------------------------+
#include <WinUser32.mqh>
#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<ArraySize(login_chars); i++)
{
PostMessageA(e,WM_CHAR,login_chars[i],0);
}
// Select password field
e=GetDlgItem(h,0x4c4);
// Press DELETE key many times in password field to remove current value
for(i=1; i<=100; i++)
{
PostMessageA(e,WM_KEYDOWN,0x2E,1);
}
// Iterate over characters in "passwd" string and pass them to password field one by one
char password_chars[];
string2CharsArray(passwd,password_chars);
for(i=0; i<ArraySize(password_chars); i++)
{
PostMessageA(e,WM_CHAR,password_chars[i],0);
}
// Select server field
e=GetDlgItem(h,0x50d);
// Press DELETE key many times in server field to remove current value
for(i=1; i<=100; i++)
{
PostMessageA(e,WM_KEYDOWN,0x2E,1);
}
// Iterate over characters in "server" string and pass them to server field one by one
char server_chars[];
string2CharsArray(server,server_chars);
for(i=0; i<ArraySize(server_chars); i++)
{
PostMessageA(e,WM_CHAR,server_chars[i],0);
}
Sleep(2*1000);
// Press submit button
e=GetDlgItem(h,0x1);
SendMessageA(e,0x00F5,0,0);
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
/*
* Iterates over string and puts each character code in array
*/
void string2CharsArray(string myString,char &chars[])
{
int cnt=StringLen(myString);
ArrayResize(chars,cnt);
for(int i=0; i<cnt; i++)
{
chars[i]=StringGetChar(myString,i);
}
}
//+------------------------------------------------------------------+