Compare commits

..

14 Commits

13 changed files with 489 additions and 96 deletions
+24 -24
View File
@@ -107,7 +107,7 @@ int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid,
try
{
MT5Handler^ mtHander = gcnew MT5Handler();
MtServerInstance::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHander);
MtAdapter::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHander);
}
catch (Exception^ e)
{
@@ -123,7 +123,7 @@ int _stdcall deinitExpert(int expertHandle, wchar_t* err)
{
try
{
MtServerInstance::GetInstance()->DeinitExpert(expertHandle);
MtAdapter::GetInstance()->DeinitExpert(expertHandle);
}
catch (Exception^ e)
{
@@ -139,7 +139,7 @@ int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double a
{
try
{
MtServerInstance::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
MtAdapter::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
}
catch (Exception^ e)
{
@@ -155,7 +155,7 @@ int _stdcall sendIntResponse(int expertHandle, int response)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
}
catch (Exception^ e)
{
@@ -169,7 +169,7 @@ int _stdcall sendLongResponse(int expertHandle, __int64 response)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
}
catch (Exception^ e)
{
@@ -183,7 +183,7 @@ int _stdcall sendULongResponse(int expertHandle, unsigned __int64 response)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseULong(response));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseULong(response));
}
catch (Exception^ e)
{
@@ -199,7 +199,7 @@ int _stdcall sendBooleanResponse(int expertHandle, int response)
{
bool value = (response != 0) ? true : false;
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
}
catch (Exception^ e)
{
@@ -213,7 +213,7 @@ int _stdcall sendDoubleResponse(int expertHandle, double response)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
}
catch (Exception^ e)
{
@@ -227,7 +227,7 @@ int _stdcall sendStringResponse(int expertHandle, wchar_t* response)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
}
catch (Exception^ e)
{
@@ -241,7 +241,7 @@ int _stdcall sendVoidResponse(int expertHandle)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, nullptr);
MtAdapter::GetInstance()->SendResponse(expertHandle, nullptr);
}
catch (Exception^ e)
{
@@ -262,7 +262,7 @@ int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size)
list[i] = values[i];
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
}
catch (Exception^ e)
{
@@ -283,7 +283,7 @@ int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size)
list[i] = values[i];
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
}
catch (Exception^ e)
{
@@ -304,7 +304,7 @@ int _stdcall sendLongArrayResponse(int expertHandle, __int64* values, int size)
list[i] = values[i];
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLongArray(list));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLongArray(list));
}
catch (Exception^ e)
{
@@ -335,7 +335,7 @@ int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int
list[i] = rates;
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlRatesArray(list));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlRatesArray(list));
}
catch (Exception^ e)
{
@@ -357,7 +357,7 @@ int _stdcall sendMqlTickResponse(int expertHandle, CMqlTick* response, int size)
mtResponse->last = response->last;
mtResponse->volume = response->volume;
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse));
}
catch (Exception^ e)
{
@@ -384,7 +384,7 @@ int _stdcall sendMqlBookInfoArrayResponse(int expertHandle, CMqlBookInfo values[
list[i] = info;
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list));
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list));
}
catch (Exception^ e)
{
@@ -400,7 +400,7 @@ int _stdcall getCommandType(int expertHandle, int* res)
{
try
{
*res = MtServerInstance::GetInstance()->GetCommandType(expertHandle);
*res = MtAdapter::GetInstance()->GetCommandType(expertHandle);
}
catch (Exception^ e)
{
@@ -414,7 +414,7 @@ int _stdcall getIntValue(int expertHandle, int paramIndex, int* res)
{
try
{
*res = (int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = (int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
@@ -428,7 +428,7 @@ int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res)
{
try
{
*res = (double)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = (double)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
@@ -442,7 +442,7 @@ int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res)
{
try
{
convertSystemString(res, (String^)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
convertSystemString(res, (String^)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
}
catch (Exception^ e)
{
@@ -456,7 +456,7 @@ int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64* r
{
try
{
*res = (unsigned long)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = (unsigned long)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
@@ -470,7 +470,7 @@ int _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res)
{
try
{
*res = (long)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = (long)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
@@ -484,7 +484,7 @@ int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
{
try
{
bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
bool val = (bool)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = val == true ? 1 : 0;
}
catch (Exception^ e)
@@ -499,7 +499,7 @@ int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int* res)
{
try
{
*res = (unsigned int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = (unsigned int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
+1 -1
View File
@@ -29,7 +29,7 @@ namespace MTApiService
var roller = new RollingFileAppender
{
AppendToFile = false,
AppendToFile = true,
File = $@"{System.IO.Path.GetTempPath()}{profileName}\Logs\{filename}",
Layout = patternLayout,
PreserveLogFileNameExtension = true,
+11 -3
View File
@@ -62,13 +62,21 @@ namespace MTApiService
}
//init local pipe host
var localUrl = CreateConnectionAddress(null, port, true);
var localServiceHost = CreateServiceHost(localUrl, true);
var localPipeUrl = CreateConnectionAddress(null, port, true);
var localPipeServiceHost = CreateServiceHost(localPipeUrl, true);
if (localPipeServiceHost != null)
{
_hosts.Add(localPipeServiceHost);
}
//init localhost
var localUrl = CreateConnectionAddress("localhost", port, false);
var localServiceHost = CreateServiceHost(localUrl, false);
if (localServiceHost != null)
{
_hosts.Add(localServiceHost);
}
//init network hosts
var dnsHostName = Dns.GetHostName();
var ips = Dns.GetHostEntry(dnsHostName);
+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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.25.0")]
[assembly: AssemblyFileVersion("1.0.25.0")]
[assembly: AssemblyVersion("1.0.27.0")]
[assembly: AssemblyFileVersion("1.0.27.0")]
+67 -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
, 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
, 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
, 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)
{
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)
{
double 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)
@@ -740,7 +786,7 @@ namespace MtApi
#endregion
#region Account Information
#region Account functions
public double AccountBalance()
{
@@ -823,6 +869,12 @@ namespace MtApi
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
#region Common Function
@@ -2186,6 +2238,15 @@ namespace MtApi
#endregion
#region Backtesting functions
public void UnlockTicks()
{
SendCommand<object>(MtCommandType.UnlockTicks, null);
}
#endregion
#region Private Methods
private MtClient Client
{
+4 -1
View File
@@ -227,6 +227,9 @@
ObjectSet = 231,
ObjectSetFiboDescription = 232,
ObjectSetText = 233,
ObjectType = 234
ObjectType = 234,
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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.33.0")]
[assembly: AssemblyFileVersion("1.0.33.0")]
[assembly: AssemblyVersion("1.0.37.0")]
[assembly: AssemblyFileVersion("1.0.37.0")]
+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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.11.1")]
[assembly: AssemblyFileVersion("1.0.11.1")]
[assembly: AssemblyVersion("1.0.12")]
[assembly: AssemblyFileVersion("1.0.12")]
+141 -34
View File
@@ -197,9 +197,18 @@
this.button38 = new System.Windows.Forms.Button();
this.button37 = new System.Windows.Forms.Button();
this.tabPage10 = new System.Windows.Forms.TabPage();
this.button68 = new System.Windows.Forms.Button();
this.comboBox11 = new System.Windows.Forms.ComboBox();
this.button4 = new System.Windows.Forms.Button();
this.button68 = 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();
@@ -218,6 +227,7 @@
this.tabPage8.SuspendLayout();
this.tabPage9.SuspendLayout();
this.tabPage10.SuspendLayout();
this.tabPage11.SuspendLayout();
this.SuspendLayout();
//
// textBoxServerName
@@ -240,7 +250,7 @@
this.buttonConnect.Location = new System.Drawing.Point(17, 73);
this.buttonConnect.Name = "buttonConnect";
this.buttonConnect.Size = new System.Drawing.Size(75, 23);
this.buttonConnect.TabIndex = 4;
this.buttonConnect.TabIndex = 2;
this.buttonConnect.Text = "Connect";
this.buttonConnect.UseVisualStyleBackColor = true;
this.buttonConnect.Click += new System.EventHandler(this.buttonConnect_Click);
@@ -322,7 +332,7 @@
this.checkBox2.Location = new System.Drawing.Point(6, 296);
this.checkBox2.Name = "checkBox2";
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.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
@@ -343,7 +353,7 @@
this.listViewQuotes.MultiSelect = false;
this.listViewQuotes.Name = "listViewQuotes";
this.listViewQuotes.Size = new System.Drawing.Size(292, 271);
this.listViewQuotes.TabIndex = 15;
this.listViewQuotes.TabIndex = 4;
this.listViewQuotes.UseCompatibleStateImageBehavior = false;
this.listViewQuotes.View = System.Windows.Forms.View.Details;
this.listViewQuotes.SelectedIndexChanged += new System.EventHandler(this.listViewQuotes_SelectedIndexChanged);
@@ -400,6 +410,7 @@
this.tabControl1.Controls.Add(this.tabPage8);
this.tabControl1.Controls.Add(this.tabPage9);
this.tabControl1.Controls.Add(this.tabPage10);
this.tabControl1.Controls.Add(this.tabPage11);
this.tabControl1.Location = new System.Drawing.Point(324, 12);
this.tabControl1.Multiline = true;
this.tabControl1.Name = "tabControl1";
@@ -442,7 +453,7 @@
this.button22.Location = new System.Drawing.Point(216, 293);
this.button22.Name = "button22";
this.button22.Size = new System.Drawing.Size(75, 23);
this.button22.TabIndex = 19;
this.button22.TabIndex = 31;
this.button22.Text = "OrderModify";
this.button22.UseVisualStyleBackColor = true;
this.button22.Click += new System.EventHandler(this.button22_Click);
@@ -452,7 +463,7 @@
this.button21.Location = new System.Drawing.Point(216, 264);
this.button21.Name = "button21";
this.button21.Size = new System.Drawing.Size(75, 23);
this.button21.TabIndex = 18;
this.button21.TabIndex = 30;
this.button21.Text = "OrderDelete";
this.button21.UseVisualStyleBackColor = true;
this.button21.Click += new System.EventHandler(this.button21_Click);
@@ -471,7 +482,7 @@
this.textBoxOppositeTicket.Location = new System.Drawing.Point(303, 239);
this.textBoxOppositeTicket.Name = "textBoxOppositeTicket";
this.textBoxOppositeTicket.Size = new System.Drawing.Size(100, 20);
this.textBoxOppositeTicket.TabIndex = 16;
this.textBoxOppositeTicket.TabIndex = 28;
this.textBoxOppositeTicket.Text = "0";
//
// button15
@@ -479,7 +490,7 @@
this.button15.Location = new System.Drawing.Point(410, 237);
this.button15.Name = "button15";
this.button15.Size = new System.Drawing.Size(92, 23);
this.button15.TabIndex = 15;
this.button15.TabIndex = 29;
this.button15.Text = "OrderCloseBy";
this.button15.UseVisualStyleBackColor = true;
this.button15.Click += new System.EventHandler(this.button15_Click);
@@ -490,7 +501,7 @@
this.checkBox1.Location = new System.Drawing.Point(297, 208);
this.checkBox1.Name = "checkBox1";
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.UseVisualStyleBackColor = true;
//
@@ -499,7 +510,7 @@
this.button20.Location = new System.Drawing.Point(216, 202);
this.button20.Name = "button20";
this.button20.Size = new System.Drawing.Size(75, 23);
this.button20.TabIndex = 13;
this.button20.TabIndex = 26;
this.button20.Text = "OrderClose";
this.button20.UseVisualStyleBackColor = true;
this.button20.Click += new System.EventHandler(this.button20_Click);
@@ -509,7 +520,7 @@
this.button17.Location = new System.Drawing.Point(558, 158);
this.button17.Name = "button17";
this.button17.Size = new System.Drawing.Size(75, 23);
this.button17.TabIndex = 12;
this.button17.TabIndex = 25;
this.button17.Text = "GetOrders";
this.button17.UseVisualStyleBackColor = true;
this.button17.Click += new System.EventHandler(this.button17_Click);
@@ -524,7 +535,7 @@
this.comboBox2.Location = new System.Drawing.Point(341, 158);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(114, 21);
this.comboBox2.TabIndex = 11;
this.comboBox2.TabIndex = 23;
//
// comboBox1
//
@@ -536,14 +547,14 @@
this.comboBox1.Location = new System.Drawing.Point(216, 158);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(119, 21);
this.comboBox1.TabIndex = 10;
this.comboBox1.TabIndex = 22;
//
// button16
//
this.button16.Location = new System.Drawing.Point(461, 158);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(75, 23);
this.button16.TabIndex = 9;
this.button16.TabIndex = 24;
this.button16.Text = "GetOrder";
this.button16.UseVisualStyleBackColor = true;
this.button16.Click += new System.EventHandler(this.button16_Click);
@@ -562,7 +573,7 @@
this.textBoxIndexTicket.Location = new System.Drawing.Point(290, 132);
this.textBoxIndexTicket.Name = "textBoxIndexTicket";
this.textBoxIndexTicket.Size = new System.Drawing.Size(109, 20);
this.textBoxIndexTicket.TabIndex = 7;
this.textBoxIndexTicket.TabIndex = 21;
this.textBoxIndexTicket.Text = "0";
//
// comboBoxSelectedCommand
@@ -596,7 +607,7 @@
this.comboBoxSelectedCommand.Location = new System.Drawing.Point(213, 344);
this.comboBoxSelectedCommand.Name = "comboBoxSelectedCommand";
this.comboBoxSelectedCommand.Size = new System.Drawing.Size(121, 21);
this.comboBoxSelectedCommand.TabIndex = 6;
this.comboBoxSelectedCommand.TabIndex = 32;
//
// label15
//
@@ -624,14 +635,14 @@
this.listBoxClosedOrders.Location = new System.Drawing.Point(213, 85);
this.listBoxClosedOrders.Name = "listBoxClosedOrders";
this.listBoxClosedOrders.Size = new System.Drawing.Size(419, 43);
this.listBoxClosedOrders.TabIndex = 5;
this.listBoxClosedOrders.TabIndex = 20;
//
// button2
//
this.button2.Location = new System.Drawing.Point(356, 342);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(87, 23);
this.button2.TabIndex = 2;
this.button2.TabIndex = 33;
this.button2.Text = "Execute";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
@@ -675,7 +686,7 @@
this.button19.Location = new System.Drawing.Point(87, 336);
this.button19.Name = "button19";
this.button19.Size = new System.Drawing.Size(75, 23);
this.button19.TabIndex = 15;
this.button19.TabIndex = 18;
this.button19.Text = "Sell";
this.button19.UseVisualStyleBackColor = true;
this.button19.Click += new System.EventHandler(this.button19_Click);
@@ -685,7 +696,7 @@
this.button18.Location = new System.Drawing.Point(6, 336);
this.button18.Name = "button18";
this.button18.Size = new System.Drawing.Size(75, 23);
this.button18.TabIndex = 14;
this.button18.TabIndex = 17;
this.button18.Text = "Buy";
this.button18.UseVisualStyleBackColor = true;
this.button18.Click += new System.EventHandler(this.button18_Click);
@@ -700,28 +711,28 @@
this.comboBoxOrderColor.Location = new System.Drawing.Point(69, 281);
this.comboBoxOrderColor.Name = "comboBoxOrderColor";
this.comboBoxOrderColor.Size = new System.Drawing.Size(121, 21);
this.comboBoxOrderColor.TabIndex = 13;
this.comboBoxOrderColor.TabIndex = 15;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(70, 255);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(120, 20);
this.textBox2.TabIndex = 11;
this.textBox2.TabIndex = 14;
//
// textBoxOrderMagic
//
this.textBoxOrderMagic.Location = new System.Drawing.Point(70, 229);
this.textBoxOrderMagic.Name = "textBoxOrderMagic";
this.textBoxOrderMagic.Size = new System.Drawing.Size(120, 20);
this.textBoxOrderMagic.TabIndex = 11;
this.textBoxOrderMagic.TabIndex = 13;
//
// textBoxOrderComment
//
this.textBoxOrderComment.Location = new System.Drawing.Point(70, 203);
this.textBoxOrderComment.Name = "textBoxOrderComment";
this.textBoxOrderComment.Size = new System.Drawing.Size(120, 20);
this.textBoxOrderComment.TabIndex = 11;
this.textBoxOrderComment.TabIndex = 12;
//
// textBoxOrderProffit
//
@@ -878,7 +889,7 @@
this.button1.Location = new System.Drawing.Point(120, 307);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 12;
this.button1.TabIndex = 16;
this.button1.Text = "Send";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
@@ -909,7 +920,7 @@
this.listBoxSendedOrders.Name = "listBoxSendedOrders";
this.listBoxSendedOrders.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
this.listBoxSendedOrders.Size = new System.Drawing.Size(419, 43);
this.listBoxSendedOrders.TabIndex = 1;
this.listBoxSendedOrders.TabIndex = 19;
//
// tabPage1
//
@@ -1106,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);
@@ -2008,6 +2026,16 @@
this.tabPage10.Text = "Object Functions";
this.tabPage10.UseVisualStyleBackColor = true;
//
// button68
//
this.button68.Location = new System.Drawing.Point(6, 39);
this.button68.Name = "button68";
this.button68.Size = new System.Drawing.Size(75, 23);
this.button68.TabIndex = 2;
this.button68.Text = "ObjectName";
this.button68.UseVisualStyleBackColor = true;
this.button68.Click += new System.EventHandler(this.button68_Click);
//
// comboBox11
//
this.comboBox11.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -2027,15 +2055,84 @@
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button68
// tabPage11
//
this.button68.Location = new System.Drawing.Point(6, 39);
this.button68.Name = "button68";
this.button68.Size = new System.Drawing.Size(75, 23);
this.button68.TabIndex = 2;
this.button68.Text = "ObjectName";
this.button68.UseVisualStyleBackColor = true;
this.button68.Click += new System.EventHandler(this.button68_Click);
this.tabPage11.Controls.Add(this.button69);
this.tabPage11.Location = new System.Drawing.Point(4, 40);
this.tabPage11.Name = "tabPage11";
this.tabPage11.Padding = new System.Windows.Forms.Padding(3);
this.tabPage11.Size = new System.Drawing.Size(638, 383);
this.tabPage11.TabIndex = 11;
this.tabPage11.Text = "Backtesting";
this.tabPage11.UseVisualStyleBackColor = true;
//
// button69
//
this.button69.Location = new System.Drawing.Point(6, 6);
this.button69.Name = "button69";
this.button69.Size = new System.Drawing.Size(75, 23);
this.button69.TabIndex = 4;
this.button69.Text = "UnlockTicks";
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
//
@@ -2081,6 +2178,7 @@
this.tabPage9.ResumeLayout(false);
this.tabPage9.PerformLayout();
this.tabPage10.ResumeLayout(false);
this.tabPage11.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -2259,6 +2357,15 @@
private System.Windows.Forms.ComboBox comboBox11;
private System.Windows.Forms.TextBox textBoxChartId;
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;
}
}
+72 -21
View File
@@ -141,7 +141,7 @@ namespace TestApiClientUI
private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
{
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask);
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask);
}
private void _apiClient_QuoteUpdate(object sender, MtQuoteEventArgs e)
@@ -673,6 +673,8 @@ namespace TestApiClientUI
//OrderSend
private async void button1_Click(object sender, EventArgs e)
{
var ticket = -1;
var symbol = textBoxOrderSymbol.Text;
var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex;
@@ -693,28 +695,43 @@ namespace TestApiClientUI
var comment = textBoxOrderComment.Text;
int magic;
int.TryParse(textBoxOrderMagic.Text, out magic);
var expiration = DateTime.Now;
Color arrowColor;
switch (comboBoxOrderColor.SelectedIndex)
if (string.IsNullOrEmpty(comment))
{
case 0:
arrowColor = Color.Green;
break;
case 1:
arrowColor = Color.Blue;
break;
case 2:
arrowColor = Color.Red;
break;
default:
return;
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit));
}
else
{
int magic;
if (!int.TryParse(textBoxOrderMagic.Text, out magic))
{
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment));
}
else
{
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}");
}
@@ -1402,5 +1419,39 @@ namespace TestApiClientUI
var result = await Execute(() => _apiClient.ObjectName(chartId, objectIndex));
PrintLog($"ObjectName result: {result}");
}
private void button69_Click(object sender, EventArgs e)
{
_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);
}
}
//+------------------------------------------------------------------+