Compare commits

...

22 Commits

Author SHA1 Message Date
DW 7175fae18c Fixed WIX error: ICE Internal Error 100. API Returned: 1615. 2017-09-08 17:07:53 +03:00
DW 3c4d8d52ca Revert version mtapi (MT5) to 1.0.12 2017-09-08 16:30:39 +03:00
DW 6873363d41 Fixed build of MT5 test client 2017-09-08 16:07:41 +03:00
DW 947599327a MtApi5 version 1.0.13 2017-09-08 13:05:01 +03:00
DW 5645902a48 Merge branch 'master' into mt5_1_0_13 2017-09-08 12:45:31 +03:00
DW c82787473f Issue #16: Added Mt5Expert into MTApiService. Refactored MT5Connector 2017-09-08 12:44:14 +03:00
Vyacheslav Demidyuk c213fb709a Merge pull request #62 from Tr4Dr/master
Fixed the type of Deviation property in MqlTradeRequest (MT5)
2017-09-08 12:38:29 +03:00
Tr4Dr 2ac29dc871 Fixed the type of Deviation property in MqlTradeRequest (MT5) 2017-09-07 20:08:01 +02:00
DW 1f72b2b790 Refactored MTApiService and connectors projects 2017-09-07 17:46:25 +03:00
Vyacheslav Demidyuk 3a62ff56d7 Merge pull request #61 from Tr4Dr/master
Updated PositionClose function and a fixed warning (MT5)
2017-09-07 12:23:34 +03:00
Unknown d25fe529b4 Fixed warning in function CreateErrorResponse (MT5)
Declaration of 'message' hides global declaration in MtApi5.mq5
2017-09-07 00:21:12 +02:00
Unknown 15538e81f4 Updated PositionClose function (MT5)
Type of the ticket argument changed to ulong, added optional argument: deviation
2017-09-07 00:06:59 +02:00
Tr4Dr a33be3c764 Merge pull request #1 from vdemydiuk/master
Bringing fork up to date
2017-09-06 23:48:13 +02:00
DW 023fe8c7c9 Disable code to print event payload in MQL code (MT4) 2017-09-06 11:47:45 +03:00
DW b77516e324 Issue #59: Added event OnChartEvent into MtApi (MT4) 2017-09-05 18:34:26 +03:00
DW 4b48423c3f Issue #57: Added function PositionSelectByTicket into MQL code 2017-09-04 13:08:30 +03:00
DW 9800177b08 Issue #57: Added function PositionSelectByTicket into C# code 2017-08-29 17:40:23 +03:00
Vyacheslav Demidyuk a33d4a4594 Merge pull request #58 from Tr4Dr/master
Refactored and updated enumerations
2017-08-28 13:56:44 +03:00
Unknown 29722f362d Added Position and PositionBy properties to MqlTradeRequest 2017-08-25 15:32:24 +02:00
Unknown e072343fe1 Missing break after PositionGetSymbol 2017-08-25 15:12:41 +02:00
Unknown acb0c20ca8 Missing break after PositionGetDouble 2017-08-25 15:00:24 +02:00
Unknown 83543fee88 Refactored and updated enumerations 2017-08-25 01:31:57 +02:00
34 changed files with 1194 additions and 1013 deletions
+1 -3
View File
@@ -35,6 +35,4 @@ using namespace System::Security::Permissions;
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
[assembly:CLSCompliantAttribute(true)];
+117 -318
View File
@@ -6,14 +6,15 @@
#include "MT5Handler.h"
#include "Windows.h"
#include < vcclr.h >
#include <vcclr.h>
#include <functional>
using namespace System;
using namespace MTApiService;
using namespace System::Runtime::InteropServices;
using namespace System::Reflection;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace System::Collections::Generic;
using namespace System::Diagnostics;
using namespace System::Security::Cryptography;
using namespace System::Security;
@@ -55,272 +56,143 @@ void convertSystemString(wchar_t* dest, String^ src)
dest[wcslen(wch)] = '\0';
}
bool VerifySignature(System::String^ inputData, System::String^ signature, System::String^ publicKey)
{
bool verifyResult = false;
#define _DLLAPI extern "C" __declspec(dllexport)
template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default_value)
{
T result = default_value;
try
{
DSACryptoServiceProvider^ dsa = gcnew DSACryptoServiceProvider();
dsa->FromXmlString(publicKey);
array<System::Byte>^ data = UTF8Encoding::ASCII->GetBytes(inputData);
array<System::Byte>^ signatureData = Convert::FromBase64String(signature);
verifyResult = dsa->VerifyData(data, signatureData);
}
catch(Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:VerifySignature(): failed. " + e->Message);
verifyResult = false;
}
return verifyResult;
}
bool g_IsVerified = true;
void _stdcall verify(int isDemo, wchar_t* accountName, long accountNumber)
{
if (isDemo != 0)
{
g_IsVerified = true;
return;
}
System::String^ signature = MtRegistryManager::ReadSignatureKey(gcnew String(accountName), accountNumber.ToString());
Resources::ResourceManager^ rm = gcnew Resources::ResourceManager(L"MT5Connector.cl", Assembly::GetExecutingAssembly());
System::String^ inputData = gcnew System::String(accountName);
inputData += accountNumber.ToString();
System::String^ publicKey = rm->GetString(L"cl");
g_IsVerified = VerifySignature(inputData, gcnew System::String(signature), publicKey);
}
int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
{
if (g_IsVerified == false)
{
System::String^ errorVerified = "Verification is failed!\nPlease contact with support.";
convertSystemString(err, errorVerified);
Debug::WriteLine("[ERROR] MT5Connector:initExpert(): not verified");
return 0;
}
try
{
MT5Handler^ mtHander = gcnew MT5Handler();
MtAdapter::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHander);
result = func();
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MT5Connector:initExpert(): " + e->Message);
return 0;
}
return 1;
return result;
}
int _stdcall deinitExpert(int expertHandle, wchar_t* err)
_DLLAPI int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, int isTestMode, wchar_t* err)
{
try
{
MtAdapter::GetInstance()->DeinitExpert(expertHandle);
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MT5Connector:deinitExpert(): " + e->Message);
return 0;
}
return 1;
return Execute<int>([&expertHandle, &port, symbol, &bid, &ask, &isTestMode]() {
bool isTesting = (isTestMode != 0) ? true : false;
auto expert = gcnew Mt5Expert(expertHandle, gcnew String(symbol), bid, ask, gcnew MT5Handler(), isTesting);
MtAdapter::GetInstance()->AddExpert(port, expert);
return 1;
}, err, 0);
}
int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
_DLLAPI int _stdcall deinitExpert(int expertHandle, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle]() {
MtAdapter::GetInstance()->RemoveExpert(expertHandle);
return 1;
}, err, 0);
}
_DLLAPI int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
{
return Execute<int>([&expertHandle, symbol, &bid, &ask]() {
MtAdapter::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
}
catch (Exception^ e)
{
convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MT5Connector:updateQuote(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendIntResponse(int expertHandle, int response)
_DLLAPI int _stdcall sendIntResponse(int expertHandle, int response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &response]() {
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendIntResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendLongResponse(int expertHandle, __int64 response)
_DLLAPI int _stdcall sendLongResponse(int expertHandle, __int64 response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &response]() {
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendLongResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendULongResponse(int expertHandle, unsigned __int64 response)
_DLLAPI int _stdcall sendULongResponse(int expertHandle, unsigned __int64 response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &response]() {
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseULong(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendLongResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendBooleanResponse(int expertHandle, int response)
_DLLAPI int _stdcall sendBooleanResponse(int expertHandle, int response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &response]() {
bool value = (response != 0) ? true : false;
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendBooleanResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendDoubleResponse(int expertHandle, double response)
_DLLAPI int _stdcall sendDoubleResponse(int expertHandle, double response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &response]() {
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendDoubleResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendStringResponse(int expertHandle, wchar_t* response)
_DLLAPI int _stdcall sendStringResponse(int expertHandle, wchar_t* response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, response]() {
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendStringResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendVoidResponse(int expertHandle)
_DLLAPI int _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle]() {
MtAdapter::GetInstance()->SendResponse(expertHandle, nullptr);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendVoidResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size)
_DLLAPI int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size, wchar_t* err)
{
try
{
return Execute<int>([&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];
}
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendDoubleArrayResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size)
_DLLAPI int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size, wchar_t* err)
{
try
{
return Execute<int>([&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];
}
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendIntArrayResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendLongArrayResponse(int expertHandle, __int64* values, int size)
_DLLAPI int _stdcall sendLongArrayResponse(int expertHandle, __int64* values, int size, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, values, &size]() {
array<System::Int64>^ list = gcnew array<System::Int64>(size);
for(int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++)
list[i] = values[i];
}
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLongArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendLongArrayResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int size)
_DLLAPI int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int size, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, values, &size]() {
array<MtMqlRates^>^ list = gcnew array<MtMqlRates^>(size);
for(int i = 0; i < size; i++)
for (int i = 0; i < size; i++)
{
MtMqlRates^ rates = gcnew MtMqlRates();
rates->time = values[i].time;
@@ -331,180 +203,107 @@ int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int
rates->tick_volume = values[i].tick_volume;
rates->spread = values[i].spread;
rates->real_volume = values[i].real_volume;
list[i] = rates;
}
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlRatesArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendMqlRatesArrayResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendMqlTickResponse(int expertHandle, CMqlTick* response, int size)
_DLLAPI int _stdcall sendMqlTickResponse(int expertHandle, CMqlTick* response, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, response]() {
MtMqlTick^ mtResponse = gcnew MtMqlTick();
mtResponse->time = response->time;
mtResponse->bid = response->bid;
mtResponse->ask = response->ask;
mtResponse->last = response->last;
mtResponse->volume = response->volume;
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendMqlTickResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall sendMqlBookInfoArrayResponse(int expertHandle, CMqlBookInfo values[], int size)
_DLLAPI int _stdcall sendMqlBookInfoArrayResponse(int expertHandle, CMqlBookInfo values[], int size, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, values, &size]() {
array<MtMqlBookInfo^>^ list = gcnew array<MtMqlBookInfo^>(size);
for(int i = 0; i < size; i++)
for (int i = 0; i < size; i++)
{
MtMqlBookInfo^ info = gcnew MtMqlBookInfo();
info->type = values[i].type;
info->price = values[i].price;
info->volume = values[i].volume;
list[i] = info;
}
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:sendMqlRatesArrayResponse(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
//----------- get values -------------------------------
int _stdcall getCommandType(int expertHandle, int* res)
_DLLAPI int _stdcall getCommandType(int expertHandle, int* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, res]() {
*res = MtAdapter::GetInstance()->GetCommandType(expertHandle);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getCommandType(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getIntValue(int expertHandle, int paramIndex, int* res)
_DLLAPI int _stdcall getIntValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getIntValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res)
_DLLAPI int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (double)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getDoubleValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res)
_DLLAPI int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
convertSystemString(res, (String^)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getStringValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64* res)
_DLLAPI int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (unsigned long)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getULongValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res)
_DLLAPI int _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (long)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getLongValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
_DLLAPI int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
bool val = (bool)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = val == true ? 1 : 0;
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int* res)
_DLLAPI int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int* res, wchar_t* err)
{
try
{
return Execute<int>([&expertHandle, &paramIndex, res]() {
*res = (unsigned int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MT5Connector:getUIntValue(): " + e->Message);
return 0;
}
return 1;
return 1;
}, err, 0);
}
-27
View File
@@ -1,27 +0,0 @@
LIBRARY MT5Connector
EXPORTS initExpert
deinitExpert
updateQuote
sendIntResponse
sendBooleanResponse
sendDoubleResponse
sendStringResponse
sendVoidResponse
sendDoubleArrayResponse
sendIntArrayResponse
sendLongArrayResponse
sendMqlRatesArrayResponse
sendLongResponse
sendULongResponse
sendMqlTickResponse
sendMqlBookInfoArrayResponse
getCommandType
getIntValue
getUIntValue
getDoubleValue
getStringValue
getLongValue
getULongValue
getBooleanValue
verify
-5
View File
@@ -95,7 +95,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib</AdditionalDependencies>
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -108,7 +107,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -120,7 +118,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -132,7 +129,6 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@@ -157,7 +153,6 @@
</ItemGroup>
<ItemGroup>
<None Include="app.ico" />
<None Include="MT5Connector.def" />
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
@@ -44,9 +44,6 @@
<None Include="app.ico">
<Filter>Resource Files</Filter>
</None>
<None Include="MT5Connector.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="app.rc">
+1 -6
View File
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MTApiService
namespace MTApiService
{
public interface IMetaTraderHandler
{
+1
View File
@@ -64,6 +64,7 @@
<Compile Include="IMetaTraderHandler.cs" />
<Compile Include="ITaskExecutor.cs" />
<Compile Include="LogConfigurator.cs" />
<Compile Include="Mt5Expert.cs" />
<Compile Include="MtCommandEventArgs.cs" />
<Compile Include="IDisposableChannel.cs" />
<Compile Include="IMtApiServer.cs" />
+48
View File
@@ -0,0 +1,48 @@
using log4net;
namespace MTApiService
{
public class Mt5Expert : MtExpert
{
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert));
private const int StopExpertInterval = 2000; // 2 sec for testing mode
private readonly System.Timers.Timer _stopTimer = new System.Timers.Timer();
public Mt5Expert(int handle, string symbol, double bid, double ask, IMetaTraderHandler mtHandler, bool isTestMode) :
base(handle, symbol, bid, ask, mtHandler)
{
IsTestMode = isTestMode;
_stopTimer.Interval = StopExpertInterval;
_stopTimer.Elapsed += _stopTimer_Elapsed;
}
public bool IsTestMode { get; }
public override void UpdateQuote(MtQuote quote)
{
Log.Debug("UpdateQuote: begin.");
base.UpdateQuote(quote);
if (IsTestMode)
{
//reset timer
_stopTimer.Stop();
_stopTimer.Start();
}
Log.Debug("UpdateQuote: end.");
}
private void _stopTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Log.Debug("_stopTimer_Elapsed: begin.");
Log.Warn("Mt5Expert has received new tick during 2 sec in testing mode. The possible cause: user has stopped the tester manually in MetaTrader 5.");
Deinit();
Log.Debug("_stopTimer_Elapsed: end.");
}
}
}
+13 -15
View File
@@ -36,12 +36,12 @@ namespace MTApiService
#region Public Methods
public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
public void AddExpert(int port, MtExpert expert)
{
if (mtHandler == null)
throw new ArgumentNullException(nameof(mtHandler));
if (expert == null)
throw new ArgumentNullException(nameof(expert));
Log.InfoFormat("InitExpert: begin. symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);
Log.InfoFormat("AddExpert: begin. expert = {0}", expert);
MtServer server;
lock (_servers)
@@ -60,8 +60,6 @@ namespace MTApiService
}
}
var expert = new MtExpert(expertHandle, new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle }, mtHandler);
lock (_experts)
{
_experts[expert.Handle] = expert;
@@ -69,12 +67,12 @@ namespace MTApiService
server.AddExpert(expert);
Log.Info("InitExpert: end");
Log.Info("AddExpert: end");
}
public void DeinitExpert(int expertHandle)
public void RemoveExpert(int expertHandle)
{
Log.InfoFormat("DeinitExpert: begin. expertHandle = {0}", expertHandle);
Log.InfoFormat("RemoveExpert: begin. expertHandle = {0}", expertHandle);
MtExpert expert = null;
@@ -93,15 +91,15 @@ namespace MTApiService
}
else
{
Log.WarnFormat("DeinitExpert: expert with id {0} has not been found.", expertHandle);
Log.WarnFormat("RemoveExpert: expert with id {0} has not been found.", expertHandle);
}
Log.Info("DeinitExpert: end");
Log.Info("RemoveExpert: end");
}
public void SendQuote(int expertHandle, string symbol, double bid, double ask)
{
Log.DebugFormat("SendQuote: begin. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);
Log.DebugFormat("UpdateQuote: begin. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);
MtExpert expert;
lock (_experts)
@@ -111,14 +109,14 @@ namespace MTApiService
if (expert != null)
{
expert.Quote = new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle };
expert.UpdateQuote(new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle });
}
else
{
Log.WarnFormat("SendQuote: expert with id {0} has not been found.", expertHandle);
Log.WarnFormat("UpdateQuote: expert with id {0} has not been found.", expertHandle);
}
Log.Debug("SendQuote: end");
Log.Debug("UpdateQuote: end");
}
public void SendEvent(int expertHandle, int eventType, string payload)
+1 -1
View File
@@ -17,7 +17,7 @@ namespace MTApiService
Command = command;
}
public MtCommand Command { get; private set; }
public MtCommand Command { get; }
public MtResponse WaitResult(int time)
{
+15 -27
View File
@@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace MTApiService
{
internal class MtExpert: ITaskExecutor
public class MtExpert: ITaskExecutor
{
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
public delegate void MtEventHandler(MtExpert expert, MtEvent e);
@@ -19,21 +19,20 @@ namespace MTApiService
#endregion
#region Public Methods
public MtExpert(int handle, MtQuote quote, IMetaTraderHandler mtHandler)
public MtExpert(int handle, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
{
if (mtHandler == null)
throw new ArgumentNullException(nameof(mtHandler));
Quote = quote;
_quote = new MtQuote { ExpertHandle = handle, Instrument = symbol, Bid = bid, Ask = ask};
Handle = handle;
_mtHadler = mtHandler;
}
public void Deinit()
public virtual void Deinit()
{
Log.Debug("Deinit: begin.");
IsEnable = false;
FireOnDeinited();
Log.Debug("Deinit: end.");
@@ -120,9 +119,18 @@ namespace MTApiService
Log.Debug("SendEvent: end.");
}
public virtual void UpdateQuote(MtQuote quote)
{
Log.DebugFormat("UpdateQuote: begin. quote = {0}", quote);
Quote = quote;
Log.Debug("UpdateQuote: end.");
}
public override string ToString()
{
return $"ExpertHandle = {Handle}";
return $"ExpertHandle = {Handle}, Quote = {Quote}";
}
#endregion
@@ -153,7 +161,7 @@ namespace MTApiService
return _quote;
}
}
set
private set
{
lock (_locker)
{
@@ -165,26 +173,6 @@ namespace MTApiService
}
public int Handle { get; }
private bool _isEnable = true;
public bool IsEnable
{
get
{
lock (_locker)
{
return _isEnable;
}
}
private set
{
lock (_locker)
{
_isEnable = value;
}
}
}
#endregion
#region Private Methods
-5
View File
@@ -80,11 +80,6 @@ namespace MTApiService
//init network hosts
var dnsHostName = Dns.GetHostName();
var ips = Dns.GetHostEntry(dnsHostName);
if (ips == null)
{
Log.WarnFormat("InitHosts: end. Dns.GetHostEntry has returned null for DNS Host Name {0}", dnsHostName);
return false;
}
foreach (var ipAddress in ips.AddressList)
{
+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.27.0")]
[assembly: AssemblyFileVersion("1.0.27.0")]
[assembly: AssemblyVersion("1.0.28.0")]
[assembly: AssemblyFileVersion("1.0.28.0")]
+3 -4
View File
@@ -44,17 +44,16 @@ template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default
_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();
MtAdapter::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHandler);
auto expert = gcnew MtExpert(expertHandle, gcnew String(symbol), bid, ask, gcnew MT4Handler());
MtAdapter::GetInstance()->AddExpert(port, expert);
return true;
}, err, false);
}
_DLLAPI bool _stdcall deinitExpert(int expertHandle, wchar_t* err)
{
return Execute<bool>([&expertHandle]() {
MtAdapter::GetInstance()->DeinitExpert(expertHandle);
MtAdapter::GetInstance()->RemoveExpert(expertHandle);
return true;
}, err, false);
}
+24
View File
@@ -0,0 +1,24 @@
using System;
namespace MtApi
{
public class ChartEventArgs : EventArgs
{
internal ChartEventArgs(int expertHandle, MtChartEvent chartEvent)
{
ExpertHandle = expertHandle;
ChartId = chartEvent.ChartId;
EventId = chartEvent.EventId;
Lparam = chartEvent.Lparam;
Dparam = chartEvent.Dparam;
Sparam = chartEvent.Sparam;
}
public int ExpertHandle { get; }
public long ChartId { get; }
public int EventId { get; }
public long Lparam { get; }
public double Dparam { get; }
public string Sparam { get; }
}
}
+18
View File
@@ -0,0 +1,18 @@
namespace MtApi
{
public enum EnumChartEvent
{
CHARTEVENT_KEYDOWN = 0,
CHARTEVENT_MOUSE_MOVE = 10,
CHARTEVENT_OBJECT_CREATE = 7,
CHARTEVENT_OBJECT_CHANGE = 8,
CHARTEVENT_OBJECT_DELETE = 6,
CHARTEVENT_CLICK = 4,
CHARTEVENT_OBJECT_CLICK = 1,
CHARTEVENT_OBJECT_DRAG = 2,
CHARTEVENT_OBJECT_ENDEDIT = 3,
CHARTEVENT_CHART_CHANGE = 9,
CHARTEVENT_CUSTOM = 1000,
CHARTEVENT_CUSTOM_LAST = 66534
}
}
+2
View File
@@ -58,6 +58,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ChartEventArgs.cs" />
<Compile Include="ChartPeriod.cs" />
<Compile Include="EnumAlignMode.cs" />
<Compile Include="EnumChartPropertyDouble.cs" />
@@ -77,6 +78,7 @@
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
<Compile Include="MqlRates.cs" />
<Compile Include="MqlTick.cs" />
<Compile Include="MtChartEvent.cs" />
<Compile Include="MtConnectionEventArgs.cs" />
<Compile Include="MtConnectionException.cs" />
<Compile Include="MtConnectionState.cs" />
+12 -5
View File
@@ -3068,18 +3068,24 @@ namespace MtApi
switch(eventType)
{
case MtEventTypes.LastTimeBar:
{
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
}
FireOnLastTimeBar(e.ExpertHandle, JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
break;
case MtEventTypes.ChartEvent:
FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject<MtChartEvent>(e.Payload));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private void FireOnLastTimeBar(MtTimeBar timeBar)
private void FireOnLastTimeBar(int expertHandler, MtTimeBar timeBar)
{
OnLastTimeBar?.Invoke(this, new TimeBarArgs(timeBar));
OnLastTimeBar?.Invoke(this, new TimeBarArgs(expertHandler, timeBar));
}
private void FireOnChartEvent(int expertHandler, MtChartEvent chartEvent)
{
OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent));
}
private void BacktestingReady()
@@ -3097,6 +3103,7 @@ namespace MtApi
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
public event EventHandler<TimeBarArgs> OnLastTimeBar;
public event EventHandler<ChartEventArgs> OnChartEvent;
#endregion
}
+11
View File
@@ -0,0 +1,11 @@
namespace MtApi
{
internal class MtChartEvent
{
public long ChartId { get; set; }
public int EventId { get; set; }
public long Lparam { get; set; }
public double Dparam { get; set; }
public string Sparam { get; set; }
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
{
public enum MtEventTypes
{
LastTimeBar = 1
LastTimeBar = 1,
ChartEvent = 2
}
}
+2 -11
View File
@@ -11,16 +11,7 @@ namespace MtApi
public double Close { get; set; }
public double High { get; set; }
public double Low { get; set; }
public DateTime OpenTime
{
get { return MtApiTimeConverter.ConvertFromMtTime(MtOpenTime); }
}
public DateTime CloseTime
{
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
}
public DateTime OpenTime => MtApiTimeConverter.ConvertFromMtTime(MtOpenTime);
public DateTime CloseTime => MtApiTimeConverter.ConvertFromMtTime(MtCloseTime);
}
}
+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.37.0")]
[assembly: AssemblyFileVersion("1.0.37.0")]
[assembly: AssemblyVersion("1.0.38.0")]
[assembly: AssemblyFileVersion("1.0.38.0")]
+8 -1
View File
@@ -4,11 +4,18 @@ namespace MtApi
{
public class TimeBarArgs: EventArgs
{
internal TimeBarArgs(int expertHandle, MtTimeBar timeBar)
: this(timeBar)
{
ExpertHandle = expertHandle;
}
public TimeBarArgs(MtTimeBar timeBar)
{
TimeBar = timeBar;
}
public MtTimeBar TimeBar { get; private set; }
public int ExpertHandle { get; }
public MtTimeBar TimeBar { get; }
}
}
+4 -2
View File
@@ -5,7 +5,7 @@ namespace MtApi5
public class MqlTradeRequest
{
public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type
public uint Magic { get; set; } // Expert Advisor ID (magic number)
public ulong Magic { get; set; } // Expert Advisor ID (magic number)
public ulong Order { get; set; } // Order ticket
public string Symbol { get; set; } // Trade symbol
public double Volume { get; set; } // Requested volume for a deal in lots
@@ -13,11 +13,13 @@ namespace MtApi5
public double Stoplimit { get; set; } // StopLimit level of the order
public double Sl { get; set; } // Stop Loss level of the order
public double Tp { get; set; } // Take Profit level of the order
public uint Deviation { get; set; } // Maximal possible deviation from the requested price
public ulong Deviation { get; set; } // Maximal possible deviation from the requested price
public ENUM_ORDER_TYPE Type { get; set; } // Order type
public ENUM_ORDER_TYPE_FILLING Type_filling { get; set; } // Order execution type
public ENUM_ORDER_TYPE_TIME Type_time { get; set; } // Order expiration type
public DateTime Expiration { get; set; } // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
public string Comment { get; set; } // Order comment
public ulong Position { get; set; } // Position ticket
public ulong PositionBy { get; set; } // The ticket of an opposite position
}
}
+2
View File
@@ -114,5 +114,7 @@ namespace MtApi5
//Requests
MtRequest = 155,
PositionSelectByTicket = 69
}
}
+487 -211
View File
@@ -1,200 +1,10 @@
namespace MtApi5
{
public enum ENUM_TRADE_REQUEST_ACTIONS
{
TRADE_ACTION_DEAL = 1, //Place a trade order for an immediate execution with the specified parameters (market order)
TRADE_ACTION_PENDING = 5, //Place a trade order for an immediate execution with the specified parameters (market order)
TRADE_ACTION_SLTP = 6, //Place a trade order for an immediate execution with the specified parameters (market order)
TRADE_ACTION_MODIFY = 7, //Place a trade order for an immediate execution with the specified parameters (market order)
TRADE_ACTION_REMOVE = 8 //Place a trade order for an immediate execution with the specified parameters (market order)
}
public enum ENUM_ORDER_TYPE
{
ORDER_TYPE_BUY = 0, //Market Buy order
ORDER_TYPE_SELL = 1, //Market Sell order
ORDER_TYPE_BUY_LIMIT = 2, //Buy Limit pending order
ORDER_TYPE_SELL_LIMIT = 3, //Sell Limit pending order
ORDER_TYPE_BUY_STOP = 4, //Buy Stop pending order
ORDER_TYPE_SELL_STOP = 5, //Sell Stop pending order
ORDER_TYPE_BUY_STOP_LIMIT = 6, //Upon reaching the order price, a pending Buy Limit order is places at the StopLimit price
ORDER_TYPE_SELL_STOP_LIMIT = 7, //Upon reaching the order price, a pending Sell Limit order is places at the StopLimit price
}
public enum ENUM_ORDER_TYPE_FILLING
{
ORDER_FILLING_FOK = 0,
ORDER_FILLING_IOC = 1,
ORDER_FILLING_RETURN = 2
}
public enum ENUM_ORDER_TYPE_TIME
{
ORDER_TIME_GTC = 0,
ORDER_TIME_DAY = 1,
ORDER_TIME_SPECIFIED = 2,
ORDER_TIME_SPECIFIED_DAY = 3
}
public enum ENUM_POSITION_PROPERTY_DOUBLE
{
POSITION_VOLUME = 3, //Position volume
POSITION_PRICE_OPEN = 4, //Position open price
POSITION_SL = 6, //Stop Loss level of opened position
POSITION_TP = 7, //Take Profit level of opened position
POSITION_PRICE_CURRENT = 5, //Current price of the position symbol
POSITION_COMMISSION = 8, //Commission
POSITION_SWAP = 9, //Cumulative swap
POSITION_PROFIT = 10 //Current profit
}
public enum ENUM_POSITION_PROPERTY_INTEGER
{
POSITION_TIME = 1, //Position open time
POSITION_TYPE = 2, //Position type
POSITION_MAGIC = 12, //Position magic number
POSITION_IDENTIFIER = 13 //Position identifier is a unique number that is assigned to every newly opened position and doesn't change during the entire lifetime of the position. Position turnover doesn't change its identifier.
}
public enum ENUM_POSITION_TYPE
{
POSITION_TYPE_BUY = 0, //Buy
POSITION_TYPE_SELL = 1 //Sell
}
public enum ENUM_POSITION_PROPERTY_STRING
{
POSITION_SYMBOL = 0, //Symbol of the position
POSITION_COMMENT = 11 //Position comment
}
public enum ENUM_ORDER_PROPERTY_DOUBLE
{
ORDER_VOLUME_INITIAL = 7, //Order initial volume
ORDER_VOLUME_CURRENT = 8, //Order current volume
ORDER_PRICE_OPEN = 9, //Price specified in the order
ORDER_SL = 12, //Stop Loss value
ORDER_TP = 13, //Take Profit value
ORDER_PRICE_CURRENT = 10, //The current price of the order symbol
ORDER_PRICE_STOPLIMIT = 11 //The Limit order price for the StopLimit order
}
public enum ENUM_ORDER_PROPERTY_STRING
{
ORDER_SYMBOL = 0, //Symbol of the order
ORDER_COMMENT = 16 //Order comment
}
public enum ENUM_ORDER_PROPERTY_INTEGER
{
ORDER_TIME_SETUP = 1, //Order setup time
ORDER_TYPE = 4, //Order type
ORDER_STATE = 14, //Order state
ORDER_TIME_EXPIRATION = 2, //Order expiration time
ORDER_TIME_DONE = 3, //Order execution or cancellation time
ORDER_TYPE_FILLING = 5, //Order filling type
ORDER_TYPE_TIME = 6, //Order lifetime
ORDER_MAGIC = 15, //ID of an Expert Advisor that has placed the order (designed to ensure that each Expert Advisor places its own unique number)
ORDER_POSITION_ID = 17 //Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of exactly this position is set to the executed order at this moment.
}
public enum ENUM_DEAL_PROPERTY_DOUBLE
{
DEAL_VOLUME = 5,
DEAL_PRICE = 6,
DEAL_COMMISSION = 7,
DEAL_SWAP = 8,
DEAL_PROFIT = 9
}
public enum ENUM_DEAL_PROPERTY_STRING
{
DEAL_SYMBOL = 0,
DEAL_COMMENT = 10
}
public enum ENUM_DEAL_TYPE
{
DEAL_TYPE_BUY = 0,
DEAL_TYPE_SELL = 1,
DEAL_TYPE_BALANCE = 2,
DEAL_TYPE_CREDIT = 3,
DEAL_TYPE_CHARGE = 4,
DEAL_TYPE_CORRECTION = 5,
DEAL_TYPE_BONUS = 6,
DEAL_TYPE_COMMISSION = 7,
DEAL_TYPE_COMMISSION_DAILY = 8,
DEAL_TYPE_COMMISSION_MONTHLY = 9,
DEAL_TYPE_COMMISSION_AGENT_DAILY = 10,
DEAL_TYPE_COMMISSION_AGENT_MONTHLY = 11,
DEAL_TYPE_INTEREST = 12,
DEAL_TYPE_BUY_CANCELED = 13,
DEAL_TYPE_SELL_CANCELED = 14
}
public enum ENUM_DEAL_ENTRY
{
DEAL_ENTRY_IN = 0,
DEAL_ENTRY_OUT = 1,
DEAL_ENTRY_INOUT = 2,
DEAL_ENTRY_STATE = 255
}
public enum ENUM_DEAL_PROPERTY_INTEGER
{
DEAL_ORDER = 1,
DEAL_TIME = 2,
DEAL_TYPE = 3,
DEAL_ENTRY = 4,
DEAL_MAGIC = 11,
DEAL_POSITION_ID = 12
}
public enum ENUM_ACCOUNT_INFO_INTEGER
{
ACCOUNT_LOGIN = 0,
ACCOUNT_TRADE_MODE = 32,
ACCOUNT_LEVERAGE = 35,
ACCOUNT_LIMIT_ORDERS = 47,
ACCOUNT_MARGIN_SO_MODE = 44,
ACCOUNT_TRADE_ALLOWED = 33,
ACCOUNT_TRADE_EXPERT = 34
}
public enum ENUM_ACCOUNT_INFO_DOUBLE
{
ACCOUNT_BALANCE = 37,
ACCOUNT_CREDIT = 38,
ACCOUNT_PROFIT = 39,
ACCOUNT_EQUITY = 40,
ACCOUNT_MARGIN = 41,
ACCOUNT_FREEMARGIN = 42,
ACCOUNT_MARGIN_LEVEL = 43,
ACCOUNT_MARGIN_SO_CALL = 45,
ACCOUNT_MARGIN_SO_SO = 46
}
public enum ENUM_ACCOUNT_INFO_STRING
{
ACCOUNT_NAME = 1,
ACCOUNT_SERVER = 3,
ACCOUNT_CURRENCY = 36,
ACCOUNT_COMPANY = 2
}
public enum ENUM_ACCOUNT_TRADE_MODE
{
ACCOUNT_TRADE_MODE_DEMO = 0,
ACCOUNT_TRADE_MODE_CONTEST = 1,
ACCOUNT_TRADE_MODE_REAL = 2
}
public enum ENUM_ACCOUNT_STOPOUT_MODE
{
ACCOUNT_STOPOUT_MODE_PERCENT = 0,
ACCOUNT_STOPOUT_MODE_MONEY = 1
}
// Chart Constants:
#region Chart Timeframes
public enum ENUM_TIMEFRAMES
{
PERIOD_CURRENT = 0,
@@ -221,19 +31,66 @@
PERIOD_MN1 = 49153
}
public enum ENUM_SERIES_INFO_INTEGER
#endregion //Chart Timeframes
// Environment State:
#region Client Terminal Properties
public enum ENUM_TERMINAL_INFO_INTEGER
{
SERIES_BARS_COUNT = 0,
SERIES_FIRSTDATE = 1,
SERIES_LASTBAR_DATE = 5,
SERIES_SERVER_FIRSTDATE = 2,
SERIES_TERMINAL_FIRSTDATE = 3,
SERIES_SYNCHRONIZED = 4
TERMINAL_BUILD = 5,
TERMINAL_COMMUNITY_ACCOUNT = 23,
TERMINAL_COMMUNITY_CONNECTION = 24,
TERMINAL_CONNECTED = 6,
TERMINAL_DLLS_ALLOWED = 7,
TERMINAL_TRADE_ALLOWED = 8,
TERMINAL_EMAIL_ENABLED = 9,
TERMINAL_FTP_ENABLED = 10,
TERMINAL_NOTIFICATIONS_ENABLED = 26,
TERMINAL_MAXBARS = 11,
TERMINAL_MQID = 22,
TERMINAL_CODEPAGE = 12,
TERMINAL_CPU_CORES = 21,
TERMINAL_DISK_SPACE = 20,
TERMINAL_MEMORY_PHYSICAL = 14,
TERMINAL_MEMORY_TOTAL = 15,
TERMINAL_MEMORY_AVAILABLE = 16,
TERMINAL_MEMORY_USED = 17,
TERMINAL_X64 = 18,
TERMINAL_OPENCL_SUPPORT = 19,
TERMINAL_SCREEN_DPI = 27,
TERMINAL_PING_LAST = 29
}
public enum ENUM_TERMINAL_INFO_DOUBLE
{
TERMINAL_COMMUNITY_BALANCE = 25
}
public enum ENUM_TERMINAL_INFO_STRING
{
TERMINAL_LANGUAGE = 13,
TERMINAL_COMPANY = 0,
TERMINAL_NAME = 1,
TERMINAL_PATH = 2,
TERMINAL_DATA_PATH = 3,
TERMINAL_COMMONDATA_PATH = 4
}
#endregion //Client Terminal Properties
#region Symbol Properties
public enum ENUM_SYMBOL_INFO_INTEGER
{
SYMBOL_CUSTOM = 78,
SYMBOL_BACKGROUND_COLOR = 79,
SYMBOL_CHART_MODE = 80,
SYMBOL_SELECT = 0,
//FIXME: SYMBOL_VISIBLE not found in MQL5 environment!
//SYMBOL_VISIBLE = ?
SYMBOL_SESSION_DEALS = 56,
SYMBOL_SESSION_BUY_ORDERS = 60,
SYMBOL_SESSION_SELL_ORDERS = 62,
@@ -254,8 +111,14 @@
SYMBOL_TRADE_EXEMODE = 33,
SYMBOL_SWAP_MODE = 37,
SYMBOL_SWAP_ROLLOVER3DAYS = 40,
SYMBOL_MARGIN_HEDGED_USE_LEG = 82,
SYMBOL_EXPIRATION_MODE = 49,
SYMBOL_FILLING_MODE = 50
SYMBOL_FILLING_MODE = 50,
SYMBOL_ORDER_MODE = 71,
SYMBOL_ORDER_GTC_MODE = 81,
SYMBOL_ORDER_CLOSEBY = 64,
SYMBOL_OPTION_MODE = 75,
SYMBOL_OPTION_RIGHT = 74,
}
public enum ENUM_SYMBOL_INFO_DOUBLE
@@ -269,12 +132,16 @@
SYMBOL_LAST = 7,
SYMBOL_LASTHIGH = 8,
SYMBOL_LASTLOW = 9,
SYMBOL_OPTION_STRIKE = 72,
SYMBOL_POINT = 16,
SYMBOL_TRADE_TICK_VALUE = 26,
SYMBOL_TRADE_TICK_VALUE_PROFIT = 53,
SYMBOL_TRADE_TICK_VALUE_LOSS = 54,
SYMBOL_TRADE_TICK_SIZE = 27,
SYMBOL_TRADE_CONTRACT_SIZE = 28,
SYMBOL_TRADE_ACCRUED_INTEREST = 87,
SYMBOL_TRADE_FACE_VALUE = 86,
SYMBOL_TRADE_LIQUIDITY_RATE = 85,
SYMBOL_VOLUME_MIN = 34,
SYMBOL_VOLUME_MAX = 35,
SYMBOL_VOLUME_STEP = 36,
@@ -283,11 +150,11 @@
SYMBOL_SWAP_SHORT = 39,
SYMBOL_MARGIN_INITIAL = 42,
SYMBOL_MARGIN_MAINTENANCE = 43,
SYMBOL_MARGIN_LONG = 44,
SYMBOL_MARGIN_SHORT = 45,
SYMBOL_MARGIN_LIMIT = 46,
SYMBOL_MARGIN_STOP = 47,
SYMBOL_MARGIN_STOPLIMIT = 48,
SYMBOL_MARGIN_LONG = 44, //FIXME: Undocumented!
SYMBOL_MARGIN_SHORT = 45, //FIXME: Undocumented!
SYMBOL_MARGIN_LIMIT = 46, //FIXME: Undocumented!
SYMBOL_MARGIN_STOP = 47, //FIXME: Undocumented!
SYMBOL_MARGIN_STOPLIMIT = 48, //FIXME: Undocumented!
SYMBOL_SESSION_VOLUME = 57,
SYMBOL_SESSION_TURNOVER = 58,
SYMBOL_SESSION_INTEREST = 59,
@@ -298,20 +165,80 @@
SYMBOL_SESSION_AW = 66,
SYMBOL_SESSION_PRICE_SETTLEMENT = 67,
SYMBOL_SESSION_PRICE_LIMIT_MIN = 68,
SYMBOL_SESSION_PRICE_LIMIT_MAX = 69
SYMBOL_SESSION_PRICE_LIMIT_MAX = 69,
SYMBOL_MARGIN_HEDGED = 77
}
public enum ENUM_SYMBOL_INFO_STRING
{
SYMBOL_BASIS = 73,
SYMBOL_CURRENCY_BASE = 22,
SYMBOL_CURRENCY_PROFIT = 23,
SYMBOL_CURRENCY_MARGIN = 24,
SYMBOL_BANK = 19,
SYMBOL_DESCRIPTION = 20,
SYMBOL_FORMULA = 84,
SYMBOL_PAGE = 83,
SYMBOL_ISIN = 70,
SYMBOL_PATH = 21
}
public enum ENUM_SYMBOL_CHART_MODE
{
SYMBOL_CHART_MODE_BID = 0,
SYMBOL_CHART_MODE_LAST = 1
}
public enum ENUM_SYMBOL_ORDER_GTC_MODE
{
SYMBOL_ORDERS_GTC = 0,
SYMBOL_ORDERS_DAILY = 1,
SYMBOL_ORDERS_DAILY_EXCLUDING_STOPS = 2
}
public enum ENUM_SYMBOL_CALC_MODE
{
SYMBOL_CALC_MODE_FOREX = 0,
SYMBOL_CALC_MODE_FUTURES = 1,
SYMBOL_CALC_MODE_CFD = 2,
SYMBOL_CALC_MODE_CFDINDEX = 3,
SYMBOL_CALC_MODE_CFDLEVERAGE = 4,
SYMBOL_CALC_MODE_EXCH_STOCKS = 32,
SYMBOL_CALC_MODE_EXCH_FUTURES = 33,
SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS = 34,
SYMBOL_CALC_MODE_SERV_COLLATERAL = 64
}
public enum ENUM_SYMBOL_TRADE_MODE
{
SYMBOL_TRADE_MODE_DISABLED = 0,
SYMBOL_TRADE_MODE_LONGONLY = 1,
SYMBOL_TRADE_MODE_SHORTONLY = 2,
SYMBOL_TRADE_MODE_CLOSEONLY = 3,
SYMBOL_TRADE_MODE_FULL = 4
}
public enum ENUM_SYMBOL_TRADE_EXECUTION
{
SYMBOL_TRADE_EXECUTION_REQUEST = 0,
SYMBOL_TRADE_EXECUTION_INSTANT = 1,
SYMBOL_TRADE_EXECUTION_MARKET = 2,
SYMBOL_TRADE_EXECUTION_EXCHANGE = 3
}
public enum ENUM_SYMBOL_SWAP_MODE
{
SYMBOL_SWAP_MODE_DISABLED = 0,
SYMBOL_SWAP_MODE_POINTS = 1,
SYMBOL_SWAP_MODE_CURRENCY_SYMBOL = 2,
SYMBOL_SWAP_MODE_CURRENCY_MARGIN = 3,
SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT = 4,
SYMBOL_SWAP_MODE_INTEREST_CURRENT = 5,
SYMBOL_SWAP_MODE_INTEREST_OPEN = 6,
SYMBOL_SWAP_MODE_REOPEN_CURRENT = 7,
SYMBOL_SWAP_MODE_REOPEN_BID = 8
}
public enum ENUM_DAY_OF_WEEK
{
SUNDAY = 0,
@@ -323,11 +250,360 @@
SATURDAY = 6
}
public enum ENUM_SYMBOL_OPTION_RIGHT
{
SYMBOL_OPTION_RIGHT_CALL = 0,
SYMBOL_OPTION_RIGHT_PUT = 1
}
public enum ENUM_SYMBOL_OPTION_MODE
{
SYMBOL_OPTION_MODE_EUROPEAN = 0,
SYMBOL_OPTION_MODE_AMERICAN = 1
}
#endregion //Symbol Properties
#region Account Properties
public enum ENUM_ACCOUNT_INFO_INTEGER
{
ACCOUNT_LOGIN = 0, //Account number
ACCOUNT_TRADE_MODE = 32, //Account trade mode
ACCOUNT_LEVERAGE = 35, //Account leverage
ACCOUNT_LIMIT_ORDERS = 47, //Maximum allowed number of active pending orders
ACCOUNT_MARGIN_SO_MODE = 44, //Mode for setting the minimal allowed margin
ACCOUNT_TRADE_ALLOWED = 33, //Allowed trade for the current account
ACCOUNT_TRADE_EXPERT = 34, //Allowed trade for an Expert Advisor
ACCOUNT_MARGIN_MODE = 53 //Margin calculation mode
}
public enum ENUM_ACCOUNT_INFO_DOUBLE
{
ACCOUNT_BALANCE = 37, //Account balance in the deposit currency
ACCOUNT_CREDIT = 38, //Account credit in the deposit currency
ACCOUNT_PROFIT = 39, //Current profit of an account in the deposit currency
ACCOUNT_EQUITY = 40, //Account equity in the deposit currency
ACCOUNT_MARGIN = 41, //Account margin used in the deposit currency
ACCOUNT_MARGIN_FREE = 42, //Free margin of an account in the deposit currency
ACCOUNT_MARGIN_LEVEL = 43, //Account margin level in percents
ACCOUNT_MARGIN_SO_CALL = 45, //Margin call level
ACCOUNT_MARGIN_SO_SO = 46, //Margin stop out level
ACCOUNT_MARGIN_INITIAL = 48, //Initial margin
ACCOUNT_MARGIN_MAINTENANCE = 49, //Maintenance margin
ACCOUNT_ASSETS = 50, //The current assets of an account
ACCOUNT_LIABILITIES = 51, //The current liabilities on an account
ACCOUNT_COMMISSION_BLOCKED = 52 //The current blocked commission amount on an account
}
public enum ENUM_ACCOUNT_INFO_STRING
{
ACCOUNT_NAME = 1, //Client name
ACCOUNT_SERVER = 3, //Trade server name
ACCOUNT_CURRENCY = 36, //Account currency
ACCOUNT_COMPANY = 2 //Name of a company that serves the account
}
public enum ENUM_ACCOUNT_TRADE_MODE
{
ACCOUNT_TRADE_MODE_DEMO = 0, //Demo account
ACCOUNT_TRADE_MODE_CONTEST = 1, //Contest account
ACCOUNT_TRADE_MODE_REAL = 2 //Real account
}
public enum ENUM_ACCOUNT_STOPOUT_MODE
{
ACCOUNT_STOPOUT_MODE_PERCENT = 0, //Account stop out mode in percents
ACCOUNT_STOPOUT_MODE_MONEY = 1 //Account stop out mode in money
}
public enum ENUM_ACCOUNT_MARGIN_MODE
{
ACCOUNT_MARGIN_MODE_RETAIL_NETTING = 0, //Used for the OTC markets to interpret positions in the "netting" mode
ACCOUNT_MARGIN_MODE_EXCHANGE = 1, //Used for the exchange markets
ACCOUNT_MARGIN_MODE_RETAIL_HEDGING = 2 //Used for the exchange markets where individual positions are possible
}
#endregion //Account Properties
// Trade Constants:
#region History Database Properties
public enum ENUM_SERIES_INFO_INTEGER
{
SERIES_BARS_COUNT = 0, //Bars count for the symbol-period for the current moment
SERIES_FIRSTDATE = 1, //The very first date for the symbol-period for the current moment
SERIES_LASTBAR_DATE = 5, //Open time of the last bar of the symbol-period
SERIES_SERVER_FIRSTDATE = 2, //The very first date in the history of the symbol on the server regardless of the timeframe
SERIES_TERMINAL_FIRSTDATE = 3, //The very first date in the history of the symbol in the client terminal, regardless of the timeframe
SERIES_SYNCHRONIZED = 4 //Symbol/period data synchronization flag for the current moment
}
#endregion //History Database Properties
#region Order Properties
public enum ENUM_ORDER_PROPERTY_INTEGER
{
ORDER_TICKET = 22, //Order ticket. Unique number assigned to each order
ORDER_TIME_SETUP = 1, //Order setup time
ORDER_TYPE = 4, //Order type
ORDER_STATE = 14, //Order state
ORDER_TIME_EXPIRATION = 2, //Order expiration time
ORDER_TIME_DONE = 3, //Order execution or cancellation time
ORDER_TIME_SETUP_MSC = 18, //The time of placing an order for execution in milliseconds since 01.01.1970
ORDER_TIME_DONE_MSC = 19, //Order execution/cancellation time in milliseconds since 01.01.1970
ORDER_TYPE_FILLING = 5, //Order filling type
ORDER_TYPE_TIME = 6, //Order lifetime
ORDER_MAGIC = 15, //ID of an Expert Advisor that has placed the order (designed to ensure that each Expert Advisor places its own unique number)
ORDER_REASON = 23, //The reason or source for placing an order
ORDER_POSITION_ID = 17, //Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of exactly this position is set to the executed order at this moment.
ORDER_POSITION_BY_ID = 21 //Identifier of an opposite position used for closing by order ORDER_TYPE_CLOSE_BY
}
public enum ENUM_ORDER_PROPERTY_DOUBLE
{
ORDER_VOLUME_INITIAL = 7, //Order initial volume
ORDER_VOLUME_CURRENT = 8, //Order current volume
ORDER_PRICE_OPEN = 9, //Price specified in the order
ORDER_SL = 12, //Stop Loss value
ORDER_TP = 13, //Take Profit value
ORDER_PRICE_CURRENT = 10, //The current price of the order symbol
ORDER_PRICE_STOPLIMIT = 11 //The Limit order price for the StopLimit order
}
public enum ENUM_ORDER_PROPERTY_STRING
{
ORDER_SYMBOL = 0, //Symbol of the order
ORDER_COMMENT = 16, //Order comment
ORDER_EXTERNAL_ID = 20 //Order identifier in an external trading system (on the Exchange)
}
public enum ENUM_ORDER_TYPE
{
ORDER_TYPE_BUY = 0, //Market Buy order
ORDER_TYPE_SELL = 1, //Market Sell order
ORDER_TYPE_BUY_LIMIT = 2, //Buy Limit pending order
ORDER_TYPE_SELL_LIMIT = 3, //Sell Limit pending order
ORDER_TYPE_BUY_STOP = 4, //Buy Stop pending order
ORDER_TYPE_SELL_STOP = 5, //Sell Stop pending order
ORDER_TYPE_BUY_STOP_LIMIT = 6, //Upon reaching the order price, a pending Buy Limit order is places at the StopLimit price
ORDER_TYPE_SELL_STOP_LIMIT = 7, //Upon reaching the order price, a pending Sell Limit order is places at the StopLimit price
ORDER_TYPE_CLOSE_BY = 8 //Order to close a position by an opposite one
}
public enum ENUM_ORDER_STATE
{
ORDER_STATE_STARTED = 0, //Order checked, but not yet accepted by broker
ORDER_STATE_PLACED = 1, //Order accepted
ORDER_STATE_CANCELED = 2, //Order canceled by client
ORDER_STATE_PARTIAL = 3, //Order partially executed
ORDER_STATE_FILLED = 4, //Order fully executed
ORDER_STATE_REJECTED = 5, //Order rejected
ORDER_STATE_EXPIRED = 6, //Order expired
ORDER_STATE_REQUEST_ADD = 7, //Order is being registered (placing to the trading system)
ORDER_STATE_REQUEST_MODIFY = 8, //Order is being modified (changing its parameters)
ORDER_STATE_REQUEST_CANCEL = 9 //Order is being deleted (deleting from the trading system)
}
public enum ENUM_ORDER_TYPE_FILLING
{
ORDER_FILLING_FOK = 0,
ORDER_FILLING_IOC = 1,
ORDER_FILLING_RETURN = 2
}
public enum ENUM_ORDER_TYPE_TIME
{
ORDER_TIME_GTC = 0,
ORDER_TIME_DAY = 1,
ORDER_TIME_SPECIFIED = 2,
ORDER_TIME_SPECIFIED_DAY = 3
}
public enum ENUM_ORDER_REASON
{
ORDER_REASON_CLIENT = 0, //The order was placed from a desktop terminal
ORDER_REASON_MOBILE = 1, //The order was placed from a mobile application
ORDER_REASON_WEB = 2, //The order was placed from a web platform
ORDER_REASON_EXPERT = 3, //The order was placed from an MQL5-program, i.e. by an Expert Advisor or a script
ORDER_REASON_SL = 4, //The order was placed as a result of Stop Loss activation
ORDER_REASON_TP = 5, //The order was placed as a result of Take Profit activation
ORDER_REASON_SO = 6 //The order was placed as a result of the Stop Out event
}
#endregion //Order Properties
#region Position Properties
public enum ENUM_POSITION_PROPERTY_INTEGER
{
POSITION_TICKET = 17, //Position ticket
POSITION_TIME = 1, //Position open time
POSITION_TIME_MSC = 14, //Position opening time in milliseconds since 01.01.1970
POSITION_TIME_UPDATE = 15, //Position changing time in seconds since 01.01.1970
POSITION_TIME_UPDATE_MSC = 16, //Position changing time in milliseconds since 01.01.1970
POSITION_TYPE = 2, //Position type
POSITION_MAGIC = 12, //Position magic number
POSITION_IDENTIFIER = 13, //Position identifier is a unique number that is assigned to every newly opened position and doesn't change during the entire lifetime of the position. Position turnover doesn't change its identifier.
POSITION_REASON = 18 //The reason for opening a position
}
public enum ENUM_POSITION_PROPERTY_DOUBLE
{
POSITION_VOLUME = 3, //Position volume
POSITION_PRICE_OPEN = 4, //Position open price
POSITION_SL = 6, //Stop Loss level of opened position
POSITION_TP = 7, //Take Profit level of opened position
POSITION_PRICE_CURRENT = 5, //Current price of the position symbol
POSITION_COMMISSION = 8, //FIXME: Undocumented!
POSITION_SWAP = 9, //Cumulative swap
POSITION_PROFIT = 10 //Current profit
}
public enum ENUM_POSITION_PROPERTY_STRING
{
POSITION_SYMBOL = 0, //Symbol of the position
POSITION_COMMENT = 11 //Position comment
}
public enum ENUM_POSITION_TYPE
{
POSITION_TYPE_BUY = 0, //Buy
POSITION_TYPE_SELL = 1 //Sell
}
public enum ENUM_POSITION_REASON
{
POSITION_REASON_CLIENT = 0, //The position was opened as a result of activation of an order placed from a desktop terminal
POSITION_REASON_MOBILE = 1, //The position was opened as a result of activation of an order placed from a mobile application
POSITION_REASON_WEB = 2, //The position was opened as a result of activation of an order placed from the web platform
POSITION_REASON_EXPERT = 3 //The position was opened as a result of activation of an order placed from an MQL5 program
}
#endregion //Position Properties
#region Deal Properties
public enum ENUM_DEAL_PROPERTY_INTEGER
{
DEAL_TICKET = 15, //Deal ticket. Unique number assigned to each deal
DEAL_ORDER = 1, //Deal order number
DEAL_TIME = 2, //Deal time
DEAL_TIME_MSC = 13, //The time of a deal execution in milliseconds since 01.01.1970
DEAL_TYPE = 3, //Deal type
DEAL_ENTRY = 4, //Deal entry - entry in, entry out, reverse
DEAL_MAGIC = 11, //Deal magic number
DEAL_REASON = 16, //The reason or source for deal execution
DEAL_POSITION_ID = 12 //Identifier of a position
}
public enum ENUM_DEAL_PROPERTY_DOUBLE
{
DEAL_VOLUME = 5, //Deal volume
DEAL_PRICE = 6, //Deal price
DEAL_COMMISSION = 7, //Deal commission
DEAL_SWAP = 8, //Cumulative swap on close
DEAL_PROFIT = 9 //Deal profit
}
public enum ENUM_DEAL_PROPERTY_STRING
{
DEAL_SYMBOL = 0, //Deal symbol
DEAL_COMMENT = 10, //Deal comment
DEAL_EXTERNAL_ID = 14 //Deal identifier in an external trading system (on the Exchange)
}
public enum ENUM_DEAL_TYPE
{
DEAL_TYPE_BUY = 0, //Buy
DEAL_TYPE_SELL = 1, //Sell
DEAL_TYPE_BALANCE = 2, //Balance
DEAL_TYPE_CREDIT = 3, //Credit
DEAL_TYPE_CHARGE = 4, //Additional charge
DEAL_TYPE_CORRECTION = 5, //Correction
DEAL_TYPE_BONUS = 6, //Bonus
DEAL_TYPE_COMMISSION = 7, //Additional commission
DEAL_TYPE_COMMISSION_DAILY = 8, //Daily commission
DEAL_TYPE_COMMISSION_MONTHLY = 9, //Monthly commission
DEAL_TYPE_COMMISSION_AGENT_DAILY = 10, //Daily agent commission
DEAL_TYPE_COMMISSION_AGENT_MONTHLY = 11, //Monthly agent commission
DEAL_TYPE_INTEREST = 12, //Interest rate
DEAL_TYPE_BUY_CANCELED = 13, //Canceled buy deal
DEAL_TYPE_SELL_CANCELED = 14, //Canceled sell deal
DEAL_DIVIDEND = 15, //Dividend operations
DEAL_DIVIDEND_FRANKED = 16, //Franked (non-taxable) dividend operations
DEAL_TAX = 17 //Tax charges
}
public enum ENUM_DEAL_ENTRY
{
DEAL_ENTRY_IN = 0, //Entry in
DEAL_ENTRY_OUT = 1, //Entry out
DEAL_ENTRY_INOUT = 2, //Reverse
DEAL_ENTRY_STATE = 255 //Close a position by an opposite one
}
public enum ENUM_DEAL_REASON
{
DEAL_REASON_CLIENT = 0, //The deal was executed as a result of activation of an order placed from a desktop terminal
DEAL_REASON_MOBILE = 1, //The deal was executed as a result of activation of an order placed from a mobile application
DEAL_REASON_WEB = 2, //The deal was executed as a result of activation of an order placed from the web platform
DEAL_REASON_EXPERT = 3, //The deal was executed as a result of activation of an order placed from an MQL5 program, i.e. an Expert Advisor or a script
DEAL_REASON_SL = 4, //The deal was executed as a result of Stop Loss activation
DEAL_REASON_TP = 5, //The deal was executed as a result of Take Profit activation
DEAL_REASON_SO = 6, //The deal was executed as a result of the Stop Out event
DEAL_REASON_ROLLOVER = 7, //The deal was executed due to a rollover
DEAL_REASON_VMARGIN = 8, //The deal was executed after charging the variation margin
DEAL_REASON_SPLIT = 9 //The deal was executed after the split (price reduction) of an instrument, which had an open position during split announcement
}
#endregion //Deal Properties
#region Trade Operation Types
public enum ENUM_TRADE_REQUEST_ACTIONS
{
TRADE_ACTION_DEAL = 1, //Place a trade order for an immediate execution with the specified parameters (market order)
TRADE_ACTION_PENDING = 5, //Place a trade order for the execution under specified conditions (pending order)
TRADE_ACTION_SLTP = 6, //Modify Stop Loss and Take Profit values of an opened position
TRADE_ACTION_MODIFY = 7, //Modify the parameters of the order placed previously
TRADE_ACTION_REMOVE = 8, //Delete the pending order placed previously
TRADE_ACTION_CLOSE_BY = 10 //Close a position by an opposite one
}
#endregion //Trade Operation Types
#region Trade Transaction Types
public enum ENUM_TRADE_TRANSACTION_TYPE
{
TRADE_TRANSACTION_ORDER_ADD = 0, //Adding a new open order
TRADE_TRANSACTION_ORDER_UPDATE = 1, //Updating an open order
TRADE_TRANSACTION_ORDER_DELETE = 2, //Removing an order from the list of the open ones
TRADE_TRANSACTION_DEAL_ADD = 6, //Adding a deal to the history
TRADE_TRANSACTION_DEAL_UPDATE = 7, //Updating a deal in the history
TRADE_TRANSACTION_DEAL_DELETE = 8, //Deleting a deal from the history
TRADE_TRANSACTION_HISTORY_ADD = 3, //Adding an order to the history as a result of execution or cancellation
TRADE_TRANSACTION_HISTORY_UPDATE = 4, //Changing an order located in the orders history
TRADE_TRANSACTION_HISTORY_DELETE = 5, //Deleting an order from the orders history
TRADE_TRANSACTION_POSITION = 9, //Changing a position not related to a deal execution
TRADE_TRANSACTION_REQUEST = 10 //Notification of the fact that a trade request has been processed by a server and processing result has been received
}
#endregion //Trade Transaction Types
#region Trade Orders in Depth Of Market
public enum ENUM_BOOK_TYPE
{
BOOK_TYPE_SELL = 1,
BOOK_TYPE_BUY = 2,
BOOK_TYPE_SELL_MARKET = 3,
BOOK_TYPE_BUY_MARKET = 4
BOOK_TYPE_SELL = 1, //Sell order (Offer)
BOOK_TYPE_BUY = 2, //Buy order (Bid)
BOOK_TYPE_SELL_MARKET = 3, //Sell order by Market
BOOK_TYPE_BUY_MARKET = 4 //Buy order by Market
}
#endregion //Trade Orders in Depth Of Market
}
+15 -3
View File
@@ -223,6 +223,17 @@ namespace MtApi5
return SendCommand<bool>(Mt5CommandType.PositionSelect, commandParameters);
}
///<summary>
///Selects an open position to work with based on the ticket number specified in the position. If successful, returns true. Returns false if the function failed.
///</summary>
///<param name="ticket">Position ticket.</param>
public bool PositionSelectByTicket(ulong ticket)
{
var commandParameters = new ArrayList { ticket };
return SendCommand<bool>(Mt5CommandType.PositionSelectByTicket, commandParameters);
}
///<summary>
///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect.
///</summary>
@@ -486,9 +497,10 @@ namespace MtApi5
///Closes a position with the specified ticket.
///</summary>
///<param name="ticket">Ticket of the closed position.</param>
public bool PositionClose(int ticket)
///<param name="deviation">Maximal deviation from the current price (in points).</param>
public bool PositionClose(ulong ticket, ulong deviation = ulong.MaxValue)
{
var commandParameters = new ArrayList { ticket};
var commandParameters = new ArrayList { ticket, deviation };
return SendCommand<bool>(Mt5CommandType.PositionClose, commandParameters);
}
@@ -1660,7 +1672,7 @@ namespace MtApi5
private void OnConnected()
{
// INFO: disabled backtesting mode while solution of window handle in testing mode is not found
//_isBacktestingMode = IsTesting();
//_isBacktestingMode = IsTestMode();
if (_isBacktestingMode)
{
+1
View File
@@ -10,6 +10,7 @@
<OutputType>Package</OutputType>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<RunWixToolsOutOfProc>true</RunWixToolsOutOfProc>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>..\build\installers\$(Configuration)\</OutputPath>
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using MtApi5;
@@ -29,7 +26,7 @@ namespace MtApi5TestClient
}
}
public uint Magic
public ulong Magic
{
get { return TradeRequest.Magic; }
set
@@ -109,7 +106,7 @@ namespace MtApi5TestClient
}
}
public uint Deviation
public ulong Deviation
{
get { return TradeRequest.Deviation; }
set
+10 -1
View File
@@ -42,6 +42,7 @@ namespace TestApiClientUI
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
_apiClient.OnChartEvent += _apiClient_OnChartEvent;
InitOrderCommandsGroup();
@@ -134,7 +135,15 @@ namespace TestApiClientUI
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
{
var msg =
$"TimeBar: Symbol = {e.TimeBar.Symbol}, OpenTime = {e.TimeBar.OpenTime}, CloseTime = {e.TimeBar.CloseTime}, Open = {e.TimeBar.Open}, Close = {e.TimeBar.Close}, High = {e.TimeBar.High}, Low = {e.TimeBar.Low}";
$"TimeBar: ExpertHandle = {e.ExpertHandle}, Symbol = {e.TimeBar.Symbol}, OpenTime = {e.TimeBar.OpenTime}, CloseTime = {e.TimeBar.CloseTime}, Open = {e.TimeBar.Open}, Close = {e.TimeBar.Close}, High = {e.TimeBar.High}, Low = {e.TimeBar.Low}";
Console.WriteLine(msg);
PrintLog(msg);
}
private void _apiClient_OnChartEvent(object sender, ChartEventArgs e)
{
var msg =
$"OnChartEvent: ExpertHandle = {e.ExpertHandle}, ChartId = {e.ChartId}, EventId = {e.EventId}, Lparam = {e.Lparam}, Dparam = {e.Dparam}, Sparam = {e.Sparam}";
Console.WriteLine(msg);
PrintLog(msg);
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+390 -355
View File
File diff suppressed because it is too large Load Diff