Issue #32: Added function ChartRedraw

This commit is contained in:
vdemydiuk
2016-12-12 17:29:52 +02:00
parent 9ef970cf1e
commit f5f13a13cc
11 changed files with 405 additions and 445 deletions
+24 -1
View File
@@ -12,7 +12,8 @@ namespace MTApiService
{
static IEnumerable<Type> GetKnownTypes()
{
return new Type[] { typeof(MtResponseInt), typeof(MtResponseDouble),
return new Type[] { typeof(MtResponseObject),
typeof(MtResponseInt), typeof(MtResponseDouble),
typeof(MtResponseString), typeof(MtResponseBool),
typeof(MtResponseLong), typeof(MtResponseULong),
typeof(MtResponseDoubleArray), typeof(MtResponseIntArray),
@@ -22,6 +23,28 @@ namespace MTApiService
}
public abstract object GetValue();
[DataMember]
public int ErrorCode { get; set; }
}
[DataContract]
public class MtResponseObject : MtResponse
{
public MtResponseObject(object value)
{
Value = value;
}
[DataMember]
public object Value { get; private set; }
public override object GetValue() { return Value; }
public override string ToString()
{
return Value?.ToString() ?? string.Empty;
}
}
[DataContract]
+108 -186
View File
@@ -4,7 +4,8 @@
#include "MT4Handler.h"
#include "Windows.h"
#include < vcclr.h >
#include <vcclr.h>
#include <functional>
using namespace System;
using namespace MTApiService;
@@ -17,6 +18,8 @@ using namespace System::IO;
using namespace System::Collections::Generic;
using namespace System::Diagnostics;
#define _DLLAPI extern "C" __declspec(dllexport)
void convertSystemString(wchar_t* dest, String^ src)
{
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
@@ -24,264 +27,183 @@ void convertSystemString(wchar_t* dest, String^ src)
dest[wcslen(wch)] = '\0';
}
int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default_value)
{
T result = default_value;
try
{
result = func();
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
}
return result;
}
_DLLAPI bool _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
{
return Execute<bool>([&expertHandle, &port, symbol, &bid, &ask]() {
MT4Handler^ mtHandler = gcnew MT4Handler();
MtServerInstance::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHandler);
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MTConnector:initExpert(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall deinitExpert(int expertHandle, wchar_t* err)
_DLLAPI bool _stdcall deinitExpert(int expertHandle, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle]() {
MtServerInstance::GetInstance()->DeinitExpert(expertHandle);
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MTConnector:deinitExpert(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
_DLLAPI bool _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, symbol, &bid, &ask]() {
MtServerInstance::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MTConnector:updateQuote(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_t* err)
_DLLAPI bool _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &eventType, payload]() {
MtServerInstance::GetInstance()->SendEvent(expertHandle, eventType, gcnew String(payload));
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MTConnector:updateTimeBar(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendIntResponse(int expertHandle, int response)
_DLLAPI bool _stdcall sendIntResponse(int expertHandle, int response, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &response]() {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendIntResponse(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendBooleanResponse(int expertHandle, int response)
_DLLAPI bool _stdcall sendBooleanResponse(int expertHandle, bool response, wchar_t* err)
{
try
{
bool value = (response != 0) ? true : false;
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendBooleanResponse(): " + e->Message);
return 0;
}
return 1;
return Execute<bool>([&expertHandle, &response]() {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(response));
return true;
}, err, false);
}
int _stdcall sendDoubleResponse(int expertHandle, double response)
_DLLAPI bool _stdcall sendDoubleResponse(int expertHandle, double response, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &response]() {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendDoubleResponse(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendStringResponse(int expertHandle, wchar_t* response)
_DLLAPI bool _stdcall sendStringResponse(int expertHandle, wchar_t* response, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, response]() {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendStringResponse(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendVoidResponse(int expertHandle)
_DLLAPI bool _stdcall sendErrorResponse(int expertHandle, int code, wchar_t* message, wchar_t* err)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, nullptr);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendVoidResponse(): " + e->Message);
return 0;
}
return 1;
return Execute<bool>([&expertHandle, &code, message]() {
MtResponseString^ res = gcnew MtResponseString(gcnew String(message));
res->ErrorCode = code;
MtServerInstance::GetInstance()->SendResponse(expertHandle, res);
return true;
}, err, false);
}
int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size)
_DLLAPI bool _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle]() {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseObject(nullptr));
return true;
}, err, false);
}
_DLLAPI bool _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size, wchar_t* err)
{
return Execute<bool>([&expertHandle, values, &size]() {
array<double>^ list = gcnew array<double>(size);
for(int i = 0; i < size; i++)
for (int i = 0; i < size; i++)
{
list[i] = values[i];
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendDoubleArrayResponse(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size)
_DLLAPI bool _stdcall sendIntArrayResponse(int expertHandle, int* values, int size, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, values, &size]() {
array<int>^ list = gcnew array<int>(size);
for(int i = 0; i < size; i++)
for (int i = 0; i < size; i++)
{
list[i] = values[i];
}
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendIntArrayResponse(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall sendLongResponse(int expertHandle, __int64 response)
_DLLAPI bool _stdcall sendLongResponse(int expertHandle, __int64 response, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &response]() {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendLongResponse(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall getCommandType(int expertHandle, int* res)
_DLLAPI bool _stdcall getCommandType(int expertHandle, int* res, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, res]() {
*res = MtServerInstance::GetInstance()->GetCommandType(expertHandle);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:getCommandType(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall getIntValue(int expertHandle, int paramIndex, int* res)
_DLLAPI bool _stdcall getIntValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &paramIndex, res]() {
*res = (int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:getIntValue(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res)
_DLLAPI bool _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &paramIndex, res]() {
*res = (double)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:getDoubleValue(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res)
_DLLAPI bool _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res, wchar_t* err)
{
try
{
return Execute<bool>([&expertHandle, &paramIndex, res]() {
convertSystemString(res, (String^)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:getStringValue(): " + e->Message);
return 0;
}
return 1;
return true;
}, err, false);
}
int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
_DLLAPI bool _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
{
try
{
bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = val == true ? 1 : 0;
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
return 0;
}
return 1;
return Execute<bool>([&expertHandle, &paramIndex, res]() {
*res = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return true;
}, err, false);
}
_DLLAPI bool _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res, wchar_t* err)
{
return Execute<bool>([&expertHandle, &paramIndex, res]() {
*res = (__int64)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
return true;
}, err, false);
}
-19
View File
@@ -1,19 +0,0 @@
LIBRARY MTConnector
EXPORTS initExpert
deinitExpert
updateQuote
sendEvent
sendIntResponse
sendBooleanResponse
sendDoubleResponse
sendStringResponse
sendVoidResponse
sendDoubleArrayResponse
sendIntArrayResponse
sendLongResponse
getCommandType
getIntValue
getDoubleValue
getStringValue
getBooleanValue
-5
View File
@@ -96,7 +96,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -109,7 +108,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -121,7 +119,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -133,7 +130,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@@ -154,7 +150,6 @@
</ItemGroup>
<ItemGroup>
<None Include="app.ico" />
<None Include="MTConnector.def" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
-3
View File
@@ -44,9 +44,6 @@
<None Include="app.ico">
<Filter>Resource Files</Filter>
</None>
<None Include="MTConnector.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="app.rc">
+14
View File
@@ -1722,6 +1722,15 @@ namespace MtApi
{
return SendCommand<long>(MtCommandType.ChartId, null);
}
///<summary>
///This function calls a forced redrawing of a specified chart.
///</summary>
public void ChartRedraw(long chartId = 0)
{
var commandParameters = new ArrayList { chartId };
SendCommand<object>(MtCommandType.ChartRedraw, commandParameters);
}
#endregion
#region Private Methods
@@ -1872,6 +1881,11 @@ namespace MtApi
throw new MtExecutionException(MtErrorCode.MtApiCustomError, "Response from MetaTrader is null");
}
if (response.ErrorCode != 0)
{
throw new MtExecutionException((MtErrorCode)response.ErrorCode, response.ToString());
}
var responseValue = response.GetValue();
return responseValue != null ? (T)responseValue : default(T);
}
+2 -1
View File
@@ -197,6 +197,7 @@
SymbolName = 201,
SymbolSelect = 202,
SymbolInfoInteger = 203,
ChartId = 206
ChartId = 206,
ChartRedraw = 207
}
}
+177 -176
View File
@@ -113,6 +113,22 @@
this.label22 = new System.Windows.Forms.Label();
this.textBoxErrorCode = new System.Windows.Forms.TextBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.button67 = new System.Windows.Forms.Button();
this.button66 = new System.Windows.Forms.Button();
this.button65 = new System.Windows.Forms.Button();
this.button64 = new System.Windows.Forms.Button();
this.button63 = new System.Windows.Forms.Button();
this.button62 = new System.Windows.Forms.Button();
this.button61 = new System.Windows.Forms.Button();
this.button60 = new System.Windows.Forms.Button();
this.button59 = new System.Windows.Forms.Button();
this.button58 = new System.Windows.Forms.Button();
this.button57 = new System.Windows.Forms.Button();
this.button56 = new System.Windows.Forms.Button();
this.button55 = new System.Windows.Forms.Button();
this.button54 = new System.Windows.Forms.Button();
this.button53 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.comboBoxAccountInfoCmd = new System.Windows.Forms.ComboBox();
this.textBoxAccountInfoVolume = new System.Windows.Forms.TextBox();
this.label25 = new System.Windows.Forms.Label();
@@ -179,22 +195,6 @@
this.tabPage9 = new System.Windows.Forms.TabPage();
this.button38 = new System.Windows.Forms.Button();
this.button37 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button53 = new System.Windows.Forms.Button();
this.button54 = new System.Windows.Forms.Button();
this.button55 = new System.Windows.Forms.Button();
this.button56 = new System.Windows.Forms.Button();
this.button57 = new System.Windows.Forms.Button();
this.button58 = new System.Windows.Forms.Button();
this.button59 = new System.Windows.Forms.Button();
this.button60 = new System.Windows.Forms.Button();
this.button61 = new System.Windows.Forms.Button();
this.button62 = new System.Windows.Forms.Button();
this.button63 = new System.Windows.Forms.Button();
this.button64 = new System.Windows.Forms.Button();
this.button65 = new System.Windows.Forms.Button();
this.button66 = new System.Windows.Forms.Button();
this.button67 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.groupBox2.SuspendLayout();
@@ -1129,6 +1129,166 @@
this.tabPage3.Text = "Account Information";
this.tabPage3.UseVisualStyleBackColor = true;
//
// button67
//
this.button67.Location = new System.Drawing.Point(157, 33);
this.button67.Name = "button67";
this.button67.Size = new System.Drawing.Size(145, 23);
this.button67.TabIndex = 14;
this.button67.Text = "AccountStopoutMode";
this.button67.UseVisualStyleBackColor = true;
this.button67.Click += new System.EventHandler(this.button67_Click);
//
// button66
//
this.button66.Location = new System.Drawing.Point(157, 4);
this.button66.Name = "button66";
this.button66.Size = new System.Drawing.Size(145, 23);
this.button66.TabIndex = 14;
this.button66.Text = "AccountStopoutLevel";
this.button66.UseVisualStyleBackColor = true;
this.button66.Click += new System.EventHandler(this.button66_Click);
//
// button65
//
this.button65.Location = new System.Drawing.Point(6, 350);
this.button65.Name = "button65";
this.button65.Size = new System.Drawing.Size(145, 23);
this.button65.TabIndex = 14;
this.button65.Text = "AccountServer";
this.button65.UseVisualStyleBackColor = true;
this.button65.Click += new System.EventHandler(this.button65_Click);
//
// button64
//
this.button64.Location = new System.Drawing.Point(6, 321);
this.button64.Name = "button64";
this.button64.Size = new System.Drawing.Size(145, 23);
this.button64.TabIndex = 14;
this.button64.Text = "AccountProfit";
this.button64.UseVisualStyleBackColor = true;
this.button64.Click += new System.EventHandler(this.button64_Click);
//
// button63
//
this.button63.Location = new System.Drawing.Point(6, 292);
this.button63.Name = "button63";
this.button63.Size = new System.Drawing.Size(145, 23);
this.button63.TabIndex = 14;
this.button63.Text = "AccountNumber";
this.button63.UseVisualStyleBackColor = true;
this.button63.Click += new System.EventHandler(this.button63_Click);
//
// button62
//
this.button62.Location = new System.Drawing.Point(6, 263);
this.button62.Name = "button62";
this.button62.Size = new System.Drawing.Size(145, 23);
this.button62.TabIndex = 14;
this.button62.Text = "AccountName";
this.button62.UseVisualStyleBackColor = true;
this.button62.Click += new System.EventHandler(this.button62_Click);
//
// button61
//
this.button61.Location = new System.Drawing.Point(6, 235);
this.button61.Name = "button61";
this.button61.Size = new System.Drawing.Size(145, 23);
this.button61.TabIndex = 14;
this.button61.Text = "AccountMargin";
this.button61.UseVisualStyleBackColor = true;
this.button61.Click += new System.EventHandler(this.button61_Click);
//
// button60
//
this.button60.Location = new System.Drawing.Point(6, 206);
this.button60.Name = "button60";
this.button60.Size = new System.Drawing.Size(145, 23);
this.button60.TabIndex = 14;
this.button60.Text = "AccountLeverage";
this.button60.UseVisualStyleBackColor = true;
this.button60.Click += new System.EventHandler(this.button60_Click);
//
// button59
//
this.button59.Location = new System.Drawing.Point(6, 177);
this.button59.Name = "button59";
this.button59.Size = new System.Drawing.Size(145, 23);
this.button59.TabIndex = 14;
this.button59.Text = "AccountFreeMarginMode";
this.button59.UseVisualStyleBackColor = true;
this.button59.Click += new System.EventHandler(this.button59_Click);
//
// button58
//
this.button58.Location = new System.Drawing.Point(190, 159);
this.button58.Name = "button58";
this.button58.Size = new System.Drawing.Size(145, 23);
this.button58.TabIndex = 14;
this.button58.Text = "AccountFreeMarginCheck";
this.button58.UseVisualStyleBackColor = true;
this.button58.Click += new System.EventHandler(this.button58_Click);
//
// button57
//
this.button57.Location = new System.Drawing.Point(6, 148);
this.button57.Name = "button57";
this.button57.Size = new System.Drawing.Size(145, 23);
this.button57.TabIndex = 14;
this.button57.Text = "AccountFreeMargin";
this.button57.UseVisualStyleBackColor = true;
this.button57.Click += new System.EventHandler(this.button57_Click);
//
// button56
//
this.button56.Location = new System.Drawing.Point(6, 119);
this.button56.Name = "button56";
this.button56.Size = new System.Drawing.Size(145, 23);
this.button56.TabIndex = 14;
this.button56.Text = "AccountEquity";
this.button56.UseVisualStyleBackColor = true;
this.button56.Click += new System.EventHandler(this.button56_Click);
//
// button55
//
this.button55.Location = new System.Drawing.Point(6, 90);
this.button55.Name = "button55";
this.button55.Size = new System.Drawing.Size(145, 23);
this.button55.TabIndex = 13;
this.button55.Text = "AccountCurrency";
this.button55.UseVisualStyleBackColor = true;
this.button55.Click += new System.EventHandler(this.button55_Click);
//
// button54
//
this.button54.Location = new System.Drawing.Point(6, 62);
this.button54.Name = "button54";
this.button54.Size = new System.Drawing.Size(145, 23);
this.button54.TabIndex = 12;
this.button54.Text = "AccountCompany";
this.button54.UseVisualStyleBackColor = true;
this.button54.Click += new System.EventHandler(this.button54_Click);
//
// button53
//
this.button53.Location = new System.Drawing.Point(6, 33);
this.button53.Name = "button53";
this.button53.Size = new System.Drawing.Size(145, 23);
this.button53.TabIndex = 11;
this.button53.Text = "AccountCredit";
this.button53.UseVisualStyleBackColor = true;
this.button53.Click += new System.EventHandler(this.button53_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(6, 4);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(145, 23);
this.button3.TabIndex = 10;
this.button3.Text = "AccountBalance";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// comboBoxAccountInfoCmd
//
this.comboBoxAccountInfoCmd.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -1808,6 +1968,7 @@
this.button38.TabIndex = 1;
this.button38.Text = "ChartRedraw";
this.button38.UseVisualStyleBackColor = true;
this.button38.Click += new System.EventHandler(this.button38_Click);
//
// button37
//
@@ -1819,166 +1980,6 @@
this.button37.UseVisualStyleBackColor = true;
this.button37.Click += new System.EventHandler(this.button37_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(6, 4);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(145, 23);
this.button3.TabIndex = 10;
this.button3.Text = "AccountBalance";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button53
//
this.button53.Location = new System.Drawing.Point(6, 33);
this.button53.Name = "button53";
this.button53.Size = new System.Drawing.Size(145, 23);
this.button53.TabIndex = 11;
this.button53.Text = "AccountCredit";
this.button53.UseVisualStyleBackColor = true;
this.button53.Click += new System.EventHandler(this.button53_Click);
//
// button54
//
this.button54.Location = new System.Drawing.Point(6, 62);
this.button54.Name = "button54";
this.button54.Size = new System.Drawing.Size(145, 23);
this.button54.TabIndex = 12;
this.button54.Text = "AccountCompany";
this.button54.UseVisualStyleBackColor = true;
this.button54.Click += new System.EventHandler(this.button54_Click);
//
// button55
//
this.button55.Location = new System.Drawing.Point(6, 90);
this.button55.Name = "button55";
this.button55.Size = new System.Drawing.Size(145, 23);
this.button55.TabIndex = 13;
this.button55.Text = "AccountCurrency";
this.button55.UseVisualStyleBackColor = true;
this.button55.Click += new System.EventHandler(this.button55_Click);
//
// button56
//
this.button56.Location = new System.Drawing.Point(6, 119);
this.button56.Name = "button56";
this.button56.Size = new System.Drawing.Size(145, 23);
this.button56.TabIndex = 14;
this.button56.Text = "AccountEquity";
this.button56.UseVisualStyleBackColor = true;
this.button56.Click += new System.EventHandler(this.button56_Click);
//
// button57
//
this.button57.Location = new System.Drawing.Point(6, 148);
this.button57.Name = "button57";
this.button57.Size = new System.Drawing.Size(145, 23);
this.button57.TabIndex = 14;
this.button57.Text = "AccountFreeMargin";
this.button57.UseVisualStyleBackColor = true;
this.button57.Click += new System.EventHandler(this.button57_Click);
//
// button58
//
this.button58.Location = new System.Drawing.Point(190, 159);
this.button58.Name = "button58";
this.button58.Size = new System.Drawing.Size(145, 23);
this.button58.TabIndex = 14;
this.button58.Text = "AccountFreeMarginCheck";
this.button58.UseVisualStyleBackColor = true;
this.button58.Click += new System.EventHandler(this.button58_Click);
//
// button59
//
this.button59.Location = new System.Drawing.Point(6, 177);
this.button59.Name = "button59";
this.button59.Size = new System.Drawing.Size(145, 23);
this.button59.TabIndex = 14;
this.button59.Text = "AccountFreeMarginMode";
this.button59.UseVisualStyleBackColor = true;
this.button59.Click += new System.EventHandler(this.button59_Click);
//
// button60
//
this.button60.Location = new System.Drawing.Point(6, 206);
this.button60.Name = "button60";
this.button60.Size = new System.Drawing.Size(145, 23);
this.button60.TabIndex = 14;
this.button60.Text = "AccountLeverage";
this.button60.UseVisualStyleBackColor = true;
this.button60.Click += new System.EventHandler(this.button60_Click);
//
// button61
//
this.button61.Location = new System.Drawing.Point(6, 235);
this.button61.Name = "button61";
this.button61.Size = new System.Drawing.Size(145, 23);
this.button61.TabIndex = 14;
this.button61.Text = "AccountMargin";
this.button61.UseVisualStyleBackColor = true;
this.button61.Click += new System.EventHandler(this.button61_Click);
//
// button62
//
this.button62.Location = new System.Drawing.Point(6, 263);
this.button62.Name = "button62";
this.button62.Size = new System.Drawing.Size(145, 23);
this.button62.TabIndex = 14;
this.button62.Text = "AccountName";
this.button62.UseVisualStyleBackColor = true;
this.button62.Click += new System.EventHandler(this.button62_Click);
//
// button63
//
this.button63.Location = new System.Drawing.Point(6, 292);
this.button63.Name = "button63";
this.button63.Size = new System.Drawing.Size(145, 23);
this.button63.TabIndex = 14;
this.button63.Text = "AccountNumber";
this.button63.UseVisualStyleBackColor = true;
this.button63.Click += new System.EventHandler(this.button63_Click);
//
// button64
//
this.button64.Location = new System.Drawing.Point(6, 321);
this.button64.Name = "button64";
this.button64.Size = new System.Drawing.Size(145, 23);
this.button64.TabIndex = 14;
this.button64.Text = "AccountProfit";
this.button64.UseVisualStyleBackColor = true;
this.button64.Click += new System.EventHandler(this.button64_Click);
//
// button65
//
this.button65.Location = new System.Drawing.Point(6, 350);
this.button65.Name = "button65";
this.button65.Size = new System.Drawing.Size(145, 23);
this.button65.TabIndex = 14;
this.button65.Text = "AccountServer";
this.button65.UseVisualStyleBackColor = true;
this.button65.Click += new System.EventHandler(this.button65_Click);
//
// button66
//
this.button66.Location = new System.Drawing.Point(157, 4);
this.button66.Name = "button66";
this.button66.Size = new System.Drawing.Size(145, 23);
this.button66.TabIndex = 14;
this.button66.Text = "AccountStopoutLevel";
this.button66.UseVisualStyleBackColor = true;
this.button66.Click += new System.EventHandler(this.button66_Click);
//
// button67
//
this.button67.Location = new System.Drawing.Point(157, 33);
this.button67.Name = "button67";
this.button67.Size = new System.Drawing.Size(145, 23);
this.button67.TabIndex = 14;
this.button67.Text = "AccountStopoutMode";
this.button67.UseVisualStyleBackColor = true;
this.button67.Click += new System.EventHandler(this.button67_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+80 -54
View File
@@ -627,9 +627,9 @@ namespace TestApiClientUI
listBoxEventLog.Items.Clear();
}
private async Task<TResult> Execute<TResult>(Func<TResult> func)
private Task<TResult> Execute<TResult>(Func<TResult> func)
{
return await Task.Factory.StartNew(() =>
return Task.Factory.StartNew(() =>
{
var result = default(TResult);
try
@@ -649,6 +649,25 @@ namespace TestApiClientUI
});
}
private Task Execute(Action action)
{
return Task.Factory.StartNew(() =>
{
try
{
action();
}
catch (MtConnectionException ex)
{
PrintLog("MtExecutionException: " + ex.Message);
}
catch (MtExecutionException ex)
{
PrintLog("MtExecutionException: " + ex.Message + "; ErrorCode = " + ex.ErrorCode);
}
});
}
//OrderSend
private async void button1_Click(object sender, EventArgs e)
{
@@ -1100,17 +1119,10 @@ namespace TestApiClientUI
_apiClient.ExecutorHandle = expertHandle;
}
//CharID
private async void button37_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.ChartId());
PrintLog($"CharID: result = {result}");
}
//GetLastError
private async void button40_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.GetLastError());
var result = await Execute(_apiClient.GetLastError);
PrintLog($"GetLastError: result = {result}");
RunOnUiThread(() => { textBoxErrorCode.Text = result.ToString(); });
}
@@ -1140,131 +1152,131 @@ namespace TestApiClientUI
//IsConnected
private async void button41_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsConnected());
var result = await Execute(_apiClient.IsConnected);
PrintLog($"IsConnected: result = {result}");
}
//IsDemo
private async void button42_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsDemo());
var result = await Execute(_apiClient.IsDemo);
PrintLog($"IsDemo: result = {result}");
}
//IsDllsAllowed
private async void button43_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsDllsAllowed());
var result = await Execute(_apiClient.IsDllsAllowed);
PrintLog($"IsDllsAllowed: result = {result}");
}
//IsExpertEnabled
private async void button44_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsExpertEnabled());
var result = await Execute(_apiClient.IsExpertEnabled);
PrintLog($"IsExpertEnabled: result = {result}");
}
//IsLibrariesAllowed
private async void button45_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsLibrariesAllowed());
var result = await Execute(_apiClient.IsLibrariesAllowed);
PrintLog($"IsLibrariesAllowed: result = {result}");
}
//IsOptimization
private async void button46_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsOptimization());
var result = await Execute(_apiClient.IsOptimization);
PrintLog($"IsOptimization: result = {result}");
}
//IsStopped
private async void button47_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsStopped());
var result = await Execute(_apiClient.IsStopped);
PrintLog($"IsStopped: result = {result}");
}
//IsTesting
private async void button48_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsTesting());
var result = await Execute(_apiClient.IsTesting);
PrintLog($"IsTesting: result = {result}");
}
//IsTradeAllowed
private async void button49_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsTradeAllowed());
var result = await Execute(_apiClient.IsTradeAllowed);
PrintLog($"IsTradeAllowed: result = {result}");
}
//IsTradeContextBusy
private async void button50_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsTradeContextBusy());
var result = await Execute(_apiClient.IsTradeContextBusy);
PrintLog($"IsTradeContextBusy: result = {result}");
}
//IsVisualMode
private async void button51_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.IsVisualMode());
var result = await Execute(_apiClient.IsVisualMode);
PrintLog($"IsVisualMode: result = {result}");
}
//UninitializeReason
private async void button52_Click(object sender, EventArgs e)
{
var result = await Execute(() => _apiClient.UninitializeReason());
var result = await Execute(_apiClient.UninitializeReason);
PrintLog($"UninitializeReason: result = {result}");
}
//AccountBalance
private void button3_Click(object sender, EventArgs e)
private async void button3_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountBalance();
var result = await Execute(_apiClient.AccountBalance);
PrintLog($"AccountBalance result: {result}");
}
//AccountCredit
private void button53_Click(object sender, EventArgs e)
private async void button53_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountCredit();
var result = await Execute(_apiClient.AccountCredit);
PrintLog($"AccountCredit result: {result}");
}
//AccountCompany
private void button54_Click(object sender, EventArgs e)
private async void button54_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountCompany();
var result = await Execute(_apiClient.AccountCompany);
PrintLog($"AccountCompany result: {result}");
}
//AccountCurrency
private void button55_Click(object sender, EventArgs e)
private async void button55_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountCurrency();
var result = await Execute(_apiClient.AccountCurrency);
PrintLog($"AccountCurrency result: {result}");
}
//AccountEquity
private void button56_Click(object sender, EventArgs e)
private async void button56_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountEquity();
var result = await Execute(_apiClient.AccountEquity);
PrintLog($"AccountEquity result: {result}");
}
//AccountFreeMargin
private void button57_Click(object sender, EventArgs e)
private async void button57_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountFreeMargin();
var result = await Execute(_apiClient.AccountFreeMargin);
PrintLog($"AccountFreeMargin result: {result}");
}
//AccountFreeMarginCheck
private void button58_Click(object sender, EventArgs e)
private async void button58_Click(object sender, EventArgs e)
{
var symbol = textBoxAccountInfoSymbol.Text;
if (string.IsNullOrEmpty(symbol))
@@ -1285,71 +1297,85 @@ namespace TestApiClientUI
TradeOperation cmd;
Enum.TryParse(comboBoxAccountInfoCmd.Text, out cmd);
var result = _apiClient.AccountFreeMarginCheck(symbol, cmd, volume);
var result = await Execute(() => _apiClient.AccountFreeMarginCheck(symbol, cmd, volume));
PrintLog($"AccountFreeMarginCheck result: {result}");
}
//AccountFreeMarginMode
private void button59_Click(object sender, EventArgs e)
private async void button59_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountFreeMarginMode();
var result = await Execute(_apiClient.AccountFreeMarginMode);
PrintLog($"AccountFreeMarginMode result: {result}");
}
//AccountLeverage
private void button60_Click(object sender, EventArgs e)
private async void button60_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountLeverage();
var result = await Execute(_apiClient.AccountLeverage);
PrintLog($"AccountLeverage result: {result}");
}
//AccountMargin
private void button61_Click(object sender, EventArgs e)
private async void button61_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountMargin();
var result = await Execute(_apiClient.AccountMargin);
PrintLog($"AccountMargin result: {result}");
}
//AccountName
private void button62_Click(object sender, EventArgs e)
private async void button62_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountName();
var result = await Execute(_apiClient.AccountName);
PrintLog($"AccountName result: {result}");
}
//AccountNumber
private void button63_Click(object sender, EventArgs e)
private async void button63_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountNumber();
var result = await Execute(_apiClient.AccountNumber);
PrintLog($"AccountNumber result: {result}");
}
//AccountProfit
private void button64_Click(object sender, EventArgs e)
private async void button64_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountProfit();
var result = await Execute(_apiClient.AccountProfit);
PrintLog($"AccountProfit result: {result}");
}
//AccountServer
private void button65_Click(object sender, EventArgs e)
private async void button65_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountServer();
var result = await Execute(_apiClient.AccountServer);
PrintLog($"AccountServer result: {result}");
}
//AccountStopoutLevel
private void button66_Click(object sender, EventArgs e)
private async void button66_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountStopoutLevel();
var result = await Execute(_apiClient.AccountStopoutLevel);
PrintLog($"AccountStopoutLevel result: {result}");
}
//AccountStopoutMode
private void button67_Click(object sender, EventArgs e)
private async void button67_Click(object sender, EventArgs e)
{
var result = _apiClient.AccountStopoutMode();
var result = await Execute(_apiClient.AccountStopoutMode);
PrintLog($"AccountStopoutMode result: {result}");
}
//CharID
private async void button37_Click(object sender, EventArgs e)
{
var result = await Execute(_apiClient.ChartId);
PrintLog($"CharID: result = {result}");
}
//ChartRedraw
private async void button38_Click(object sender, EventArgs e)
{
await Execute(() => _apiClient.ChartRedraw());
PrintLog($"ChartRedraw: called.");
}
}
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.