mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-13 18:58:09 +00:00
Compare commits
117
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7b8ef894c | ||
|
|
7f33cebce1 | ||
|
|
84740787d5 | ||
|
|
ad6bad5187 | ||
|
|
0086b02bc8 | ||
|
|
f7e06c1570 | ||
|
|
c86a3a3752 | ||
|
|
be8a17c0fd | ||
|
|
5c6751de9b | ||
|
|
83776f8b7a | ||
|
|
f1c1df1e00 | ||
|
|
d6640300f5 | ||
|
|
c9c188f697 | ||
|
|
3a4f561836 | ||
|
|
bdb30edee3 | ||
|
|
29f501b055 | ||
|
|
521d7ea2c0 | ||
|
|
0e5bb40a6f | ||
|
|
14079dc3c1 | ||
|
|
3600a86971 | ||
|
|
83e62fbff7 | ||
|
|
5c96aeb2fd | ||
|
|
a238e5eb36 | ||
|
|
11fd5b7527 | ||
|
|
cbe75cfbf6 | ||
|
|
9581431a9f | ||
|
|
acf0c12531 | ||
|
|
1eccda9b2c | ||
|
|
fd4aac7c32 | ||
|
|
36c90c8481 | ||
|
|
fefa451371 | ||
|
|
1c57f88cb1 | ||
|
|
08ba45c65f | ||
|
|
b8314e9ed7 | ||
|
|
9587b10c8c | ||
|
|
b838084ba2 | ||
|
|
cd24891022 | ||
|
|
add69a4c03 | ||
|
|
5a3407e47c | ||
|
|
ce8cfbbb70 | ||
|
|
8470bbd5cc | ||
|
|
5c7ae748a5 | ||
|
|
7abb4d3b5e | ||
|
|
486c42685a | ||
|
|
f41ab37b6f | ||
|
|
9e129fb6e2 | ||
|
|
f7b00a8d88 | ||
|
|
a7cb14de25 | ||
|
|
f50925c8d3 | ||
|
|
e29a11de68 | ||
|
|
12141775f3 | ||
|
|
b6d24b8aa9 | ||
|
|
7175fae18c | ||
|
|
3c4d8d52ca | ||
|
|
6873363d41 | ||
|
|
947599327a | ||
|
|
5645902a48 | ||
|
|
c82787473f | ||
|
|
c213fb709a | ||
|
|
2ac29dc871 | ||
|
|
1f72b2b790 | ||
|
|
3a62ff56d7 | ||
|
|
d25fe529b4 | ||
|
|
15538e81f4 | ||
|
|
a33be3c764 | ||
|
|
023fe8c7c9 | ||
|
|
b77516e324 | ||
|
|
4b48423c3f | ||
|
|
9800177b08 | ||
|
|
a33d4a4594 | ||
|
|
29722f362d | ||
|
|
e072343fe1 | ||
|
|
acb0c20ca8 | ||
|
|
83543fee88 | ||
|
|
3ce6b042de | ||
|
|
9dd770e768 | ||
|
|
abb8b8afaa | ||
|
|
1d6569caa8 | ||
|
|
441a3cb8de | ||
|
|
443f5c982c | ||
|
|
515a12ab15 | ||
|
|
84b00b605a | ||
|
|
10e267d031 | ||
|
|
abcd489367 | ||
|
|
d630e61e3c | ||
|
|
280bab7faf | ||
|
|
26d270422b | ||
|
|
9cd2e3b18f | ||
|
|
50013c0c29 | ||
|
|
ca49d23017 | ||
|
|
0346836d35 | ||
|
|
2cc41df01a | ||
|
|
f05ade2cbf | ||
|
|
d34524d77f | ||
|
|
d06cc67a5d | ||
|
|
5b76bf0547 | ||
|
|
1c269f7339 | ||
|
|
21fb790d8c | ||
|
|
7c9a0aa8cc | ||
|
|
18ddf3df1c | ||
|
|
a8832b79ba | ||
|
|
39146d68b2 | ||
|
|
5b03f01e9b | ||
|
|
8f5a1c8222 | ||
|
|
f5f13a13cc | ||
|
|
9ef970cf1e | ||
|
|
b5878ccb62 | ||
|
|
4a7bb6f2cb | ||
|
|
5abfeebc90 | ||
|
|
e333164552 | ||
|
|
9a6968f618 | ||
|
|
d63a53b8a9 | ||
|
|
7e821fcade | ||
|
|
88e2d22abe | ||
|
|
fcfd741e5b | ||
|
|
c722511c03 | ||
|
|
39599436ab |
@@ -35,6 +35,4 @@ using namespace System::Security::Permissions;
|
|||||||
|
|
||||||
[assembly:ComVisible(false)];
|
[assembly:ComVisible(false)];
|
||||||
|
|
||||||
[assembly:CLSCompliantAttribute(true)];
|
[assembly:CLSCompliantAttribute(true)];
|
||||||
|
|
||||||
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
|
|
||||||
+157
-344
@@ -6,14 +6,15 @@
|
|||||||
#include "MT5Handler.h"
|
#include "MT5Handler.h"
|
||||||
|
|
||||||
#include "Windows.h"
|
#include "Windows.h"
|
||||||
#include < vcclr.h >
|
#include <vcclr.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
using namespace System;
|
using namespace System;
|
||||||
using namespace MTApiService;
|
using namespace MTApiService;
|
||||||
using namespace System::Runtime::InteropServices;
|
using namespace System::Runtime::InteropServices;
|
||||||
using namespace System::Reflection;
|
using namespace System::Reflection;
|
||||||
using namespace System::Text;
|
using namespace System::Text;
|
||||||
using namespace System::Collections::Generic;
|
using namespace System::Collections::Generic;
|
||||||
using namespace System::Diagnostics;
|
using namespace System::Diagnostics;
|
||||||
using namespace System::Security::Cryptography;
|
using namespace System::Security::Cryptography;
|
||||||
using namespace System::Security;
|
using namespace System::Security;
|
||||||
@@ -50,277 +51,162 @@ public struct CMqlBookInfo
|
|||||||
|
|
||||||
void convertSystemString(wchar_t* dest, String^ src)
|
void convertSystemString(wchar_t* dest, String^ src)
|
||||||
{
|
{
|
||||||
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
|
if (src != nullptr) {
|
||||||
memcpy(dest, wch, wcslen(wch) * sizeof(wchar_t));
|
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
|
||||||
dest[wcslen(wch)] = '\0';
|
memcpy(dest, wch, wcsnlen(wch, 1000) * sizeof(wchar_t));
|
||||||
|
dest[wcsnlen(wch, 1000)] = L'\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dest[0] = L'\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VerifySignature(System::String^ inputData, System::String^ signature, System::String^ publicKey)
|
#define _DLLAPI extern "C" __declspec(dllexport)
|
||||||
{
|
|
||||||
bool verifyResult = false;
|
|
||||||
|
|
||||||
|
template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default_value)
|
||||||
|
{
|
||||||
|
T result = default_value;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DSACryptoServiceProvider^ dsa = gcnew DSACryptoServiceProvider();
|
result = func();
|
||||||
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();
|
|
||||||
MtServerInstance::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHander);
|
|
||||||
}
|
}
|
||||||
catch (Exception^ e)
|
catch (Exception^ e)
|
||||||
{
|
{
|
||||||
convertSystemString(err, e->Message);
|
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
|
return Execute<int>([&expertHandle, &port, symbol, &bid, &ask, &isTestMode]() {
|
||||||
{
|
bool isTesting = (isTestMode != 0) ? true : false;
|
||||||
MtServerInstance::GetInstance()->DeinitExpert(expertHandle);
|
auto expert = gcnew Mt5Expert(expertHandle, gcnew String(symbol), bid, ask, gcnew MT5Handler(), isTesting);
|
||||||
}
|
MtAdapter::GetInstance()->AddExpert(port, expert);
|
||||||
catch (Exception^ e)
|
return 1;
|
||||||
{
|
}, err, 0);
|
||||||
convertSystemString(err, e->Message);
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:deinitExpert(): " + e->Message);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
MtServerInstance::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
convertSystemString(err, e->Message);
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:updateQuote(): " + e->Message);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendIntResponse(int expertHandle, int response)
|
_DLLAPI int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<int>([&expertHandle, symbol, &bid, &ask]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendIntResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendLongResponse(int expertHandle, __int64 response)
|
_DLLAPI bool _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &eventType, payload]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendEvent(expertHandle, eventType, gcnew String(payload));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendLongResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendULongResponse(int expertHandle, unsigned __int64 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));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseULong(response));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendLongResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendBooleanResponse(int expertHandle, int 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));
|
||||||
|
return 1;
|
||||||
|
}, err, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI int _stdcall sendULongResponse(int expertHandle, unsigned __int64 response, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<int>([&expertHandle, &response]() {
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseULong(response));
|
||||||
|
return 1;
|
||||||
|
}, err, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI int _stdcall sendBooleanResponse(int expertHandle, int response, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<int>([&expertHandle, &response]() {
|
||||||
bool value = (response != 0) ? true : false;
|
bool value = (response != 0) ? true : false;
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendBooleanResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendDoubleResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendStringResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendVoidResponse(int expertHandle)
|
_DLLAPI int _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<int>([&expertHandle]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendResponse(expertHandle, nullptr);
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, nullptr);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendVoidResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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];
|
list[i] = values[i];
|
||||||
}
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
|
||||||
|
return 1;
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
|
}, err, 0);
|
||||||
}
|
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendDoubleArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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];
|
list[i] = values[i];
|
||||||
}
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
|
||||||
|
return 1;
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
|
}, err, 0);
|
||||||
}
|
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendIntArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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];
|
list[i] = values[i];
|
||||||
}
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLongArray(list));
|
||||||
|
return 1;
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLongArray(list));
|
}, err, 0);
|
||||||
}
|
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendLongArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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();
|
MtMqlRates^ rates = gcnew MtMqlRates();
|
||||||
rates->time = values[i].time;
|
rates->time = values[i].time;
|
||||||
@@ -331,180 +217,107 @@ int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int
|
|||||||
rates->tick_volume = values[i].tick_volume;
|
rates->tick_volume = values[i].tick_volume;
|
||||||
rates->spread = values[i].spread;
|
rates->spread = values[i].spread;
|
||||||
rates->real_volume = values[i].real_volume;
|
rates->real_volume = values[i].real_volume;
|
||||||
|
|
||||||
list[i] = rates;
|
list[i] = rates;
|
||||||
}
|
}
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlRatesArray(list));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlRatesArray(list));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendMqlRatesArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
MtMqlTick^ mtResponse = gcnew MtMqlTick();
|
||||||
|
|
||||||
mtResponse->time = response->time;
|
mtResponse->time = response->time;
|
||||||
mtResponse->bid = response->bid;
|
mtResponse->bid = response->bid;
|
||||||
mtResponse->ask = response->ask;
|
mtResponse->ask = response->ask;
|
||||||
mtResponse->last = response->last;
|
mtResponse->last = response->last;
|
||||||
mtResponse->volume = response->volume;
|
mtResponse->volume = response->volume;
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendMqlTickResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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();
|
MtMqlBookInfo^ info = gcnew MtMqlBookInfo();
|
||||||
|
|
||||||
info->type = values[i].type;
|
info->type = values[i].type;
|
||||||
info->price = values[i].price;
|
info->price = values[i].price;
|
||||||
info->volume = values[i].volume;
|
info->volume = values[i].volume;
|
||||||
|
|
||||||
list[i] = info;
|
list[i] = info;
|
||||||
}
|
}
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:sendMqlRatesArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------- get values -------------------------------
|
//----------- 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);
|
||||||
*res = MtServerInstance::GetInstance()->GetCommandType(expertHandle);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getCommandType(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
*res = (int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getIntValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
*res = (double)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (double)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getDoubleValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
convertSystemString(res, (String^)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
|
||||||
convertSystemString(res, (String^)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getStringValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
*res = (unsigned __int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (unsigned long)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getULongValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
*res = (__int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (long)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getLongValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
bool val = (bool)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
|
||||||
*res = val == true ? 1 : 0;
|
*res = val == true ? 1 : 0;
|
||||||
}
|
return 1;
|
||||||
catch (Exception^ e)
|
}, err, 0);
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
*res = (unsigned int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (unsigned int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return 1;
|
||||||
}
|
}, err, 0);
|
||||||
catch (Exception^ e)
|
}
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getUIntValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -95,7 +95,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -108,7 +107,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -120,7 +118,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -132,7 +129,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -157,7 +153,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.ico" />
|
<None Include="app.ico" />
|
||||||
<None Include="MT5Connector.def" />
|
|
||||||
<None Include="ReadMe.txt" />
|
<None Include="ReadMe.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -44,9 +44,6 @@
|
|||||||
<None Include="app.ico">
|
<None Include="app.ico">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="MT5Connector.def">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="app.rc">
|
<ResourceCompile Include="app.rc">
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
public interface ICommandManager
|
internal interface ICommandManager
|
||||||
{
|
{
|
||||||
void EnqueueCommandTask(MtCommandTask task);
|
MtCommandTask SendCommand(MtCommand task);
|
||||||
MtCommandTask DequeueCommandTask();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
using System;
|
namespace MTApiService
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MTApiService
|
|
||||||
{
|
{
|
||||||
public interface IMetaTraderHandler
|
public interface IMetaTraderHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MTApiService
|
||||||
|
{
|
||||||
|
internal interface ITaskExecutor
|
||||||
|
{
|
||||||
|
void Execute(MtCommandTask task);
|
||||||
|
|
||||||
|
int Handle { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,50 @@ using log4net.Repository.Hierarchy;
|
|||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
public class MtLog
|
||||||
|
{
|
||||||
|
#region ctor
|
||||||
|
internal MtLog(Type type)
|
||||||
|
{
|
||||||
|
_log = LogManager.GetLogger(type);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public
|
||||||
|
|
||||||
|
public void Debug(object message)
|
||||||
|
{
|
||||||
|
_log.Debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(object message)
|
||||||
|
{
|
||||||
|
_log.Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fatal(object message)
|
||||||
|
{
|
||||||
|
_log.Fatal(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Info(object message)
|
||||||
|
{
|
||||||
|
_log.Info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warn(object message)
|
||||||
|
{
|
||||||
|
_log.Warn(message);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private
|
||||||
|
|
||||||
|
private readonly ILog _log;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
public class LogConfigurator
|
public class LogConfigurator
|
||||||
{
|
{
|
||||||
private const string LogFileNameExtension = "txt";
|
private const string LogFileNameExtension = "txt";
|
||||||
@@ -29,7 +73,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
var roller = new RollingFileAppender
|
var roller = new RollingFileAppender
|
||||||
{
|
{
|
||||||
AppendToFile = false,
|
AppendToFile = true,
|
||||||
File = $@"{System.IO.Path.GetTempPath()}{profileName}\Logs\{filename}",
|
File = $@"{System.IO.Path.GetTempPath()}{profileName}\Logs\{filename}",
|
||||||
Layout = patternLayout,
|
Layout = patternLayout,
|
||||||
PreserveLogFileNameExtension = true,
|
PreserveLogFileNameExtension = true,
|
||||||
@@ -41,10 +85,6 @@ namespace MTApiService
|
|||||||
roller.ActivateOptions();
|
roller.ActivateOptions();
|
||||||
hierarchy.Root.AddAppender(roller);
|
hierarchy.Root.AddAppender(roller);
|
||||||
|
|
||||||
var memory = new MemoryAppender();
|
|
||||||
memory.ActivateOptions();
|
|
||||||
hierarchy.Root.AddAppender(memory);
|
|
||||||
|
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
hierarchy.Root.Level = Level.Debug;
|
hierarchy.Root.Level = Level.Debug;
|
||||||
#else
|
#else
|
||||||
@@ -52,5 +92,13 @@ namespace MTApiService
|
|||||||
#endif
|
#endif
|
||||||
hierarchy.Configured = true;
|
hierarchy.Configured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MtLog GetLogger(Type type)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException(nameof(type));
|
||||||
|
|
||||||
|
return new MtLog(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ICommandManager.cs" />
|
<Compile Include="ICommandManager.cs" />
|
||||||
<Compile Include="IMetaTraderHandler.cs" />
|
<Compile Include="IMetaTraderHandler.cs" />
|
||||||
|
<Compile Include="ITaskExecutor.cs" />
|
||||||
<Compile Include="LogConfigurator.cs" />
|
<Compile Include="LogConfigurator.cs" />
|
||||||
|
<Compile Include="Mt5Expert.cs" />
|
||||||
<Compile Include="MtCommandEventArgs.cs" />
|
<Compile Include="MtCommandEventArgs.cs" />
|
||||||
<Compile Include="IDisposableChannel.cs" />
|
<Compile Include="IDisposableChannel.cs" />
|
||||||
<Compile Include="IMtApiServer.cs" />
|
<Compile Include="IMtApiServer.cs" />
|
||||||
@@ -78,11 +80,11 @@
|
|||||||
<Compile Include="MtConnectionProfile.cs" />
|
<Compile Include="MtConnectionProfile.cs" />
|
||||||
<Compile Include="MtExecutorManager.cs" />
|
<Compile Include="MtExecutorManager.cs" />
|
||||||
<Compile Include="MtExpert.cs" />
|
<Compile Include="MtExpert.cs" />
|
||||||
<Compile Include="MtInstrument.cs" />
|
<Compile Include="MtQuote.cs" />
|
||||||
<Compile Include="MtResponse.cs" />
|
<Compile Include="MtResponse.cs" />
|
||||||
<Compile Include="MtServer.cs" />
|
<Compile Include="MtServer.cs" />
|
||||||
<Compile Include="MtCommand.cs" />
|
<Compile Include="MtCommand.cs" />
|
||||||
<Compile Include="MtServerInstance.cs" />
|
<Compile Include="MtAdapter.cs" />
|
||||||
<Compile Include="MtService.cs" />
|
<Compile Include="MtService.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable → Regular
+64
-22
@@ -4,13 +4,13 @@ using log4net;
|
|||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
public class MtServerInstance
|
public class MtAdapter
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private const string LogProfileName = "MtApiService";
|
private const string LogProfileName = "MtApiService";
|
||||||
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtServerInstance));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(MtAdapter));
|
||||||
private static readonly MtServerInstance Instance = new MtServerInstance();
|
private static readonly MtAdapter Instance = new MtAdapter();
|
||||||
|
|
||||||
private readonly Dictionary<int, MtServer> _servers = new Dictionary<int, MtServer>();
|
private readonly Dictionary<int, MtServer> _servers = new Dictionary<int, MtServer>();
|
||||||
private readonly Dictionary<int, MtExpert> _experts = new Dictionary<int, MtExpert>();
|
private readonly Dictionary<int, MtExpert> _experts = new Dictionary<int, MtExpert>();
|
||||||
@@ -18,16 +18,16 @@ namespace MTApiService
|
|||||||
|
|
||||||
#region Init Instance
|
#region Init Instance
|
||||||
|
|
||||||
private MtServerInstance()
|
private MtAdapter()
|
||||||
{
|
{
|
||||||
LogConfigurator.Setup(LogProfileName);
|
LogConfigurator.Setup(LogProfileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static MtServerInstance()
|
static MtAdapter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MtServerInstance GetInstance()
|
public static MtAdapter GetInstance()
|
||||||
{
|
{
|
||||||
return Instance;
|
return Instance;
|
||||||
}
|
}
|
||||||
@@ -36,12 +36,12 @@ namespace MTApiService
|
|||||||
|
|
||||||
|
|
||||||
#region Public Methods
|
#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)
|
if (expert == null)
|
||||||
throw new ArgumentNullException(nameof(mtHandler));
|
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;
|
MtServer server;
|
||||||
lock (_servers)
|
lock (_servers)
|
||||||
@@ -60,8 +60,6 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var expert = new MtExpert(expertHandle, new MtQuote(symbol, bid, ask), mtHandler);
|
|
||||||
|
|
||||||
lock (_experts)
|
lock (_experts)
|
||||||
{
|
{
|
||||||
_experts[expert.Handle] = expert;
|
_experts[expert.Handle] = expert;
|
||||||
@@ -69,12 +67,12 @@ namespace MTApiService
|
|||||||
|
|
||||||
server.AddExpert(expert);
|
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;
|
MtExpert expert = null;
|
||||||
|
|
||||||
@@ -93,15 +91,15 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
else
|
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)
|
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;
|
MtExpert expert;
|
||||||
lock (_experts)
|
lock (_experts)
|
||||||
@@ -111,14 +109,14 @@ namespace MTApiService
|
|||||||
|
|
||||||
if (expert != null)
|
if (expert != null)
|
||||||
{
|
{
|
||||||
expert.Quote = new MtQuote(symbol, bid, ask);
|
expert.UpdateQuote(new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle });
|
||||||
}
|
}
|
||||||
else
|
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)
|
public void SendEvent(int expertHandle, int eventType, string payload)
|
||||||
@@ -133,7 +131,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
if (expert != null)
|
if (expert != null)
|
||||||
{
|
{
|
||||||
expert.SendEvent(new MtEvent(eventType, payload));
|
expert.SendEvent(new MtEvent { EventType = eventType, Payload = payload, ExpertHandle = expertHandle });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -208,6 +206,50 @@ namespace MTApiService
|
|||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object GetNamedParameter(int expertHandle, string name)
|
||||||
|
{
|
||||||
|
Log.DebugFormat("GetNamedParameter: begin. expertHandle = {0}, name = {1}", expertHandle, name);
|
||||||
|
|
||||||
|
MtExpert expert;
|
||||||
|
lock (_experts)
|
||||||
|
{
|
||||||
|
expert = _experts[expertHandle];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expert == null)
|
||||||
|
{
|
||||||
|
Log.WarnFormat("GetNamedParameter: expert with id {0} has not been found.", expertHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
var retval = expert?.GetNamedParameter(name);
|
||||||
|
|
||||||
|
Log.DebugFormat("GetNamedParameter: end. retval = {0}", retval);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsNamedParameter(int expertHandle, string name)
|
||||||
|
{
|
||||||
|
Log.DebugFormat("ContainsNamedParameter: begin. expertHandle = {0}, name = {1}", expertHandle, name);
|
||||||
|
|
||||||
|
MtExpert expert;
|
||||||
|
lock (_experts)
|
||||||
|
{
|
||||||
|
expert = _experts[expertHandle];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expert == null)
|
||||||
|
{
|
||||||
|
Log.WarnFormat("ContainsNamedParameter: expert with id {0} has not been found.", expertHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool retval = expert != null ? expert.ContainsNamedParameter(name) : false;
|
||||||
|
|
||||||
|
Log.DebugFormat("ContainsNamedParameter: end. retval = {0}", retval);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
@@ -11,13 +11,13 @@ namespace MTApiService
|
|||||||
: base(callbackContext, binding, remoteAddress)
|
: base(callbackContext, binding, remoteAddress)
|
||||||
{
|
{
|
||||||
InnerDuplexChannel.Faulted += InnerDuplexChannel_Faulted;
|
InnerDuplexChannel.Faulted += InnerDuplexChannel_Faulted;
|
||||||
InnerDuplexChannel.Open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IMtApi Members
|
#region IMtApi Members
|
||||||
|
|
||||||
public bool Connect()
|
public bool Connect()
|
||||||
{
|
{
|
||||||
|
InnerDuplexChannel.Open();
|
||||||
return Channel.Connect();
|
return Channel.Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+42
-90
@@ -6,38 +6,33 @@ using log4net;
|
|||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
[CallbackBehavior(UseSynchronizationContext = false)]
|
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
|
||||||
public class MtClient: IMtApiCallback, IDisposable
|
public class MtClient : IMtApiCallback, IDisposable
|
||||||
{
|
{
|
||||||
private const string ServiceName = "MtApiService";
|
private const string ServiceName = "MtApiService";
|
||||||
|
|
||||||
public delegate void MtQuoteHandler(MtQuote quote);
|
public delegate void MtQuoteHandler(MtQuote quote);
|
||||||
|
public delegate void MtEventHandler(MtEvent e);
|
||||||
|
|
||||||
#region Fields
|
#region Fields
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtClient));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(MtClient));
|
||||||
|
|
||||||
private MtApiProxy _proxy;
|
private readonly MtApiProxy _proxy;
|
||||||
private bool _isConnected;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region ctor
|
||||||
public void Open(string host, int port)
|
public MtClient(string host, int port)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Open: begin. host = {0}, port = {1}", host, port);
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(host))
|
if (string.IsNullOrEmpty(host))
|
||||||
throw new ArgumentNullException(nameof(host), "host is null or empty");
|
throw new ArgumentNullException(nameof(host), "host is null or empty");
|
||||||
|
|
||||||
if (port < 0 || port > 65536)
|
if (port < 0 || port > 65536)
|
||||||
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");
|
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");
|
||||||
|
|
||||||
var urlService = $"net.tcp://{host}:{port}/{ServiceName}";
|
Host = host;
|
||||||
|
Port = port;
|
||||||
|
|
||||||
if (_proxy != null)
|
var urlService = $"net.tcp://{host}:{port}/{ServiceName}";
|
||||||
{
|
|
||||||
Log.Warn("Open: end. _proxy is not null.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bind = new NetTcpBinding(SecurityMode.None)
|
var bind = new NetTcpBinding(SecurityMode.None)
|
||||||
{
|
{
|
||||||
@@ -55,28 +50,19 @@ namespace MTApiService
|
|||||||
MaxNameTableCharCount = 2147483647
|
MaxNameTableCharCount = 2147483647
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Commented next statement since it is not required
|
|
||||||
|
|
||||||
_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
||||||
_proxy.Faulted += ProxyFaulted;
|
_proxy.Faulted += ProxyFaulted;
|
||||||
|
|
||||||
Log.Debug("Open: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open(int port)
|
public MtClient(int port)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Open: begin. port = {0}", port);
|
|
||||||
|
|
||||||
if (port < 0 || port > 65536)
|
if (port < 0 || port > 65536)
|
||||||
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");
|
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");
|
||||||
|
|
||||||
var urlService = $"net.pipe://localhost/{ServiceName}_{port}";
|
Port = port;
|
||||||
|
|
||||||
if (_proxy != null)
|
var urlService = $"net.pipe://localhost/{ServiceName}_{port}";
|
||||||
{
|
|
||||||
Log.Warn("Open: end. _proxy is not null.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
|
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
|
||||||
{
|
{
|
||||||
@@ -94,61 +80,40 @@ namespace MTApiService
|
|||||||
MaxNameTableCharCount = 2147483647
|
MaxNameTableCharCount = 2147483647
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Commented next statement since it is not required
|
|
||||||
|
|
||||||
_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
||||||
_proxy.Faulted += ProxyFaulted;
|
_proxy.Faulted += ProxyFaulted;
|
||||||
|
|
||||||
Log.Debug("Open: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
Log.Debug("Close: begin.");
|
|
||||||
|
|
||||||
if (_proxy != null)
|
#endregion
|
||||||
{
|
|
||||||
_proxy.Faulted -= ProxyFaulted;
|
|
||||||
_proxy.Dispose();
|
|
||||||
_proxy = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
_isConnected = false;
|
|
||||||
|
|
||||||
Log.Debug("Close: end.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
Log.Debug("Connect: begin.");
|
Log.Debug("Connect: begin.");
|
||||||
|
|
||||||
if (_proxy == null)
|
if (_proxy.State != CommunicationState.Created)
|
||||||
{
|
{
|
||||||
Log.Error("Connect: _proxy is not defined.");
|
Log.ErrorFormat("Connected: end. Client has invalid state {0}", _proxy.State);
|
||||||
throw new CommunicationException("Connection failed to service. Proxy is not defined (needs to call Open)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_isConnected)
|
|
||||||
{
|
|
||||||
Log.Warn("Connected: end. Client is already connected.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool coonected;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_isConnected = _proxy.Connect();
|
coonected = _proxy.Connect();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Connect: Exception - {0}", ex.Message);
|
Log.ErrorFormat("Connect: Exception - {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
|
||||||
|
|
||||||
throw new CommunicationException($"Connection failed to service. {ex.Message}");
|
throw new CommunicationException($"Connection failed to service. {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_isConnected == false)
|
if (coonected == false)
|
||||||
{
|
{
|
||||||
Log.Error("Connect: end. Connection failed.");
|
Log.Error("Connect: end. Connection failed.");
|
||||||
throw new CommunicationException("Connection failed");
|
throw new CommunicationException("Connection failed");
|
||||||
@@ -163,72 +128,60 @@ namespace MTApiService
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_isConnected = false;
|
_proxy.Disconnect();
|
||||||
|
|
||||||
_proxy?.Disconnect();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Disconnect: Exception - {0}", ex.Message);
|
Log.ErrorFormat("Disconnect: Exception - {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("Disconnect: end.");
|
Log.Debug("Disconnect: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
||||||
public MtResponse SendCommand(int commandType, ArrayList parameters)
|
public MtResponse SendCommand(int commandType, ArrayList parameters, Dictionary<string, object> namedParams, int expertHandle)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendCommand: begin. commandType = {0}, parameters count = {1}", commandType, parameters?.Count);
|
Log.DebugFormat("SendCommand: begin. commandType = {0}, parameters count = {1}", commandType, parameters?.Count);
|
||||||
|
|
||||||
MtResponse result;
|
if (IsConnected == false)
|
||||||
|
|
||||||
if (_isConnected == false)
|
|
||||||
{
|
{
|
||||||
Log.Error("SendCommand: Client is not connected.");
|
Log.Error("SendCommand: Client is not connected.");
|
||||||
throw new CommunicationException("Client is not connected.");
|
throw new CommunicationException("Client is not connected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_proxy == null)
|
MtResponse result;
|
||||||
{
|
|
||||||
Log.Error("SendCommand: Proxy is not defined.");
|
|
||||||
throw new CommunicationException("Proxy is not defined.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = _proxy.SendCommand(new MtCommand(commandType, parameters));
|
result = _proxy.SendCommand(new MtCommand {
|
||||||
|
CommandType = commandType,
|
||||||
|
Parameters = parameters,
|
||||||
|
NamedParams = namedParams,
|
||||||
|
ExpertHandle = expertHandle});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("SendCommand: Exception - {0}", ex.Message);
|
Log.ErrorFormat("SendCommand: Exception - {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
|
||||||
|
|
||||||
throw new CommunicationException("Service connection failed! " + ex.Message);
|
throw new CommunicationException("Service connection failed! " + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.DebugFormat("SendCommand: end. result = {0}", result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
||||||
public IEnumerable<MtQuote> GetQuotes()
|
public List<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
Log.Debug("GetQuotes: begin.");
|
Log.Debug("GetQuotes: begin.");
|
||||||
|
|
||||||
if (_isConnected == false)
|
if (IsConnected == false)
|
||||||
{
|
{
|
||||||
Log.Warn("GetQuotes: end. Client is not connected.");
|
Log.Warn("GetQuotes: end. Client is not connected.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_proxy == null)
|
|
||||||
{
|
|
||||||
Log.Warn("GetQuotes: end. _proxy is not defined.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MtQuote> result;
|
List<MtQuote> result;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -239,8 +192,6 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Log.ErrorFormat("GetQuotes: Exception - {0}", ex.Message);
|
Log.ErrorFormat("GetQuotes: Exception - {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
|
||||||
|
|
||||||
throw new CommunicationException($"Service connection failed! {ex.Message}");
|
throw new CommunicationException($"Service connection failed! {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,18 +237,17 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Log.Debug("OnServerStopped: begin.");
|
Log.Debug("OnServerStopped: begin.");
|
||||||
|
|
||||||
Close();
|
|
||||||
ServerDisconnected?.Invoke(this, EventArgs.Empty);
|
ServerDisconnected?.Invoke(this, EventArgs.Empty);
|
||||||
|
|
||||||
Log.Debug("OnServerStopped: end.");
|
Log.Debug("OnServerStopped: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnMtEvent(MtEvent mtEvent)
|
public void OnMtEvent(MtEvent e)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("OnMtEvent: begin. event = {0}", mtEvent);
|
Log.DebugFormat("OnMtEvent: begin. event = {0}", e);
|
||||||
|
|
||||||
MtEventReceived?.Invoke(this, new MtEventArgs(mtEvent));
|
MtEventReceived?.Invoke(e);
|
||||||
|
|
||||||
Log.Debug("OnMtEvent: end.");
|
Log.Debug("OnMtEvent: end.");
|
||||||
}
|
}
|
||||||
@@ -305,7 +255,10 @@ namespace MTApiService
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public bool IsConnected => _proxy.State == CommunicationState.Opened && _isConnected;
|
public string Host { get; private set; }
|
||||||
|
public int Port { get; private set; }
|
||||||
|
|
||||||
|
private bool IsConnected => _proxy.State == CommunicationState.Opened;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -315,7 +268,6 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Log.Debug("ProxyFaulted: begin.");
|
Log.Debug("ProxyFaulted: begin.");
|
||||||
|
|
||||||
Close();
|
|
||||||
ServerFailed?.Invoke(this, EventArgs.Empty);
|
ServerFailed?.Invoke(this, EventArgs.Empty);
|
||||||
|
|
||||||
Log.Debug("ProxyFaulted: end.");
|
Log.Debug("ProxyFaulted: end.");
|
||||||
@@ -329,7 +281,7 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Log.Debug("Dispose: begin.");
|
Log.Debug("Dispose: begin.");
|
||||||
|
|
||||||
Close();
|
_proxy.Dispose();
|
||||||
|
|
||||||
Log.Debug("Dispose: end.");
|
Log.Debug("Dispose: end.");
|
||||||
}
|
}
|
||||||
@@ -342,7 +294,7 @@ namespace MTApiService
|
|||||||
public event MtQuoteHandler QuoteUpdated;
|
public event MtQuoteHandler QuoteUpdated;
|
||||||
public event EventHandler ServerDisconnected;
|
public event EventHandler ServerDisconnected;
|
||||||
public event EventHandler ServerFailed;
|
public event EventHandler ServerFailed;
|
||||||
public event EventHandler<MtEventArgs> MtEventReceived;
|
public event MtEventHandler MtEventReceived;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class MtCommand
|
public class MtCommand
|
||||||
{
|
{
|
||||||
public MtCommand(int commandType, ArrayList parameters)
|
[DataMember]
|
||||||
{
|
public int CommandType { get; set; }
|
||||||
CommandType = commandType;
|
|
||||||
Parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int CommandType { get; private set; }
|
public ArrayList Parameters { get; set; }
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public ArrayList Parameters { get; private set; }
|
public Dictionary<string, object> NamedParams { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public int ExpertHandle { get; set; }
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"CommandType = {CommandType}";
|
return $"CommandType = {CommandType}; ExpertHandle = {ExpertHandle}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace MTApiService
|
|||||||
Command = command;
|
Command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtCommand Command { get; private set; }
|
public MtCommand Command { get; }
|
||||||
|
|
||||||
public MtResponse WaitResult(int time)
|
public MtResponse WaitResult(int time)
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-18
@@ -7,30 +7,17 @@ namespace MTApiService
|
|||||||
public class MtEvent
|
public class MtEvent
|
||||||
{
|
{
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int EventType { get; private set; }
|
public int EventType { get; internal set; }
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Payload { get; private set; }
|
public string Payload { get; internal set; }
|
||||||
|
|
||||||
public MtEvent(int eventType, string payload)
|
[DataMember]
|
||||||
{
|
public int ExpertHandle { get; internal set; }
|
||||||
EventType = eventType;
|
|
||||||
Payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "MtEvent = " + EventType + ", Payload = " + Payload;
|
return $"EventType = {EventType}; Payload = {Payload}; ExpertHandle = {ExpertHandle}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MtEventArgs: EventArgs
|
|
||||||
{
|
|
||||||
public MtEventArgs(MtEvent e)
|
|
||||||
{
|
|
||||||
Event = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MtEvent Event { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ using log4net;
|
|||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
internal class MtCommandExecutorManager : ICommandManager
|
internal class MtExecutorManager : ICommandManager
|
||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtCommandExecutorManager));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExecutorManager));
|
||||||
|
|
||||||
private readonly List<MtExpert> _commandExecutors = new List<MtExpert>();
|
|
||||||
private readonly Queue<MtCommandTask> _commandTasks = new Queue<MtCommandTask>();
|
|
||||||
|
|
||||||
|
private readonly List<ITaskExecutor> _executorList = new List<ITaskExecutor>();
|
||||||
|
private readonly Dictionary<int, ITaskExecutor> _executorMap = new Dictionary<int, ITaskExecutor>();
|
||||||
private readonly object _locker = new object();
|
private readonly object _locker = new object();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -23,149 +22,94 @@ namespace MTApiService
|
|||||||
|
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
_commandExecutors.Clear();
|
_executorList.Clear();
|
||||||
_commandTasks.Clear();
|
_executorMap.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("Stop: end.");
|
Log.Debug("Stop: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCommandExecutor(MtExpert commandExecutor)
|
public void AddExecutor(ITaskExecutor executor)
|
||||||
{
|
{
|
||||||
if (commandExecutor == null)
|
if (executor == null)
|
||||||
throw new ArgumentNullException(nameof(commandExecutor));
|
throw new ArgumentNullException(nameof(executor));
|
||||||
|
|
||||||
Log.DebugFormat("AddCommandExecutor: begin. commandExecutor = {0}", commandExecutor);
|
Log.DebugFormat("AddExecutor: begin. executor = {0}", executor);
|
||||||
|
|
||||||
var notify = false;
|
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
if (_commandExecutors.Contains(commandExecutor))
|
if (_executorList.Contains(executor))
|
||||||
{
|
{
|
||||||
Log.Warn("AddCommandExecutor: end. Command executor already exist.");
|
Log.Warn("AddExecutor: end. Executor already exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_commandExecutors.Add(commandExecutor);
|
_executorList.Add(executor);
|
||||||
if (_commandTasks.Count > 0)
|
_executorMap[executor.Handle] = executor;
|
||||||
{
|
|
||||||
notify = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commandExecutor.CommandExecuted += CommandExecutor_CommandExecuted;
|
|
||||||
commandExecutor.CommandManager = this;
|
|
||||||
|
|
||||||
if (notify)
|
|
||||||
{
|
|
||||||
NotifyCommandReady();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("AddCommandExecutor: end.");
|
Log.Debug("AddCommandExecutor: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveCommandExecutor(MtExpert commandExecutor)
|
public void RemoveExecutor(ITaskExecutor executor)
|
||||||
{
|
{
|
||||||
if (commandExecutor == null)
|
if (executor == null)
|
||||||
throw new ArgumentNullException(nameof(commandExecutor));
|
throw new ArgumentNullException(nameof(executor));
|
||||||
|
|
||||||
Log.DebugFormat("RemoveCommandExecutor: begin. commandExecutor = {0}", commandExecutor);
|
Log.DebugFormat("RemoveExecutor: begin. executor = {0}", executor);
|
||||||
|
|
||||||
var notify = false;
|
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
if (_commandExecutors.Contains(commandExecutor) == false)
|
if (_executorList.Contains(executor) == false)
|
||||||
{
|
{
|
||||||
Log.Warn("RemoveCommandExecutor: end. Command executor is not exist in collection.");
|
Log.Warn("RemoveExecutor: end. Executor is not exist in collection.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_commandExecutors.Remove(commandExecutor);
|
_executorList.Remove(executor);
|
||||||
if (_commandTasks.Count > 0)
|
_executorMap.Remove(executor.Handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Debug("RemoveExecutor: end.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public MtCommandTask SendCommand(MtCommand command)
|
||||||
|
{
|
||||||
|
if (command == null)
|
||||||
|
throw new ArgumentNullException(nameof(command));
|
||||||
|
|
||||||
|
var task = new MtCommandTask(command);
|
||||||
|
|
||||||
|
Log.DebugFormat("SendTask: begin. command = {0}", command);
|
||||||
|
|
||||||
|
ITaskExecutor executor;
|
||||||
|
|
||||||
|
lock (_locker)
|
||||||
|
{
|
||||||
|
if (_executorMap.ContainsKey(command.ExpertHandle))
|
||||||
{
|
{
|
||||||
notify = true;
|
executor = _executorMap[command.ExpertHandle];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
executor = _executorList.Count > 0 ? _executorList[0] : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commandExecutor.CommandExecuted -= CommandExecutor_CommandExecuted;
|
if (executor == null)
|
||||||
commandExecutor.CommandManager = null;
|
|
||||||
|
|
||||||
if (notify)
|
|
||||||
{
|
{
|
||||||
NotifyCommandReady();
|
Log.Error("SendTask: Executor is null!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
executor.Execute(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("RemoveCommandExecutor: end.");
|
Log.Debug("SendTask: end.");
|
||||||
|
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnqueueCommandTask(MtCommandTask task)
|
|
||||||
{
|
|
||||||
if (task == null)
|
|
||||||
throw new ArgumentNullException(nameof(task));
|
|
||||||
|
|
||||||
Log.DebugFormat("EnqueueCommandTask: begin. task = {0}", task);
|
|
||||||
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
_commandTasks.Enqueue(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
NotifyCommandReady();
|
|
||||||
|
|
||||||
Log.Debug("EnqueueCommandTask: end.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public MtCommandTask DequeueCommandTask()
|
|
||||||
{
|
|
||||||
Log.Debug("DequeueCommandTask: called.");
|
|
||||||
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
return _commandTasks.Count > 0 ? _commandTasks.Dequeue() : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Methods
|
|
||||||
private void NotifyCommandReady()
|
|
||||||
{
|
|
||||||
Log.Debug("NotifyCommandReady: begin.");
|
|
||||||
|
|
||||||
var commandExecutors = new List<MtExpert>();
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
commandExecutors.AddRange(_commandExecutors);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var executor in commandExecutors)
|
|
||||||
{
|
|
||||||
executor.NotifyCommandReady();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.DebugFormat("NotifyCommandReady: end. Notified executor count = {0}", commandExecutors.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CommandExecutor_CommandExecuted(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Log.Debug("CommandExecutor_CommandExecuted: begin.");
|
|
||||||
|
|
||||||
var notify = false;
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
if (_commandTasks.Count > 0)
|
|
||||||
{
|
|
||||||
notify = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notify)
|
|
||||||
{
|
|
||||||
NotifyCommandReady();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("CommandExecutor_CommandExecuted: end.");
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+105
-78
@@ -1,37 +1,38 @@
|
|||||||
using System;
|
using System;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
public class MtExpert
|
public class MtExpert: ITaskExecutor
|
||||||
{
|
{
|
||||||
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
|
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
|
||||||
|
public delegate void MtEventHandler(MtExpert expert, MtEvent e);
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert));
|
||||||
|
|
||||||
private readonly IMetaTraderHandler _mtHadler;
|
private readonly IMetaTraderHandler _mtHadler;
|
||||||
private MtCommandTask _commandTask;
|
private MtCommandTask _currentTask;
|
||||||
private ICommandManager _commandManager;
|
private readonly Queue<MtCommandTask> _taskQueue = new Queue<MtCommandTask>();
|
||||||
private readonly object _locker = new object();
|
private readonly object _locker = new object();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#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)
|
if (mtHandler == null)
|
||||||
throw new ArgumentNullException(nameof(mtHandler));
|
throw new ArgumentNullException(nameof(mtHandler));
|
||||||
|
|
||||||
Quote = quote;
|
_quote = new MtQuote { ExpertHandle = handle, Instrument = symbol, Bid = bid, Ask = ask};
|
||||||
Handle = handle;
|
Handle = handle;
|
||||||
_mtHadler = mtHandler;
|
_mtHadler = mtHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deinit()
|
public virtual void Deinit()
|
||||||
{
|
{
|
||||||
Log.Debug("Deinit: begin.");
|
Log.Debug("Deinit: begin.");
|
||||||
|
|
||||||
IsEnable = false;
|
|
||||||
FireOnDeinited();
|
FireOnDeinited();
|
||||||
|
|
||||||
Log.Debug("Deinit: end.");
|
Log.Debug("Deinit: end.");
|
||||||
@@ -41,9 +42,8 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Log.DebugFormat("SendResponse: begin. response = {0}", response);
|
Log.DebugFormat("SendResponse: begin. response = {0}", response);
|
||||||
|
|
||||||
_commandTask.SetResult(response);
|
_currentTask.SetResult(response);
|
||||||
_commandTask = null;
|
_currentTask = null;
|
||||||
FireOnCommandExecuted();
|
|
||||||
|
|
||||||
Log.Debug("SendResponse: end.");
|
Log.Debug("SendResponse: end.");
|
||||||
}
|
}
|
||||||
@@ -52,20 +52,16 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Log.Debug("GetCommandType: called.");
|
Log.Debug("GetCommandType: called.");
|
||||||
|
|
||||||
var commandManager = CommandManager;
|
_currentTask = DequeueTask();
|
||||||
if (commandManager != null)
|
|
||||||
{
|
|
||||||
_commandTask = commandManager.DequeueCommandTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _commandTask?.Command?.CommandType ?? 0;
|
return _currentTask?.Command?.CommandType ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetCommandParameter(int index)
|
public object GetCommandParameter(int index)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("GetCommandType: called. index = {0}", index);
|
Log.DebugFormat("GetCommandParameter: called. index = {0}", index);
|
||||||
|
|
||||||
var command = _commandTask?.Command;
|
var command = _currentTask?.Command;
|
||||||
if (command?.Parameters != null && index >= 0 && index < command.Parameters.Count)
|
if (command?.Parameters != null && index >= 0 && index < command.Parameters.Count)
|
||||||
{
|
{
|
||||||
return command.Parameters[index];
|
return command.Parameters[index];
|
||||||
@@ -74,6 +70,46 @@ namespace MTApiService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object GetNamedParameter(string name)
|
||||||
|
{
|
||||||
|
Log.DebugFormat("GetNamedParameter: called. name = {0}", name);
|
||||||
|
|
||||||
|
var command = _currentTask?.Command;
|
||||||
|
if (command == null)
|
||||||
|
{
|
||||||
|
Log.Warn("GetNamedParameter: command is not defined in task.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.NamedParams == null)
|
||||||
|
{
|
||||||
|
Log.Warn("GetNamedParameter: NamedParams is not defined in command.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return command.NamedParams[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsNamedParameter(string name)
|
||||||
|
{
|
||||||
|
Log.DebugFormat("ContainsNamedParameter: called. name = {0}", name);
|
||||||
|
|
||||||
|
var command = _currentTask?.Command;
|
||||||
|
if (command == null)
|
||||||
|
{
|
||||||
|
Log.Warn("ContainsNamedParameter: command is not defined in task.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.NamedParams == null)
|
||||||
|
{
|
||||||
|
Log.Warn("ContainsNamedParameter: NamedParams is not defined in command.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return command.NamedParams.ContainsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
public void SendEvent(MtEvent mtEvent)
|
public void SendEvent(MtEvent mtEvent)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendEvent: begin. event = {0}", mtEvent);
|
Log.DebugFormat("SendEvent: begin. event = {0}", mtEvent);
|
||||||
@@ -83,14 +119,38 @@ namespace MTApiService
|
|||||||
Log.Debug("SendEvent: end.");
|
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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"ExpertHandle = {Handle}";
|
return $"ExpertHandle = {Handle}, Quote = {Quote}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ITaskExecutor
|
||||||
|
|
||||||
|
public void Execute(MtCommandTask task)
|
||||||
|
{
|
||||||
|
lock (_taskQueue)
|
||||||
|
{
|
||||||
|
_taskQueue.Enqueue(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyCommandReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
private MtQuote _quote;
|
private MtQuote _quote;
|
||||||
public MtQuote Quote
|
public MtQuote Quote
|
||||||
{
|
{
|
||||||
@@ -101,7 +161,7 @@ namespace MTApiService
|
|||||||
return _quote;
|
return _quote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set
|
private set
|
||||||
{
|
{
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
@@ -113,61 +173,34 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int Handle { get; }
|
public int Handle { get; }
|
||||||
|
|
||||||
private bool _isEnable = true;
|
|
||||||
public bool IsEnable
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
return _isEnable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
_isEnable = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICommandManager CommandManager
|
|
||||||
{
|
|
||||||
private get
|
|
||||||
{
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
return _commandManager;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
_commandManager = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IMtCommandExecutor
|
|
||||||
public void NotifyCommandReady()
|
|
||||||
{
|
|
||||||
Log.Debug("NotifyCommandReady: begin.");
|
|
||||||
|
|
||||||
SendTickToMetaTrader();
|
|
||||||
|
|
||||||
Log.Debug("NotifyCommandReady: end.");
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void SendTickToMetaTrader()
|
private MtCommandTask DequeueTask()
|
||||||
{
|
{
|
||||||
|
Log.Debug("DequeueTask: called.");
|
||||||
|
|
||||||
|
MtCommandTask task;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
lock (_locker)
|
||||||
|
{
|
||||||
|
count = _taskQueue.Count;
|
||||||
|
task = _taskQueue.Count > 0 ? _taskQueue.Dequeue() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.DebugFormat("DequeueTask: end. left task count = {0}.", count);
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NotifyCommandReady()
|
||||||
|
{
|
||||||
|
Log.Debug("NotifyCommandReady: begin.");
|
||||||
|
|
||||||
_mtHadler.SendTickToMetaTrader(Handle);
|
_mtHadler.SendTickToMetaTrader(Handle);
|
||||||
|
|
||||||
|
Log.Debug("NotifyCommandReady: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FireOnQuoteChanged(MtQuote quote)
|
private void FireOnQuoteChanged(MtQuote quote)
|
||||||
@@ -180,22 +213,16 @@ namespace MTApiService
|
|||||||
Deinited?.Invoke(this, EventArgs.Empty);
|
Deinited?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FireOnCommandExecuted()
|
|
||||||
{
|
|
||||||
CommandExecuted?.Invoke(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FireOnMtEvent(MtEvent mtEvent)
|
private void FireOnMtEvent(MtEvent mtEvent)
|
||||||
{
|
{
|
||||||
OnMtEvent?.Invoke(this, new MtEventArgs(mtEvent));
|
OnMtEvent?.Invoke(this, mtEvent);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
public event EventHandler Deinited;
|
public event EventHandler Deinited;
|
||||||
public event MtQuoteHandler QuoteChanged;
|
public event MtQuoteHandler QuoteChanged;
|
||||||
public event EventHandler CommandExecuted;
|
public event MtEventHandler OnMtEvent;
|
||||||
public event EventHandler<MtEventArgs> OnMtEvent;
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace MTApiService
|
|
||||||
{
|
|
||||||
[DataContract]
|
|
||||||
public class MtQuote
|
|
||||||
{
|
|
||||||
[DataMember]
|
|
||||||
public string Instrument { get; private set; }
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public double Bid { get; private set; }
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public double Ask { get; private set; }
|
|
||||||
|
|
||||||
public MtQuote(string instrument, double bid, double ask)
|
|
||||||
{
|
|
||||||
Instrument = instrument;
|
|
||||||
Bid = bid;
|
|
||||||
Ask = ask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return "Instrument = " + Instrument + ", Bid = " + Bid + ", Ask = " + Ask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,9 +9,9 @@ namespace MTApiService
|
|||||||
[DataMember]
|
[DataMember]
|
||||||
public int Action { get; set; }
|
public int Action { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public uint Magic { get; set; }
|
public ulong Magic { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public uint Order { get; set; }
|
public ulong Order { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Symbol { get; set; }
|
public string Symbol { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
@@ -25,7 +25,7 @@ namespace MTApiService
|
|||||||
[DataMember]
|
[DataMember]
|
||||||
public double Tp { get; set; }
|
public double Tp { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public uint Deviation { get; set; }
|
public ulong Deviation { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int Type { get; set; }
|
public int Type { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
@@ -36,5 +36,9 @@ namespace MTApiService
|
|||||||
public DateTime Expiration { get; set; }
|
public DateTime Expiration { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Comment { get; set; }
|
public string Comment { get; set; }
|
||||||
|
[DataMember]
|
||||||
|
public ulong Position { get; set; }
|
||||||
|
[DataMember]
|
||||||
|
public ulong PositionBy { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace MTApiService
|
||||||
|
{
|
||||||
|
[DataContract]
|
||||||
|
public class MtQuote
|
||||||
|
{
|
||||||
|
[DataMember]
|
||||||
|
public string Instrument { get; internal set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public double Bid { get; internal set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public double Ask { get; internal set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public int ExpertHandle { get; internal set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Instrument = {Instrument}; Bid = {Bid}; Ask = {Ask}; ExpertHandle = {ExpertHandle}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,8 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
static IEnumerable<Type> GetKnownTypes()
|
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(MtResponseString), typeof(MtResponseBool),
|
||||||
typeof(MtResponseLong), typeof(MtResponseULong),
|
typeof(MtResponseLong), typeof(MtResponseULong),
|
||||||
typeof(MtResponseDoubleArray), typeof(MtResponseIntArray),
|
typeof(MtResponseDoubleArray), typeof(MtResponseIntArray),
|
||||||
@@ -22,6 +23,28 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract object GetValue();
|
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]
|
[DataContract]
|
||||||
|
|||||||
+29
-17
@@ -21,7 +21,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
private readonly MtService _service;
|
private readonly MtService _service;
|
||||||
private readonly List<ServiceHost> _hosts = new List<ServiceHost>();
|
private readonly List<ServiceHost> _hosts = new List<ServiceHost>();
|
||||||
private readonly MtCommandExecutorManager _executorManager = new MtCommandExecutorManager();
|
private readonly MtExecutorManager _executorManager = new MtExecutorManager();
|
||||||
private readonly List<MtExpert> _experts = new List<MtExpert>();
|
private readonly List<MtExpert> _experts = new List<MtExpert>();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -62,21 +62,24 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
|
|
||||||
//init local pipe host
|
//init local pipe host
|
||||||
var localUrl = CreateConnectionAddress(null, port, true);
|
var localPipeUrl = CreateConnectionAddress(null, port, true);
|
||||||
var localServiceHost = CreateServiceHost(localUrl, true);
|
var localPipeServiceHost = CreateServiceHost(localPipeUrl, true);
|
||||||
|
if (localPipeServiceHost != null)
|
||||||
|
{
|
||||||
|
_hosts.Add(localPipeServiceHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
//init localhost
|
||||||
|
var localUrl = CreateConnectionAddress("localhost", port, false);
|
||||||
|
var localServiceHost = CreateServiceHost(localUrl, false);
|
||||||
if (localServiceHost != null)
|
if (localServiceHost != null)
|
||||||
{
|
{
|
||||||
_hosts.Add(localServiceHost);
|
_hosts.Add(localServiceHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
//init network hosts
|
//init network hosts
|
||||||
var dnsHostName = Dns.GetHostName();
|
var dnsHostName = Dns.GetHostName();
|
||||||
var ips = Dns.GetHostEntry(dnsHostName);
|
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)
|
foreach (var ipAddress in ips.AddressList)
|
||||||
{
|
{
|
||||||
@@ -149,7 +152,7 @@ namespace MTApiService
|
|||||||
_experts.Add(expert);
|
_experts.Add(expert);
|
||||||
}
|
}
|
||||||
|
|
||||||
_executorManager.AddCommandExecutor(expert);
|
_executorManager.AddExecutor(expert);
|
||||||
|
|
||||||
_service.OnQuoteAdded(expert.Quote);
|
_service.OnQuoteAdded(expert.Quote);
|
||||||
|
|
||||||
@@ -170,11 +173,20 @@ namespace MTApiService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var task = new MtCommandTask(command);
|
var task = _executorManager.SendCommand(command);
|
||||||
_executorManager.EnqueueCommandTask(task);
|
|
||||||
|
|
||||||
//wait for execute command in MetaTrader
|
//wait for execute command in MetaTrader
|
||||||
var response = task.WaitResult(WaitResponseTime);
|
MtResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = task.WaitResult(WaitResponseTime);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.WarnFormat("SendCommand: Exception - {0}", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.DebugFormat("SendCommand: end. response = {0}", response);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -371,7 +383,7 @@ namespace MTApiService
|
|||||||
expertsCount = _experts.Count;
|
expertsCount = _experts.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
_executorManager.RemoveCommandExecutor(expert);
|
_executorManager.RemoveExecutor(expert);
|
||||||
|
|
||||||
expert.Deinited -= expert_Deinited;
|
expert.Deinited -= expert_Deinited;
|
||||||
expert.QuoteChanged -= expert_QuoteChanged;
|
expert.QuoteChanged -= expert_QuoteChanged;
|
||||||
@@ -398,11 +410,11 @@ namespace MTApiService
|
|||||||
Log.Debug("expert_QuoteChanged: end.");
|
Log.Debug("expert_QuoteChanged: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Expert_OnMtEvent(object sender, MtEventArgs e)
|
private void Expert_OnMtEvent(MtExpert expert, MtEvent e)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Expert_OnMtEvent: begin. event = {0}", e.Event);
|
Log.DebugFormat("Expert_OnMtEvent: begin. expert = {0}, event = {1}", expert, e);
|
||||||
|
|
||||||
_service.OnMtEvent(e.Event);
|
_service.OnMtEvent(e);
|
||||||
|
|
||||||
Log.Debug("Expert_OnMtEvent: end.");
|
Log.Debug("Expert_OnMtEvent: end.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
if (callback == null)
|
if (callback == null)
|
||||||
{
|
{
|
||||||
Log.Warn("Connect: end. Callback is not definded.");
|
Log.Warn("Connect: end. Callback is not defined.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
public void QuoteUpdate(MtQuote quote)
|
public void QuoteUpdate(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.Debug("QuoteUpdate: begin.");
|
Log.DebugFormat("QuoteUpdate: begin. quote = {0}", quote);
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnQuoteUpdate(quote));
|
ExecuteCallbackAction(a => a.OnQuoteUpdate(quote));
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
public void OnQuoteAdded(MtQuote quote)
|
public void OnQuoteAdded(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.Debug("OnQuoteAdded: begin.");
|
Log.DebugFormat("OnQuoteAdded: begin. quote = {0}", quote);
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnQuoteAdded(quote));
|
ExecuteCallbackAction(a => a.OnQuoteAdded(quote));
|
||||||
|
|
||||||
@@ -176,18 +176,18 @@ namespace MTApiService
|
|||||||
|
|
||||||
public void OnQuoteRemoved(MtQuote quote)
|
public void OnQuoteRemoved(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.Debug("OnQuoteRemoved: begin.");
|
Log.DebugFormat("OnQuoteRemoved: begin. quote = {0}", quote);
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnQuoteRemoved(quote));
|
ExecuteCallbackAction(a => a.OnQuoteRemoved(quote));
|
||||||
|
|
||||||
Log.Debug("OnQuoteRemoved: end.");
|
Log.Debug("OnQuoteRemoved: end.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMtEvent(MtEvent mtEvent)
|
public void OnMtEvent(MtEvent e)
|
||||||
{
|
{
|
||||||
Log.Debug("OnMtEvent: begin.");
|
Log.DebugFormat("OnMtEvent: begin.quote = {0}", e);
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnMtEvent(mtEvent));
|
ExecuteCallbackAction(a => a.OnMtEvent(e));
|
||||||
|
|
||||||
Log.Debug("OnMtEvent: end.");
|
Log.Debug("OnMtEvent: end.");
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+2
-2
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.23.0")]
|
[assembly: AssemblyVersion("1.0.29.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.23.0")]
|
[assembly: AssemblyFileVersion("1.0.29.0")]
|
||||||
+175
-196
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
#include "MT4Handler.h"
|
#include "MT4Handler.h"
|
||||||
#include "Windows.h"
|
#include "Windows.h"
|
||||||
#include < vcclr.h >
|
#include <vcclr.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
using namespace System;
|
using namespace System;
|
||||||
using namespace MTApiService;
|
using namespace MTApiService;
|
||||||
@@ -17,6 +18,8 @@ using namespace System::IO;
|
|||||||
using namespace System::Collections::Generic;
|
using namespace System::Collections::Generic;
|
||||||
using namespace System::Diagnostics;
|
using namespace System::Diagnostics;
|
||||||
|
|
||||||
|
#define _DLLAPI extern "C" __declspec(dllexport)
|
||||||
|
|
||||||
void convertSystemString(wchar_t* dest, String^ src)
|
void convertSystemString(wchar_t* dest, String^ src)
|
||||||
{
|
{
|
||||||
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
|
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
|
||||||
@@ -24,264 +27,240 @@ void convertSystemString(wchar_t* dest, String^ src)
|
|||||||
dest[wcslen(wch)] = '\0';
|
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
|
try
|
||||||
{
|
{
|
||||||
MT4Handler^ mtHandler = gcnew MT4Handler();
|
result = func();
|
||||||
|
|
||||||
MtServerInstance::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHandler);
|
|
||||||
}
|
}
|
||||||
catch (Exception^ e)
|
catch (Exception^ e)
|
||||||
{
|
{
|
||||||
convertSystemString(err, e->Message);
|
convertSystemString(err, e->Message);
|
||||||
Debug::WriteLine("[ERROR] MTConnector:initExpert(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall deinitExpert(int expertHandle, wchar_t* err)
|
_DLLAPI bool _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &port, symbol, &bid, &ask]() {
|
||||||
{
|
auto expert = gcnew MtExpert(expertHandle, gcnew String(symbol), bid, ask, gcnew MT4Handler());
|
||||||
MtServerInstance::GetInstance()->DeinitExpert(expertHandle);
|
MtAdapter::GetInstance()->AddExpert(port, expert);
|
||||||
}
|
return true;
|
||||||
catch (Exception^ e)
|
}, err, false);
|
||||||
{
|
|
||||||
convertSystemString(err, e->Message);
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:deinitExpert(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
_DLLAPI bool _stdcall deinitExpert(int expertHandle, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle]() {
|
||||||
{
|
MtAdapter::GetInstance()->RemoveExpert(expertHandle);
|
||||||
MtServerInstance::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
}
|
||||||
{
|
|
||||||
convertSystemString(err, e->Message);
|
_DLLAPI bool _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||||
Debug::WriteLine("[ERROR] MTConnector:updateQuote(): " + e->Message);
|
{
|
||||||
return 0;
|
return Execute<bool>([&expertHandle, symbol, &bid, &ask]() {
|
||||||
}
|
MtAdapter::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
|
||||||
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]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendEvent(expertHandle, eventType, gcnew String(payload));
|
||||||
MtServerInstance::GetInstance()->SendEvent(expertHandle, eventType, gcnew String(payload));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
convertSystemString(err, e->Message);
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:updateTimeBar(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendIntResponse(int expertHandle, int response)
|
_DLLAPI bool _stdcall sendIntResponse(int expertHandle, int response, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &response]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendIntResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendBooleanResponse(int expertHandle, int response)
|
_DLLAPI bool _stdcall sendBooleanResponse(int expertHandle, bool response, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &response]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(response));
|
||||||
bool value = (response != 0) ? true : false;
|
return true;
|
||||||
|
}, err, false);
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
|
|
||||||
}
|
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendBooleanResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendDoubleResponse(int expertHandle, double response)
|
_DLLAPI bool _stdcall sendDoubleResponse(int expertHandle, double response, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &response]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendDoubleResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendStringResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendVoidResponse(int expertHandle)
|
_DLLAPI bool _stdcall sendErrorResponse(int expertHandle, int code, wchar_t* message, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &code, message]() {
|
||||||
{
|
MtResponseString^ res = gcnew MtResponseString(gcnew String(message));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, nullptr);
|
res->ErrorCode = code;
|
||||||
}
|
MtAdapter::GetInstance()->SendResponse(expertHandle, res);
|
||||||
catch (Exception^ e)
|
return true;
|
||||||
{
|
}, err, false);
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendVoidResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size)
|
_DLLAPI bool _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle]() {
|
||||||
{
|
MtAdapter::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);
|
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];
|
list[i] = values[i];
|
||||||
}
|
}
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendDoubleArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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];
|
list[i] = values[i];
|
||||||
}
|
}
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendIntArrayResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall sendLongResponse(int expertHandle, __int64 response)
|
_DLLAPI bool _stdcall sendLongResponse(int expertHandle, __int64 response, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, &response]() {
|
||||||
{
|
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
|
||||||
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:sendLongResponse(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = MtAdapter::GetInstance()->GetCommandType(expertHandle);
|
||||||
*res = MtServerInstance::GetInstance()->GetCommandType(expertHandle);
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:getCommandType(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
*res = (int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:getIntValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res)
|
// --- index parameters
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, ¶mIndex, res]() {
|
||||||
{
|
*res = (double)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
*res = (double)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:getDoubleValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, ¶mIndex, res]() {
|
||||||
{
|
convertSystemString(res, (String^)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
|
||||||
convertSystemString(res, (String^)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
|
return true;
|
||||||
}
|
}, err, false);
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
|
||||||
Debug::WriteLine("[ERROR] MTConnector:getStringValue(): " + e->Message);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
|
_DLLAPI bool _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
|
||||||
{
|
{
|
||||||
try
|
return Execute<bool>([&expertHandle, ¶mIndex, res]() {
|
||||||
{
|
*res = (bool)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
return true;
|
||||||
*res = val == true ? 1 : 0;
|
}, err, false);
|
||||||
}
|
}
|
||||||
catch (Exception^ e)
|
|
||||||
{
|
_DLLAPI bool _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res, wchar_t* err)
|
||||||
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
|
{
|
||||||
return 0;
|
return Execute<bool>([&expertHandle, ¶mIndex, res]() {
|
||||||
}
|
*res = (__int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
return 1;
|
return true;
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- named parameters
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall containsNamedValue(int expertHandle, wchar_t* paramName)
|
||||||
|
{
|
||||||
|
wchar_t err[1000];
|
||||||
|
return Execute<bool>([&expertHandle, paramName]() {
|
||||||
|
return MtAdapter::GetInstance()->ContainsNamedParameter(expertHandle, gcnew String(paramName));
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall getNamedIntValue(int expertHandle, wchar_t* paramName, int* res, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<bool>([&expertHandle, paramName, res]() {
|
||||||
|
System::Object^ obj = MtAdapter::GetInstance()->GetNamedParameter(expertHandle, gcnew String(paramName));
|
||||||
|
*res = (int)obj;
|
||||||
|
return true;
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall getNamedDoubleValue(int expertHandle, wchar_t* paramName, double* res, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<bool>([&expertHandle, paramName, res]() {
|
||||||
|
System::Object^ obj = MtAdapter::GetInstance()->GetNamedParameter(expertHandle, gcnew String(paramName));
|
||||||
|
*res = (double)obj;
|
||||||
|
return true;
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall getNamedStringValue(int expertHandle, wchar_t* paramName, wchar_t* res, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<bool>([&expertHandle, paramName, res]() {
|
||||||
|
System::Object^ obj = MtAdapter::GetInstance()->GetNamedParameter(expertHandle, gcnew String(paramName));
|
||||||
|
convertSystemString(res, (String^)obj);
|
||||||
|
return true;
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall getNamedBooleanValue(int expertHandle, wchar_t* paramName, int* res, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<bool>([&expertHandle, paramName, res]() {
|
||||||
|
System::Object^ obj = MtAdapter::GetInstance()->GetNamedParameter(expertHandle, gcnew String(paramName));
|
||||||
|
*res = (bool)obj;
|
||||||
|
return true;
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall getNamedLongValue(int expertHandle, wchar_t* paramName, __int64* res, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<bool>([&expertHandle, paramName, res]() {
|
||||||
|
System::Object^ obj = MtAdapter::GetInstance()->GetNamedParameter(expertHandle, gcnew String(paramName));
|
||||||
|
if (obj != nullptr)
|
||||||
|
*res = (__int64)obj;
|
||||||
|
return true;
|
||||||
|
}, err, false);
|
||||||
}
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
LIBRARY MTConnector
|
|
||||||
|
|
||||||
EXPORTS initExpert
|
|
||||||
deinitExpert
|
|
||||||
updateQuote
|
|
||||||
sendEvent
|
|
||||||
sendIntResponse
|
|
||||||
sendBooleanResponse
|
|
||||||
sendDoubleResponse
|
|
||||||
sendStringResponse
|
|
||||||
sendVoidResponse
|
|
||||||
sendDoubleArrayResponse
|
|
||||||
sendIntArrayResponse
|
|
||||||
sendLongResponse
|
|
||||||
getCommandType
|
|
||||||
getIntValue
|
|
||||||
getDoubleValue
|
|
||||||
getStringValue
|
|
||||||
getBooleanValue
|
|
||||||
@@ -96,7 +96,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -109,7 +108,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -121,7 +119,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -133,7 +130,6 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<ModuleDefinitionFile>.\MTConnector.def</ModuleDefinitionFile>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -154,7 +150,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.ico" />
|
<None Include="app.ico" />
|
||||||
<None Include="MTConnector.def" />
|
|
||||||
<None Include="ReadMe.txt" />
|
<None Include="ReadMe.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -44,9 +44,6 @@
|
|||||||
<None Include="app.ico">
|
<None Include="app.ico">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="MTConnector.def">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="app.rc">
|
<ResourceCompile Include="app.rc">
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumAlignMode
|
||||||
|
{
|
||||||
|
ALIGN_LEFT = 1,
|
||||||
|
ALIGN_CENTER = 2,
|
||||||
|
ALIGN_RIGHT = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumChartPropertyDouble
|
||||||
|
{
|
||||||
|
CHART_SHIFT_SIZE = 3,
|
||||||
|
CHART_FIXED_POSITION = 41,
|
||||||
|
CHART_FIXED_MAX = 8,
|
||||||
|
CHART_FIXED_MIN = 9,
|
||||||
|
CHART_POINTS_PER_BAR = 11,
|
||||||
|
CHART_PRICE_MIN = 108,
|
||||||
|
CHART_PRICE_MAX = 109
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumChartPropertyInteger
|
||||||
|
{
|
||||||
|
CHART_BRING_TO_TOP = 35,
|
||||||
|
CHART_MOUSE_SCROLL = 42,
|
||||||
|
CHART_EVENT_MOUSE_MOVE = 40,
|
||||||
|
CHART_EVENT_OBJECT_CREATE = 38,
|
||||||
|
CHART_EVENT_OBJECT_DELETE = 39,
|
||||||
|
CHART_MODE = 0,
|
||||||
|
CHART_FOREGROUND = 1,
|
||||||
|
CHART_SHIFT = 2,
|
||||||
|
CHART_AUTOSCROLL = 4,
|
||||||
|
CHART_QUICK_NAVIGATION = 45,
|
||||||
|
CHART_SCALE = 5,
|
||||||
|
CHART_SCALEFIX = 6,
|
||||||
|
CHART_SCALEFIX_11 = 7,
|
||||||
|
CHART_SCALE_PT_PER_BAR = 10,
|
||||||
|
CHART_SHOW_OHLC = 12,
|
||||||
|
CHART_SHOW_BID_LINE = 13,
|
||||||
|
CHART_SHOW_ASK_LINE = 14,
|
||||||
|
CHART_SHOW_LAST_LINE = 15,
|
||||||
|
CHART_SHOW_PERIOD_SEP = 16,
|
||||||
|
CHART_SHOW_GRID = 17,
|
||||||
|
CHART_SHOW_VOLUMES = 18,
|
||||||
|
CHART_SHOW_OBJECT_DESCR = 19,
|
||||||
|
CHART_VISIBLE_BARS = 100,
|
||||||
|
CHART_WINDOWS_TOTAL = 101,
|
||||||
|
CHART_WINDOW_IS_VISIBLE = 102,
|
||||||
|
CHART_WINDOW_HANDLE = 103,
|
||||||
|
CHART_WINDOW_YDISTANCE = 110,
|
||||||
|
CHART_FIRST_VISIBLE_BAR = 104,
|
||||||
|
CHART_WIDTH_IN_BARS = 105,
|
||||||
|
CHART_WIDTH_IN_PIXELS = 106,
|
||||||
|
CHART_HEIGHT_IN_PIXELS = 107,
|
||||||
|
CHART_COLOR_BACKGROUND = 21,
|
||||||
|
CHART_COLOR_FOREGROUND = 22,
|
||||||
|
CHART_COLOR_GRID = 23,
|
||||||
|
CHART_COLOR_VOLUME = 24,
|
||||||
|
CHART_COLOR_CHART_UP = 25,
|
||||||
|
CHART_COLOR_CHART_DOWN = 26,
|
||||||
|
CHART_COLOR_CHART_LINE = 27,
|
||||||
|
CHART_COLOR_CANDLE_BULL = 28,
|
||||||
|
CHART_COLOR_CANDLE_BEAR = 29,
|
||||||
|
CHART_COLOR_BID = 30,
|
||||||
|
CHART_COLOR_ASK = 31,
|
||||||
|
CHART_COLOR_LAST = 32,
|
||||||
|
CHART_COLOR_STOP_LEVEL = 33,
|
||||||
|
CHART_SHOW_TRADE_LEVELS = 34,
|
||||||
|
CHART_DRAG_TRADE_LEVELS = 43,
|
||||||
|
CHART_SHOW_DATE_SCALE = 36,
|
||||||
|
CHART_SHOW_PRICE_SCALE = 37,
|
||||||
|
CHART_IS_OFFLINE = 112
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumChartPropertyString
|
||||||
|
{
|
||||||
|
CHART_COMMENT = 20
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
enum EnumColorFormat
|
||||||
|
{
|
||||||
|
COLOR_FORMAT_XRGB_NOALPHA = 0, //The component of the alpha channel is ignored
|
||||||
|
COLOR_FORMAT_ARGB_RAW = 1, //Color components are not handled by the terminal (must be correctly set by the user)
|
||||||
|
COLOR_FORMAT_ARGB_NORMALIZE = 2 //Color components are handled by the terminal
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumObject
|
||||||
|
{
|
||||||
|
OBJ_VLINE = 0, //Vertical Line
|
||||||
|
OBJ_HLINE = 1, //Horizontal Line
|
||||||
|
OBJ_TREND = 2, //Trend Line
|
||||||
|
BJ_TRENDBYANGLE = 3, //Trend Line By Angle
|
||||||
|
OBJ_CYCLES = 20, //Cycle Lines
|
||||||
|
OBJ_CHANNEL = 5, //Equidistant Channel
|
||||||
|
OBJ_STDDEVCHANNEL = 6, //Standard Deviation Channel
|
||||||
|
OBJ_REGRESSION = 4, //Linear Regression Channel
|
||||||
|
OBJ_PITCHFORK = 19, //Andrews Pitchfork
|
||||||
|
OBJ_GANNLINE = 7, //Gann Line
|
||||||
|
OBJ_GANNFAN = 8, //Gann Fan
|
||||||
|
OBJ_GANNGRID = 9, //Gann Grid
|
||||||
|
OBJ_FIBO = 10, //Fibonacci Retracement
|
||||||
|
OBJ_FIBOTIMES = 11, //Fibonacci Time Zones
|
||||||
|
OBJ_FIBOFAN = 12, //Fibonacci Fan
|
||||||
|
OBJ_FIBOARC = 13, //Fibonacci Arcs
|
||||||
|
OBJ_FIBOCHANNEL = 15, //Fibonacci Channel
|
||||||
|
OBJ_EXPANSION = 14, //Fibonacci Expansion
|
||||||
|
OBJ_RECTANGLE = 16, //Rectangle
|
||||||
|
OBJ_TRIANGLE = 17, //Triangle
|
||||||
|
OBJ_ELLIPSE = 18, //Ellipse
|
||||||
|
OBJ_ARROW_THUMB_UP = 29, //Thumbs Up
|
||||||
|
OBJ_ARROW_THUMB_DOWN = 30, //Thumbs Down
|
||||||
|
OBJ_ARROW_UP = 31, //Arrow Up
|
||||||
|
OBJ_ARROW_DOWN = 32, //Arrow Down
|
||||||
|
OBJ_ARROW_STOP = 33, //Stop Sign
|
||||||
|
OBJ_ARROW_CHECK = 34, //Check Sign
|
||||||
|
OBJ_ARROW_LEFT_PRICE = 35, //Left Price Label
|
||||||
|
OBJ_ARROW_RIGHT_PRICE = 36, //Right Price Label
|
||||||
|
OBJ_ARROW_BUY = 37, //Buy Sign
|
||||||
|
OBJ_ARROW_SELL = 38, //Sell Sign
|
||||||
|
OBJ_ARROW = 22, //Arrow
|
||||||
|
OBJ_TEXT = 21, //Text
|
||||||
|
OBJ_LABEL = 23, //Label
|
||||||
|
OBJ_BUTTON = 25, //Button
|
||||||
|
OBJ_BITMAP = 26, //Bitmap
|
||||||
|
OBJ_BITMAP_LABEL = 24, //Bitmap Label
|
||||||
|
OBJ_EDIT = 27, //Edit
|
||||||
|
OBJ_EVENT = 42, //The "Event" object corresponding to an event in the economic calendar
|
||||||
|
OBJ_RECTANGLE_LABEL = 28 //The "Rectangle label" object for creating and designing the custom graphical interface.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumObjectPropertyDouble
|
||||||
|
{
|
||||||
|
OBJPROP_PRICE = 20, // Price coordinate
|
||||||
|
OBJPROP_LEVELVALUE = 204, // Level value
|
||||||
|
OBJPROP_SCALE = 12, // Scale (properties of Gann objects, Fibonacci Arcs and Ellipse)
|
||||||
|
OBJPROP_ANGLE = 13, // Angle. For the objects with no angle specified, created from a program, the value is equal to EMPTY_VALUE
|
||||||
|
OBJPROP_DEVIATION = 16, // Deviation for the Standard Deviation Channel
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumObjectPropertyInteger
|
||||||
|
{
|
||||||
|
OBJPROP_COLOR = 6,
|
||||||
|
OBJPROP_STYLE = 7,
|
||||||
|
OBJPROP_WIDTH = 8,
|
||||||
|
OBJPROP_BACK = 9,
|
||||||
|
OBJPROP_ZORDER = 207,
|
||||||
|
OBJPROP_HIDDEN = 208,
|
||||||
|
OBJPROP_SELECTED = 17,
|
||||||
|
OBJPROP_READONLY = 1028,
|
||||||
|
OBJPROP_TYPE = 18,
|
||||||
|
OBJPROP_TIME = 19,
|
||||||
|
OBJPROP_SELECTABLE = 1000,
|
||||||
|
OBJPROP_CREATETIME = 998,
|
||||||
|
OBJPROP_LEVELS = 200,
|
||||||
|
OBJPROP_LEVELCOLOR = 201,
|
||||||
|
OBJPROP_LEVELSTYLE = 202,
|
||||||
|
OBJPROP_LEVELWIDTH = 203,
|
||||||
|
OBJPROP_ALIGN = 1036,
|
||||||
|
OBJPROP_FONTSIZE = 100,
|
||||||
|
OBJPROP_RAY_RIGHT = 1004,
|
||||||
|
OBJPROP_ELLIPSE = 11,
|
||||||
|
OBJPROP_ARROWCODE = 14,
|
||||||
|
OBJPROP_TIMEFRAMES = 15,
|
||||||
|
OBJPROP_ANCHOR = 1011,
|
||||||
|
OBJPROP_XDISTANCE = 102,
|
||||||
|
OBJPROP_YDISTANCE = 103,
|
||||||
|
OBJPROP_STATE = 1018,
|
||||||
|
OBJPROP_XSIZE = 1019,
|
||||||
|
OBJPROP_YSIZE = 1020,
|
||||||
|
OBJPROP_XOFFSET = 1033,
|
||||||
|
OBJPROP_YOFFSET = 1034,
|
||||||
|
OBJPROP_BGCOLOR = 1025,
|
||||||
|
OBJPROP_CORNER = 101,
|
||||||
|
OBJPROP_BORDER_TYPE = 1029,
|
||||||
|
OBJPROP_BORDER_COLOR = 1035
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumObjectPropertyString
|
||||||
|
{
|
||||||
|
OBJPROP_NAME = 1037,
|
||||||
|
OBJPROP_TEXT = 999,
|
||||||
|
OBJPROP_TOOLTIP = 206,
|
||||||
|
OBJPROP_LEVELTEXT = 205,
|
||||||
|
OBJPROP_FONT = 1001,
|
||||||
|
OBJPROP_BMPFILE = 1017,
|
||||||
|
OBJPROP_SYMBOL = 1021
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MtApi
|
|
||||||
{
|
|
||||||
static class ExtensionMethods
|
|
||||||
{
|
|
||||||
#region Event Methods
|
|
||||||
|
|
||||||
public static Task FireEventAsync(this MtApiQuoteHandler evenHandler, object sender, string symbol, double bid, double ask)
|
|
||||||
{
|
|
||||||
return Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
evenHandler?.Invoke(sender, symbol, bid, ask);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task FireEventAsync(this EventHandler eventHandler, object sender)
|
|
||||||
{
|
|
||||||
return Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
eventHandler?.Invoke(sender, EventArgs.Empty);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task FireEventAsync<T>(this EventHandler<T> eventHandler, object sender, T e)
|
|
||||||
where T : EventArgs
|
|
||||||
{
|
|
||||||
return Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
eventHandler?.Invoke(sender, e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public static MtQuote Convert(this MTApiService.MtQuote quote)
|
|
||||||
{
|
|
||||||
return (quote != null) ? new MtQuote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum FlagFontStyle
|
||||||
|
{
|
||||||
|
//Flags for specifying font style
|
||||||
|
FONT_ITALIC = -2147483648,
|
||||||
|
FONT_UNDERLINE = 1073741824,
|
||||||
|
FONT_STRIKEOUT = 536870912,
|
||||||
|
|
||||||
|
//Flags for specifying font width
|
||||||
|
FW_DONTCARE = 0,
|
||||||
|
FW_THIN = 1,
|
||||||
|
FW_EXTRALIGHT = 2,
|
||||||
|
FW_ULTRALIGHT = 3,
|
||||||
|
FW_LIGHT = 4,
|
||||||
|
FW_NORMAL = 5,
|
||||||
|
FW_REGULAR = 6,
|
||||||
|
FW_MEDIUM = 7,
|
||||||
|
FW_SEMIBOLD = 8,
|
||||||
|
FW_DEMIBOLD = 9,
|
||||||
|
FW_BOLD = 10,
|
||||||
|
FW_EXTRABOLD = 11,
|
||||||
|
FW_ULTRABOLD = 12,
|
||||||
|
FW_HEAVY = 13,
|
||||||
|
FW_BLACK = 14
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-1
@@ -58,16 +58,27 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ChartEventArgs.cs" />
|
||||||
<Compile Include="ChartPeriod.cs" />
|
<Compile Include="ChartPeriod.cs" />
|
||||||
|
<Compile Include="EnumAlignMode.cs" />
|
||||||
|
<Compile Include="EnumChartPropertyDouble.cs" />
|
||||||
|
<Compile Include="EnumChartPropertyInteger.cs" />
|
||||||
|
<Compile Include="EnumChartPropertyString.cs" />
|
||||||
|
<Compile Include="EnumColorFormat.cs" />
|
||||||
|
<Compile Include="EnumObject.cs" />
|
||||||
|
<Compile Include="EnumObjectPropertyDouble.cs" />
|
||||||
|
<Compile Include="EnumObjectPropertyInteger.cs" />
|
||||||
|
<Compile Include="EnumObjectPropertyString.cs" />
|
||||||
<Compile Include="EnumSeriesInfoInteger.cs" />
|
<Compile Include="EnumSeriesInfoInteger.cs" />
|
||||||
<Compile Include="EnumSymbolInfoDouble.cs" />
|
<Compile Include="EnumSymbolInfoDouble.cs" />
|
||||||
<Compile Include="EnumSymbolInfoInteger.cs" />
|
<Compile Include="EnumSymbolInfoInteger.cs" />
|
||||||
<Compile Include="EnumTerminalInfoDouble.cs" />
|
<Compile Include="EnumTerminalInfoDouble.cs" />
|
||||||
<Compile Include="EnumTerminalInfoInteger.cs" />
|
<Compile Include="EnumTerminalInfoInteger.cs" />
|
||||||
<Compile Include="ExtensionMethods.cs" />
|
<Compile Include="FlagFontStyle.cs" />
|
||||||
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
||||||
<Compile Include="MqlRates.cs" />
|
<Compile Include="MqlRates.cs" />
|
||||||
<Compile Include="MqlTick.cs" />
|
<Compile Include="MqlTick.cs" />
|
||||||
|
<Compile Include="MtChartEvent.cs" />
|
||||||
<Compile Include="MtConnectionEventArgs.cs" />
|
<Compile Include="MtConnectionEventArgs.cs" />
|
||||||
<Compile Include="MtConnectionException.cs" />
|
<Compile Include="MtConnectionException.cs" />
|
||||||
<Compile Include="MtConnectionState.cs" />
|
<Compile Include="MtConnectionState.cs" />
|
||||||
|
|||||||
+1320
-121
File diff suppressed because it is too large
Load Diff
@@ -13,9 +13,9 @@ namespace MtApi
|
|||||||
return Color.FromArgb((byte)(color), (byte)(color >> 8), (byte)(color >> 16));
|
return Color.FromArgb((byte)(color), (byte)(color >> 8), (byte)(color >> 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ConvertToMtColor(Color color)
|
public static int ConvertToMtColor(Color? color)
|
||||||
{
|
{
|
||||||
return color == Color.Empty ? 0xffffff : (Color.FromArgb(color.B, color.G, color.R).ToArgb() & 0xffffff);
|
return color == null || color == Color.Empty ? 0xffffff : (Color.FromArgb(color.Value.B, color.Value.G, color.Value.R).ToArgb() & 0xffffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ namespace MtApi
|
|||||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ConvertToMtTime(DateTime time)
|
public static int ConvertToMtTime(DateTime? time)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (time != DateTime.MinValue)
|
if (time != null && time != DateTime.MinValue)
|
||||||
{
|
{
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||||
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
result = (int)((time.Value.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable → Regular
+86
-9
@@ -1,9 +1,4 @@
|
|||||||
using System;
|
namespace MtApi
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi
|
|
||||||
{
|
{
|
||||||
enum MtCommandType
|
enum MtCommandType
|
||||||
{
|
{
|
||||||
@@ -116,6 +111,7 @@ namespace MtApi
|
|||||||
TimeSeconds = 86,
|
TimeSeconds = 86,
|
||||||
TimeYear = 87,
|
TimeYear = 87,
|
||||||
Year = 88,
|
Year = 88,
|
||||||
|
TimeGMT = 281,
|
||||||
|
|
||||||
//Global Variables
|
//Global Variables
|
||||||
GlobalVariableCheck = 89,
|
GlobalVariableCheck = 89,
|
||||||
@@ -140,8 +136,8 @@ namespace MtApi
|
|||||||
iBullsPower = 106,
|
iBullsPower = 106,
|
||||||
iCCI = 107,
|
iCCI = 107,
|
||||||
iCCIOnArray = 108,
|
iCCIOnArray = 108,
|
||||||
iCustom = 109,
|
//iCustom = 109,
|
||||||
iCustom_d = 10109,
|
//iCustom_d = 10109,
|
||||||
iDeMarker = 110,
|
iDeMarker = 110,
|
||||||
iEnvelopes = 111,
|
iEnvelopes = 111,
|
||||||
iEnvelopesOnArray = 112,
|
iEnvelopesOnArray = 112,
|
||||||
@@ -201,6 +197,87 @@ namespace MtApi
|
|||||||
SymbolsTotal = 200,
|
SymbolsTotal = 200,
|
||||||
SymbolName = 201,
|
SymbolName = 201,
|
||||||
SymbolSelect = 202,
|
SymbolSelect = 202,
|
||||||
SymbolInfoInteger = 203
|
SymbolInfoInteger = 203,
|
||||||
|
|
||||||
|
//Object Functions
|
||||||
|
ObjectCreate = 208,
|
||||||
|
ObjectName = 209,
|
||||||
|
ObjectDelete = 210,
|
||||||
|
ObjectsDeleteAll = 211,
|
||||||
|
ObjectFind = 212,
|
||||||
|
ObjectGetTimeByValue = 213,
|
||||||
|
ObjectGetValueByTime = 214,
|
||||||
|
ObjectMove = 215,
|
||||||
|
ObjectsTotal = 216,
|
||||||
|
ObjectGetDouble = 217,
|
||||||
|
ObjectGetInteger = 218,
|
||||||
|
ObjectGetString = 219,
|
||||||
|
ObjectSetDouble = 220,
|
||||||
|
ObjectSetInteger = 221,
|
||||||
|
ObjectSetString = 222,
|
||||||
|
TextSetFont = 223,
|
||||||
|
TextOut = 224,
|
||||||
|
TextGetSize = 225,
|
||||||
|
ObjectDescription = 226,
|
||||||
|
ObjectGet = 227,
|
||||||
|
ObjectGetFiboDescription = 228,
|
||||||
|
ObjectGetShiftByValue = 229,
|
||||||
|
ObjectGetValueByShift = 230,
|
||||||
|
ObjectSet = 231,
|
||||||
|
ObjectSetFiboDescription = 232,
|
||||||
|
ObjectSetText = 233,
|
||||||
|
ObjectType = 234,
|
||||||
|
|
||||||
|
UnlockTicks = 235,
|
||||||
|
|
||||||
|
//Chart Operations
|
||||||
|
ChartId = 206,
|
||||||
|
ChartRedraw = 207,
|
||||||
|
ChartApplyTemplate = 236,
|
||||||
|
ChartSaveTemplate = 237,
|
||||||
|
ChartWindowFind = 238,
|
||||||
|
ChartTimePriceToXY = 239,
|
||||||
|
ChartXYToTimePrice = 240,
|
||||||
|
ChartOpen = 241,
|
||||||
|
ChartFirst = 242,
|
||||||
|
ChartNext = 243,
|
||||||
|
ChartClose = 244,
|
||||||
|
ChartSymbol = 245,
|
||||||
|
ChartPeriod = 246,
|
||||||
|
ChartSetDouble = 247,
|
||||||
|
ChartSetInteger = 248,
|
||||||
|
ChartSetString = 249,
|
||||||
|
ChartGetDouble = 250,
|
||||||
|
ChartGetInteger = 251,
|
||||||
|
ChartGetString = 252,
|
||||||
|
ChartNavigate = 253,
|
||||||
|
ChartIndicatorDelete = 254,
|
||||||
|
ChartIndicatorName = 255,
|
||||||
|
ChartIndicatorsTotal = 256,
|
||||||
|
ChartWindowOnDropped = 257,
|
||||||
|
ChartPriceOnDropped = 258,
|
||||||
|
ChartTimeOnDropped = 259,
|
||||||
|
ChartXOnDropped = 260,
|
||||||
|
ChartYOnDropped = 261,
|
||||||
|
ChartSetSymbolPeriod = 262,
|
||||||
|
ChartScreenShot = 263,
|
||||||
|
WindowBarsPerChart = 264,
|
||||||
|
WindowExpertName = 265,
|
||||||
|
WindowFind = 266,
|
||||||
|
WindowFirstVisibleBar = 267,
|
||||||
|
WindowHandle = 268,
|
||||||
|
WindowIsVisible = 269,
|
||||||
|
WindowOnDropped = 270,
|
||||||
|
WindowPriceMax = 271,
|
||||||
|
WindowPriceMin = 272,
|
||||||
|
WindowPriceOnDropped = 273,
|
||||||
|
WindowRedraw = 274,
|
||||||
|
WindowScreenShot = 275,
|
||||||
|
WindowTimeOnDropped = 276,
|
||||||
|
WindowsTotal = 277,
|
||||||
|
WindowXOnDropped = 278,
|
||||||
|
WindowYOnDropped = 279,
|
||||||
|
|
||||||
|
ChangeAccount = 280
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi
|
namespace MtApi
|
||||||
{
|
{
|
||||||
public class MtConnectionEventArgs: EventArgs
|
public class MtConnectionEventArgs: EventArgs
|
||||||
{
|
{
|
||||||
public MtConnectionState Status { get; private set; }
|
public MtConnectionState Status { get; private set; }
|
||||||
public String ConnectionMessage { get; private set; }
|
public string ConnectionMessage { get; private set; }
|
||||||
|
|
||||||
public MtConnectionEventArgs(MtConnectionState status, string message)
|
public MtConnectionEventArgs(MtConnectionState status, string message)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
public enum MtEventTypes
|
public enum MtEventTypes
|
||||||
{
|
{
|
||||||
LastTimeBar = 1
|
LastTimeBar = 1,
|
||||||
|
ChartEvent = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
public string Instrument { get; private set; }
|
public string Instrument { get; private set; }
|
||||||
public double Bid { get; private set; }
|
public double Bid { get; private set; }
|
||||||
public double Ask { get; private set; }
|
public double Ask { get; private set; }
|
||||||
|
public int ExpertHandle { get; private set; }
|
||||||
|
|
||||||
public MtQuote(string instrument, double bid, double ask)
|
public MtQuote(string instrument, double bid, double ask)
|
||||||
{
|
{
|
||||||
@@ -12,5 +13,13 @@
|
|||||||
Bid = bid;
|
Bid = bid;
|
||||||
Ask = ask;
|
Ask = ask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal MtQuote(MTApiService.MtQuote quote)
|
||||||
|
{
|
||||||
|
Instrument = quote.Instrument;
|
||||||
|
Bid = quote.Bid;
|
||||||
|
Ask = quote.Ask;
|
||||||
|
ExpertHandle = quote.ExpertHandle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi
|
namespace MtApi
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-11
@@ -11,16 +11,7 @@ namespace MtApi
|
|||||||
public double Close { get; set; }
|
public double Close { get; set; }
|
||||||
public double High { get; set; }
|
public double High { get; set; }
|
||||||
public double Low { get; set; }
|
public double Low { get; set; }
|
||||||
|
public DateTime OpenTime => MtApiTimeConverter.ConvertFromMtTime(MtOpenTime);
|
||||||
public DateTime OpenTime
|
public DateTime CloseTime => MtApiTimeConverter.ConvertFromMtTime(MtCloseTime);
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtOpenTime); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public DateTime CloseTime
|
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
namespace MtApi
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi
|
||||||
{
|
{
|
||||||
public enum ENUM_TERMINAL_INFO_STRING
|
public enum ENUM_TERMINAL_INFO_STRING
|
||||||
{
|
{
|
||||||
|
|||||||
Executable → Regular
+2
-2
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.32.0")]
|
[assembly: AssemblyVersion("1.0.40.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.32.0")]
|
[assembly: AssemblyFileVersion("1.0.40.0")]
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MtApi
|
namespace MtApi
|
||||||
{
|
{
|
||||||
public class TimeBarArgs: EventArgs
|
public class TimeBarArgs: EventArgs
|
||||||
{
|
{
|
||||||
|
internal TimeBarArgs(int expertHandle, MtTimeBar timeBar)
|
||||||
|
: this(timeBar)
|
||||||
|
{
|
||||||
|
ExpertHandle = expertHandle;
|
||||||
|
}
|
||||||
|
|
||||||
public TimeBarArgs(MtTimeBar timeBar)
|
public TimeBarArgs(MtTimeBar timeBar)
|
||||||
{
|
{
|
||||||
TimeBar = timeBar;
|
TimeBar = timeBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtTimeBar TimeBar { get; private set; }
|
public int ExpertHandle { get; }
|
||||||
|
public MtTimeBar TimeBar { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace MtApi5.Events
|
||||||
|
{
|
||||||
|
internal enum Mt5EventTypes
|
||||||
|
{
|
||||||
|
OnTradeTransaction = 1,
|
||||||
|
OnBookEvent = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace MtApi5.Events
|
||||||
|
{
|
||||||
|
internal class OnBookEvent
|
||||||
|
{
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi5.Events
|
||||||
|
{
|
||||||
|
internal class OnTradeTransactionEvent
|
||||||
|
{
|
||||||
|
public MqlTradeTransaction Trans { get; set; }
|
||||||
|
public MqlTradeRequest Request { get; set; }
|
||||||
|
public MqlTradeResult Result { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace MtApi5
|
|
||||||
{
|
|
||||||
internal static class ExtensionMethods
|
|
||||||
{
|
|
||||||
#region Event Methods
|
|
||||||
public static void FireEvent(this EventHandler eventHandler, object sender)
|
|
||||||
{
|
|
||||||
eventHandler?.Invoke(sender, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void FireEvent<T>(this EventHandler<T> eventHandler, object sender, T e)
|
|
||||||
where T : EventArgs
|
|
||||||
{
|
|
||||||
eventHandler?.Invoke(sender, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class MqlBookInfo
|
public class MqlBookInfo
|
||||||
@@ -14,8 +10,13 @@ namespace MtApi5
|
|||||||
this.volume = volume;
|
this.volume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ENUM_BOOK_TYPE type { get; private set; } // Order type from ENUM_BOOK_TYPE enumeration
|
public ENUM_BOOK_TYPE type { get; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||||
public double price { get; private set; } // Price
|
public double price { get; } // Price
|
||||||
public long volume { get; private set; } // Volume
|
public long volume { get; } // Volume
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{type}|{price}|{volume}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace MtApi5
|
||||||
|
{
|
||||||
|
public class MqlParam
|
||||||
|
{
|
||||||
|
public ENUM_DATATYPE DataType { get; set; }
|
||||||
|
public long? IntegerValue { get; set; }
|
||||||
|
public double? DoubleValue { get; set; }
|
||||||
|
public string StringValue { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class MqlTradeCheckResult
|
public class MqlTradeCheckResult
|
||||||
{
|
{
|
||||||
public uint Retcode { get; private set; } // Reply code
|
public uint Retcode { get; } // Reply code
|
||||||
public double Balance { get; private set; } // Balance after the execution of the deal
|
public double Balance { get; } // Balance after the execution of the deal
|
||||||
public double Equity { get; private set; } // Equity after the execution of the deal
|
public double Equity { get; } // Equity after the execution of the deal
|
||||||
public double Profit { get; private set; } // Floating profit
|
public double Profit { get; } // Floating profit
|
||||||
public double Margin { get; private set; } // Margin requirements
|
public double Margin { get; } // Margin requirements
|
||||||
public double Margin_free { get; private set; } // Free margin
|
public double Margin_free { get; } // Free margin
|
||||||
public double Margin_level { get; private set; } // Margin level
|
public double Margin_level { get; } // Margin level
|
||||||
public string Comment { get; private set; } // Comment to the reply code (description of the error)
|
public string Comment { get; } // Comment to the reply code (description of the error)
|
||||||
|
|
||||||
public MqlTradeCheckResult(uint retcode
|
public MqlTradeCheckResult(uint retcode
|
||||||
, double balance
|
, double balance
|
||||||
@@ -34,5 +31,10 @@ namespace MtApi5
|
|||||||
Margin_level = margin_level;
|
Margin_level = margin_level;
|
||||||
Comment = comment;
|
Comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Retcode={Retcode}; Comment={Comment}; Balance={Balance}; Equity={Equity}; Profit={Profit}; Margin={Margin}; Margin_free={Margin_free}; Margin_level={Margin_level}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class MqlTradeRequest
|
public class MqlTradeRequest
|
||||||
{
|
{
|
||||||
public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type
|
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 ulong Order { get; set; } // Order ticket
|
||||||
public string Symbol { get; set; } // Trade symbol
|
public string Symbol { get; set; } // Trade symbol
|
||||||
public double Volume { get; set; } // Requested volume for a deal in lots
|
public double Volume { get; set; } // Requested volume for a deal in lots
|
||||||
@@ -13,11 +15,27 @@ namespace MtApi5
|
|||||||
public double Stoplimit { get; set; } // StopLimit level of the order
|
public double Stoplimit { get; set; } // StopLimit level of the order
|
||||||
public double Sl { get; set; } // Stop Loss 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 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 Type { get; set; } // Order type
|
||||||
public ENUM_ORDER_TYPE_FILLING Type_filling { get; set; } // Order execution 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 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)
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public DateTime Expiration // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
|
||||||
|
{
|
||||||
|
get { return Mt5TimeConverter.ConvertFromMtTime(MtExpiration); }
|
||||||
|
set { MtExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||||
|
}
|
||||||
|
|
||||||
public string Comment { get; set; } // Order comment
|
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
|
||||||
|
|
||||||
|
public int MtExpiration { get; private set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Action={Action}; Magic={Magic}; Order={Order}; Symbol={Symbol}; Volume={Volume}; Price={Price}; Stoplimit={Stoplimit}; Sl={Sl}; Tp={Tp}; Deviation={Deviation}; Type={Type}; Type_filling={Type_filling}; Type_time={Type_time}; Expiration={Expiration}; Comment={Comment}; Position={Position}; PositionBy={PositionBy}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-12
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
@@ -19,14 +17,32 @@ namespace MtApi5
|
|||||||
Request_id = request_id;
|
Request_id = request_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint Retcode { get; private set; } // Operation return code
|
internal MqlTradeResult(MqlTradeResult o)
|
||||||
public ulong Deal { get; private set; } // Deal ticket, if it is performed
|
{
|
||||||
public ulong Order { get; private set; } // Order ticket, if it is placed
|
Retcode = o.Retcode;
|
||||||
public double Volume { get; private set; } // Deal volume, confirmed by broker
|
Deal = o.Deal;
|
||||||
public double Price { get; private set; } // Deal price, confirmed by broker
|
Order = o.Order;
|
||||||
public double Bid { get; private set; } // Current Bid price
|
Volume = o.Volume;
|
||||||
public double Ask { get; private set; } // Current Ask price
|
Price = o.Price;
|
||||||
public string Comment { get; private set; } // Broker comment to operation (by default it is filled by the operation description)
|
Bid = o.Bid;
|
||||||
public uint Request_id { get; private set; } // Request ID set by the terminal during the dispatch
|
Ask = o.Ask;
|
||||||
|
Comment = o.Comment;
|
||||||
|
Request_id = o.Request_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint Retcode { get; } // Operation return code
|
||||||
|
public ulong Deal { get; } // Deal ticket, if it is performed
|
||||||
|
public ulong Order { get; } // Order ticket, if it is placed
|
||||||
|
public double Volume { get; } // Deal volume, confirmed by broker
|
||||||
|
public double Price { get; } // Deal price, confirmed by broker
|
||||||
|
public double Bid { get; } // Current Bid price
|
||||||
|
public double Ask { get; } // Current Ask price
|
||||||
|
public string Comment { get; } // Broker comment to operation (by default it is filled by the operation description)
|
||||||
|
public uint Request_id { get; } // Request ID set by the terminal during the dispatch
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Retcode={Retcode}; Comment={Comment}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Request_id={Request_id}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MtApi5
|
||||||
|
{
|
||||||
|
public class MqlTradeTransaction
|
||||||
|
{
|
||||||
|
public ulong Deal { get; set; } // Deal ticket
|
||||||
|
public ulong Order { get; set; } // Order ticket
|
||||||
|
public string Symbol { get; set; } // Trade symbol name
|
||||||
|
public ENUM_TRADE_TRANSACTION_TYPE Type { get; set; } // Trade transaction type
|
||||||
|
public ENUM_ORDER_TYPE OrderType { get; set; } // Order type
|
||||||
|
public ENUM_ORDER_STATE OrderState { get; set; } // Order state
|
||||||
|
public ENUM_DEAL_TYPE DealType { get; set; } // Deal type
|
||||||
|
public ENUM_ORDER_TYPE_TIME TimeType { get; set; } // Order type by action period
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public DateTime TimeExpiration // Order expiration time
|
||||||
|
{
|
||||||
|
get { return Mt5TimeConverter.ConvertFromMtTime(MtTimeExpiration); }
|
||||||
|
set { MtTimeExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Price { get; set; } // Price
|
||||||
|
public double PriceTrigger { get; set; } // Stop limit order activation price
|
||||||
|
public double PriceSl { get; set; } // Stop Loss level
|
||||||
|
public double PriceTp { get; set; } // Take Profit level
|
||||||
|
public double Volume { get; set; } // Volume in lots
|
||||||
|
public ulong Position { get; set; } // Position ticket
|
||||||
|
public ulong PositionBy { get; set; } // Ticket of an opposite position
|
||||||
|
|
||||||
|
public int MtTimeExpiration { get; private set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Deal={Deal}; Order={Order}; Symbol={Symbol}; Type={Type}; OrderType={OrderType}; OrderState={OrderState}; DealType={DealType}; TimeType={TimeType}; TimeExpiration={TimeExpiration}; Price={Price}; PriceTrigger{PriceTrigger}; PriceSl={PriceSl}; PriceTp={PriceTp}; Volume={Volume}; Position={Position}; PositionBy={PositionBy}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MtApi5
|
||||||
|
{
|
||||||
|
public class Mt5BookEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public int ExpertHandle { get; set; }
|
||||||
|
public string Symbol { get; set; } //Symbol of OnBookEvent event.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
internal enum Mt5CommandType
|
internal enum Mt5CommandType
|
||||||
@@ -10,10 +6,10 @@ namespace MtApi5
|
|||||||
//NoCommand = 0
|
//NoCommand = 0
|
||||||
|
|
||||||
//trade operations
|
//trade operations
|
||||||
OrderSend = 1,
|
//OrderSend = 1,
|
||||||
OrderCalcMargin = 2,
|
OrderCalcMargin = 2,
|
||||||
OrderCalcProfit = 3,
|
OrderCalcProfit = 3,
|
||||||
OrderCheck = 4,
|
//OrderCheck = 4,
|
||||||
//OrderSendAsync = 5,
|
//OrderSendAsync = 5,
|
||||||
PositionsTotal = 6,
|
PositionsTotal = 6,
|
||||||
PositionGetSymbol = 7,
|
PositionGetSymbol = 7,
|
||||||
@@ -99,12 +95,13 @@ namespace MtApi5
|
|||||||
SymbolInfoSessionTrade = 59,
|
SymbolInfoSessionTrade = 59,
|
||||||
MarketBookAdd = 60,
|
MarketBookAdd = 60,
|
||||||
MarketBookRelease = 61,
|
MarketBookRelease = 61,
|
||||||
MarketBookGet = 62,
|
//MarketBookGet = 62,
|
||||||
OrderCloseAll = 63,
|
OrderCloseAll = 63,
|
||||||
|
|
||||||
//CTrade
|
//CTrade
|
||||||
PositionClose = 64,
|
PositionClose = 64,
|
||||||
PositionOpen = 65,
|
PositionOpen = 65,
|
||||||
|
//PositionOpenWithResult = 1065,
|
||||||
|
|
||||||
//Backtesting
|
//Backtesting
|
||||||
BacktestingReady = 66,
|
BacktestingReady = 66,
|
||||||
@@ -114,5 +111,74 @@ namespace MtApi5
|
|||||||
|
|
||||||
//Requests
|
//Requests
|
||||||
MtRequest = 155,
|
MtRequest = 155,
|
||||||
|
|
||||||
|
PositionSelectByTicket = 69,
|
||||||
|
|
||||||
|
ObjectCreate = 70,
|
||||||
|
ObjectName = 71,
|
||||||
|
ObjectDelete = 72,
|
||||||
|
ObjectsDeleteAll = 73,
|
||||||
|
ObjectFind = 74,
|
||||||
|
ObjectGetTimeByValue = 75,
|
||||||
|
ObjectGetValueByTime = 76,
|
||||||
|
ObjectMove = 77,
|
||||||
|
ObjectsTotal = 78,
|
||||||
|
ObjectGetDouble = 79,
|
||||||
|
ObjectGetInteger = 80,
|
||||||
|
ObjectGetString = 81,
|
||||||
|
ObjectSetDouble = 82,
|
||||||
|
ObjectSetInteger = 83,
|
||||||
|
ObjectSetString = 84,
|
||||||
|
//TextSetFont = 85,
|
||||||
|
//TextOut = 86,
|
||||||
|
//TextGetSize = 87,
|
||||||
|
|
||||||
|
iAC = 88,
|
||||||
|
iAD = 89,
|
||||||
|
iADX = 90,
|
||||||
|
iADXWilder = 91,
|
||||||
|
iAlligator = 92,
|
||||||
|
iAMA = 93,
|
||||||
|
iAO = 94,
|
||||||
|
iATR = 95,
|
||||||
|
iBearsPower = 96,
|
||||||
|
iBands = 97,
|
||||||
|
iBullsPower = 98,
|
||||||
|
iCCI = 99,
|
||||||
|
iChaikin = 100,
|
||||||
|
//iCustom = 101,
|
||||||
|
iDEMA = 102,
|
||||||
|
iDeMarker = 103,
|
||||||
|
iEnvelopes = 104,
|
||||||
|
iForce = 105,
|
||||||
|
iFractals = 106,
|
||||||
|
iFrAMA = 107,
|
||||||
|
iGator = 108,
|
||||||
|
iIchimoku = 109,
|
||||||
|
iBWMFI = 110,
|
||||||
|
iMomentum = 111,
|
||||||
|
iMFI = 112,
|
||||||
|
iMA = 113,
|
||||||
|
iOsMA = 114,
|
||||||
|
iMACD = 115,
|
||||||
|
iOBV = 116,
|
||||||
|
iSAR = 117,
|
||||||
|
iRSI = 118,
|
||||||
|
iRVI = 119,
|
||||||
|
iStdDev = 120,
|
||||||
|
iStochastic = 121,
|
||||||
|
iTEMA = 122,
|
||||||
|
iTriX = 123,
|
||||||
|
iWPR = 124,
|
||||||
|
iVIDyA = 125,
|
||||||
|
iVolumes = 126,
|
||||||
|
|
||||||
|
//Date and Time
|
||||||
|
TimeCurrent = 127,
|
||||||
|
TimeTradeServer = 128,
|
||||||
|
TimeLocal = 129,
|
||||||
|
TimeGMT = 130,
|
||||||
|
|
||||||
|
IndicatorRelease = 131
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class Mt5ConnectionEventArgs: EventArgs
|
public class Mt5ConnectionEventArgs: EventArgs
|
||||||
{
|
{
|
||||||
public Mt5ConnectionState Status { get; private set; }
|
public Mt5ConnectionState Status { get; }
|
||||||
public String ConnectionMessage { get; private set; }
|
public string ConnectionMessage { get; }
|
||||||
|
|
||||||
public Mt5ConnectionEventArgs(Mt5ConnectionState status, string message)
|
public Mt5ConnectionEventArgs(Mt5ConnectionState status, string message)
|
||||||
{
|
{
|
||||||
|
|||||||
+730
-212
File diff suppressed because it is too large
Load Diff
+4
-9
@@ -1,15 +1,10 @@
|
|||||||
using System;
|
namespace MtApi5
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
|
||||||
{
|
{
|
||||||
public class Mt5Quote
|
public class Mt5Quote
|
||||||
{
|
{
|
||||||
public string Instrument { get; private set; }
|
public string Instrument { get; }
|
||||||
public double Bid { get; private set; }
|
public double Bid { get; }
|
||||||
public double Ask { get; private set; }
|
public double Ask { get; }
|
||||||
|
|
||||||
public Mt5Quote(string instrument, double bid, double ask)
|
public Mt5Quote(string instrument, double bid, double ask)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class Mt5QuoteEventArgs: EventArgs
|
public class Mt5QuoteEventArgs: EventArgs
|
||||||
{
|
{
|
||||||
public Mt5Quote Quote { get; private set; }
|
public Mt5Quote Quote { get; }
|
||||||
|
|
||||||
public Mt5QuoteEventArgs(Mt5Quote quote)
|
public Mt5QuoteEventArgs(Mt5Quote quote)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,32 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
class Mt5TimeConverter
|
internal class Mt5TimeConverter
|
||||||
{
|
{
|
||||||
public static DateTime ConvertFromMtTime(int time)
|
public static DateTime ConvertFromMtTime(int time)
|
||||||
{
|
{
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
var tmpTime = new DateTime(1970, 1, 1);
|
||||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateTime ConvertFromMtTime(long time)
|
public static DateTime ConvertFromMtTime(long time)
|
||||||
{
|
{
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
var tmpTime = new DateTime(1970, 1, 1);
|
||||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ConvertToMtTime(DateTime time)
|
public static int ConvertToMtTime(DateTime time)
|
||||||
{
|
{
|
||||||
int result = 0;
|
var result = 0;
|
||||||
if (time != DateTime.MinValue)
|
if (time == DateTime.MinValue) return result;
|
||||||
{
|
var tmpTime = new DateTime(1970, 1, 1);
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||||
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MtApi5
|
||||||
|
{
|
||||||
|
public class Mt5TradeTransactionEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public int ExpertHandle { get; set; }
|
||||||
|
public MqlTradeTransaction Trans { get; set; } // trade transaction structure
|
||||||
|
public MqlTradeRequest Request { get; set; } // request structure
|
||||||
|
public MqlTradeResult Result { get; set; } // result structure
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-3
@@ -48,30 +48,43 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CopyTicksFlag.cs" />
|
<Compile Include="CopyTicksFlag.cs" />
|
||||||
|
<Compile Include="Events\OnBookEvent.cs" />
|
||||||
|
<Compile Include="Events\OnTradeTransactionEvent.cs" />
|
||||||
<Compile Include="MqlBookInfo.cs" />
|
<Compile Include="MqlBookInfo.cs" />
|
||||||
|
<Compile Include="MqlParam.cs" />
|
||||||
<Compile Include="MqlRates.cs" />
|
<Compile Include="MqlRates.cs" />
|
||||||
<Compile Include="MqlTick.cs" />
|
<Compile Include="MqlTick.cs" />
|
||||||
<Compile Include="MqlTradeCheckResult.cs" />
|
<Compile Include="MqlTradeCheckResult.cs" />
|
||||||
|
<Compile Include="MqlTradeTransaction.cs" />
|
||||||
|
<Compile Include="Mt5BookEventArgs.cs" />
|
||||||
<Compile Include="Mt5TimeConverter.cs" />
|
<Compile Include="Mt5TimeConverter.cs" />
|
||||||
<Compile Include="Mt5Enums.cs" />
|
<Compile Include="Mt5Enums.cs" />
|
||||||
<Compile Include="Mt5ConnectionEventArgs.cs" />
|
<Compile Include="Mt5ConnectionEventArgs.cs" />
|
||||||
<Compile Include="Mt5ConnectionState.cs" />
|
<Compile Include="Mt5ConnectionState.cs" />
|
||||||
<Compile Include="ExtensionMethods.cs" />
|
|
||||||
<Compile Include="MqlTradeRequest.cs" />
|
<Compile Include="MqlTradeRequest.cs" />
|
||||||
<Compile Include="MqlTradeResult.cs" />
|
<Compile Include="MqlTradeResult.cs" />
|
||||||
<Compile Include="Mt5QuoteEventArgs.cs" />
|
<Compile Include="Mt5QuoteEventArgs.cs" />
|
||||||
|
<Compile Include="Mt5TradeTransactionEventArgs.cs" />
|
||||||
<Compile Include="MtApi5Client.cs" />
|
<Compile Include="MtApi5Client.cs" />
|
||||||
<Compile Include="Mt5CommandType.cs" />
|
<Compile Include="Mt5CommandType.cs" />
|
||||||
<Compile Include="MtConverters.cs" />
|
<Compile Include="MtConverters.cs" />
|
||||||
<Compile Include="ErrorCode.cs" />
|
<Compile Include="ErrorCode.cs" />
|
||||||
<Compile Include="ExecutionException.cs" />
|
<Compile Include="ExecutionException.cs" />
|
||||||
|
<Compile Include="Events\Mt5EventTypes.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Mt5Quote.cs" />
|
<Compile Include="Mt5Quote.cs" />
|
||||||
<Compile Include="Requests\CopyTicksRequest.cs" />
|
<Compile Include="Requests\CopyTicksRequest.cs" />
|
||||||
|
<Compile Include="Requests\ICustomRequest.cs" />
|
||||||
|
<Compile Include="Requests\IndicatorCreateRequest.cs" />
|
||||||
|
<Compile Include="Requests\MarketBookGetRequest.cs" />
|
||||||
|
<Compile Include="Requests\OrderCheckRequest.cs" />
|
||||||
|
<Compile Include="Requests\OrderCheckResult.cs" />
|
||||||
|
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||||
|
<Compile Include="Requests\PositionOpenRequest.cs" />
|
||||||
<Compile Include="Requests\RequestBase.cs" />
|
<Compile Include="Requests\RequestBase.cs" />
|
||||||
<Compile Include="Requests\RequestType.cs" />
|
<Compile Include="Requests\RequestType.cs" />
|
||||||
<Compile Include="Responses\CopyTicksResponse.cs" />
|
<Compile Include="Requests\OrderSendResult.cs" />
|
||||||
<Compile Include="Responses\ResponseBase.cs" />
|
<Compile Include="Requests\Response.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||||
@@ -82,6 +95,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
+1194
-162
File diff suppressed because it is too large
Load Diff
+21
-75
@@ -6,84 +6,18 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
internal static class MtConverters
|
internal static class MtConverters
|
||||||
{
|
{
|
||||||
|
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtConverters));
|
||||||
|
|
||||||
#region Values Converters
|
#region Values Converters
|
||||||
public static Mt5Quote Parse(this MtQuote quote)
|
public static Mt5Quote Convert(this MtQuote quote)
|
||||||
{
|
{
|
||||||
return (quote != null) ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
return quote != null ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
|
||||||
{
|
|
||||||
var retVal = false;
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
|
||||||
{
|
|
||||||
var values = inputString.Split(separator);
|
|
||||||
if (values.Length == 10)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
retVal = int.Parse(values[0]) != 0;
|
|
||||||
|
|
||||||
var retcode = uint.Parse(values[1]);
|
|
||||||
var deal = ulong.Parse(values[2]);
|
|
||||||
var order = ulong.Parse(values[3]);
|
|
||||||
var volume = double.Parse(values[4]);
|
|
||||||
var price = double.Parse(values[5]);
|
|
||||||
var bid = double.Parse(values[6]);
|
|
||||||
var ask = double.Parse(values[7]);
|
|
||||||
var comment = values[8];
|
|
||||||
var requestId = uint.Parse(values[9]);
|
|
||||||
|
|
||||||
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
|
||||||
{
|
|
||||||
var retVal = false;
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
|
||||||
{
|
|
||||||
var values = inputString.Split(separator);
|
|
||||||
if (values.Length == 10)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
retVal = int.Parse(values[0]) != 0;
|
|
||||||
|
|
||||||
var retcode = uint.Parse(values[1]);
|
|
||||||
var balance = double.Parse(values[2]);
|
|
||||||
var equity = double.Parse(values[3]);
|
|
||||||
var profit = double.Parse(values[4]);
|
|
||||||
var margin = double.Parse(values[5]);
|
|
||||||
var marginFree = double.Parse(values[6]);
|
|
||||||
var marginLevel = double.Parse(values[7]);
|
|
||||||
var comment = values[8];
|
|
||||||
|
|
||||||
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
retVal = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out double result)
|
public static bool ParseResult(this string inputString, char separator, out double result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
@@ -98,18 +32,25 @@ namespace MtApi5
|
|||||||
|
|
||||||
result = double.Parse(values[1]);
|
result = double.Parse(values[1]);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
|
|
||||||
from = new DateTime();
|
from = new DateTime();
|
||||||
@@ -130,12 +71,17 @@ namespace MtApi5
|
|||||||
var iTo= int.Parse(values[2]);
|
var iTo= int.Parse(values[2]);
|
||||||
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
@@ -149,7 +95,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
return new ArrayList { (int)request.Action, request.Magic, request.Order, request.Symbol, request.Volume
|
return new ArrayList { (int)request.Action, request.Magic, request.Order, request.Symbol, request.Volume
|
||||||
, request.Price, request.Stoplimit, request.Sl, request.Tp, request.Deviation, (int)request.Type
|
, request.Price, request.Stoplimit, request.Sl, request.Tp, request.Deviation, (int)request.Type
|
||||||
, (int)request.Type_filling, (int)request.Type_time, exp, request.Comment };
|
, (int)request.Type_filling, (int)request.Type_time, exp, request.Comment, request.Position, request.PositionBy };
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.11.0")]
|
[assembly: AssemblyVersion("1.0.17")]
|
||||||
[assembly: AssemblyFileVersion("1.0.11.0")]
|
[assembly: AssemblyFileVersion("1.0.17")]
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class ICustomRequest : RequestBase
|
||||||
|
{
|
||||||
|
public enum ParametersType
|
||||||
|
{
|
||||||
|
Int = 0,
|
||||||
|
Double = 1,
|
||||||
|
String = 2,
|
||||||
|
Boolean = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public int Timeframe { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public ArrayList Params { get; set; }
|
||||||
|
public ParametersType ParamsType { get; set; }
|
||||||
|
|
||||||
|
public override RequestType RequestType => RequestType.iCustom;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class IndicatorCreateRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.IndicatorCreate;
|
||||||
|
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public ENUM_TIMEFRAMES Period { get; set; }
|
||||||
|
public ENUM_INDICATOR IndicatorType { get; set; }
|
||||||
|
public List<MqlParam> Parameters { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class MarketBookGetRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.MarketBookGet;
|
||||||
|
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderCheckRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.OrderCheck;
|
||||||
|
|
||||||
|
public MqlTradeRequest TradeRequest { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
public class OrderCheckResult
|
||||||
|
{
|
||||||
|
public bool RetVal { get; set; }
|
||||||
|
public MqlTradeCheckResult TradeCheckResult { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderSendRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.OrderSend;
|
||||||
|
|
||||||
|
public MqlTradeRequest TradeRequest { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderSendResult
|
||||||
|
{
|
||||||
|
public bool RetVal { get; set; }
|
||||||
|
public MqlTradeResult TradeResult { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class PositionOpenRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.PositionOpen;
|
||||||
|
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public ENUM_ORDER_TYPE OrderType { get; set; }
|
||||||
|
public double Volume { get; set; }
|
||||||
|
public double Price { get; set; }
|
||||||
|
public double Sl { get; set; }
|
||||||
|
public double Tp { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,16 @@
|
|||||||
namespace MtApi5.Requests
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi5.Requests
|
||||||
{
|
{
|
||||||
internal enum RequestType
|
internal enum RequestType
|
||||||
{
|
{
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
CopyTicks = 1
|
CopyTicks = 1,
|
||||||
|
iCustom = 2,
|
||||||
|
OrderSend = 3,
|
||||||
|
PositionOpen = 4,
|
||||||
|
OrderCheck = 5,
|
||||||
|
MarketBookGet = 6,
|
||||||
|
IndicatorCreate = 7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Executable → Regular
+4
-2
@@ -1,8 +1,10 @@
|
|||||||
namespace MtApi5.Responses
|
namespace MtApi5.Requests
|
||||||
{
|
{
|
||||||
internal class ResponseBase
|
internal class Response<T>
|
||||||
{
|
{
|
||||||
public int ErrorCode { get; set; }
|
public int ErrorCode { get; set; }
|
||||||
public string ErrorMessage { get; set; }
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
public T Value { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace MtApi5.Responses
|
|
||||||
{
|
|
||||||
internal class CopyTicksResponse: ResponseBase
|
|
||||||
{
|
|
||||||
public List<MqlTick> Ticks { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
<OutputType>Package</OutputType>
|
<OutputType>Package</OutputType>
|
||||||
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
|
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
|
||||||
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
|
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
|
||||||
|
<RunWixToolsOutOfProc>true</RunWixToolsOutOfProc>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<OutputPath>..\build\installers\$(Configuration)\</OutputPath>
|
<OutputPath>..\build\installers\$(Configuration)\</OutputPath>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
||||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||||
xmlns:mtApi5TestClient="clr-namespace:MtApi5TestClient"
|
xmlns:mtApi5TestClient="clr-namespace:MtApi5TestClient"
|
||||||
Title="MainWindow" Height="700" Width="650"
|
Title="MainWindow" Height="700" Width="700"
|
||||||
Closing="Window_Closing">
|
Closing="Window_Closing">
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<DataTemplate x:Key="ConnectionTextBlockTemplate" DataType="{x:Type mtapi5:Mt5ConnectionState}">
|
<DataTemplate x:Key="ConnectionTextBlockTemplate" DataType="{x:Type mtapi5:Mt5ConnectionState}">
|
||||||
@@ -84,6 +84,13 @@
|
|||||||
<x:Type TypeName="mtapi5:ENUM_TIMEFRAMES"/>
|
<x:Type TypeName="mtapi5:ENUM_TIMEFRAMES"/>
|
||||||
</ObjectDataProvider.MethodParameters>
|
</ObjectDataProvider.MethodParameters>
|
||||||
</ObjectDataProvider>
|
</ObjectDataProvider>
|
||||||
|
|
||||||
|
<ObjectDataProvider x:Key="ENUM_INDICATOR_Key" MethodName="GetValues"
|
||||||
|
ObjectType="{x:Type sys:Enum}">
|
||||||
|
<ObjectDataProvider.MethodParameters>
|
||||||
|
<x:Type TypeName="mtapi5:ENUM_INDICATOR"/>
|
||||||
|
</ObjectDataProvider.MethodParameters>
|
||||||
|
</ObjectDataProvider>
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
|
|
||||||
<Grid x:Name="_MainLayout">
|
<Grid x:Name="_MainLayout">
|
||||||
@@ -100,58 +107,33 @@
|
|||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Expander ExpandDirection="Right" IsExpanded="True"
|
<Grid Margin="10">
|
||||||
Grid.Row="0" Grid.Column="0" Margin="5">
|
<Grid.RowDefinitions>
|
||||||
<Expander.Header>
|
<RowDefinition Height="Auto"/>
|
||||||
<TextBlock Text="Connection" RenderTransformOrigin="0.5,0.5" Margin="0,0,0,0" Width="Auto">
|
<RowDefinition Height="Auto"/>
|
||||||
<TextBlock.LayoutTransform>
|
<RowDefinition Height="Auto"/>
|
||||||
<TransformGroup>
|
</Grid.RowDefinitions>
|
||||||
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
|
||||||
<SkewTransform AngleX="0" AngleY="0"/>
|
|
||||||
<RotateTransform Angle="-90"/>
|
|
||||||
<TranslateTransform X="0" Y="0"/>
|
|
||||||
</TransformGroup>
|
|
||||||
</TextBlock.LayoutTransform>
|
|
||||||
<TextBlock.RenderTransform>
|
|
||||||
<TransformGroup>
|
|
||||||
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
|
||||||
<SkewTransform AngleX="0" AngleY="0"/>
|
|
||||||
<RotateTransform Angle="0"/>
|
|
||||||
<TranslateTransform X="0" Y="0"/>
|
|
||||||
</TransformGroup>
|
|
||||||
</TextBlock.RenderTransform>
|
|
||||||
</TextBlock>
|
|
||||||
</Expander.Header>
|
|
||||||
<Expander.Content>
|
|
||||||
<Grid Margin="10">
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="150"/>
|
<ColumnDefinition Width="150"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Host"/>
|
<TextBlock Grid.Row="0" Grid.Column="0" Text="Host"/>
|
||||||
<TextBox Grid.Row="0" Grid.Column="1"
|
<TextBox Grid.Row="0" Grid.Column="1"
|
||||||
Margin="5,0,0,0"
|
Margin="5,0,0,0"
|
||||||
Text="{Binding Host, UpdateSourceTrigger=PropertyChanged}"/>
|
Text="{Binding Host, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Port"/>
|
<TextBlock Grid.Row="1" Grid.Column="0" Text="Port"/>
|
||||||
<TextBox Grid.Row="1" Grid.Column="1"
|
<TextBox Grid.Row="1" Grid.Column="1"
|
||||||
Margin="5,0,0,0"
|
Margin="5,0,0,0"
|
||||||
Text="{Binding Port, UpdateSourceTrigger=PropertyChanged}"/>
|
Text="{Binding Port, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Orientation="Horizontal">
|
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Orientation="Horizontal">
|
||||||
<Button Content="Connect" Width="70" Command="{Binding ConnectCommand}" />
|
<Button Content="Connect" Width="70" Command="{Binding ConnectCommand}" />
|
||||||
<Button Margin="5,0,0,0" Width="70" Content="Disconnect" Command="{Binding DisconnectCommand}" />
|
<Button Margin="5,0,0,0" Width="70" Content="Disconnect" Command="{Binding DisconnectCommand}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Expander.Content>
|
|
||||||
</Expander>
|
|
||||||
|
|
||||||
<ListView Grid.Row="0" Grid.Column="1"
|
<ListView Grid.Row="0" Grid.Column="1"
|
||||||
ItemsSource="{Binding Quotes}"
|
ItemsSource="{Binding Quotes}"
|
||||||
@@ -247,15 +229,26 @@
|
|||||||
SelectedItem="{Binding TradeRequest.Type_time}" Margin="5,0,0,0"/>
|
SelectedItem="{Binding TradeRequest.Type_time}" Margin="5,0,0,0"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="2" Grid.Row="6" Text="Expiration" Margin="10,0,0,0"/>
|
<TextBlock Grid.Column="2" Grid.Row="6" Text="Expiration" Margin="10,0,0,0"/>
|
||||||
<TextBox Grid.Column="3" Grid.Row="6" Text="{Binding TradeRequest}" Margin="5,0,0,0"/>
|
<TextBox Grid.Column="3" Grid.Row="6" Text="{Binding TradeRequest.Expiration}" Margin="5,0,0,0"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="0" Grid.Row="7" Text="Comment"/>
|
<TextBlock Grid.Column="0" Grid.Row="7" Text="Comment"/>
|
||||||
<TextBox Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="3" Text="{Binding TradeRequest}" Margin="5,0,0,0"/>
|
<TextBox Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="3" Text="{Binding TradeRequest.Comment}" Margin="5,0,0,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Expander>
|
</Expander>
|
||||||
|
|
||||||
<StackPanel Grid.Row="1" Orientation="Horizontal">
|
<StackPanel Grid.Row="1" Orientation="Vertical">
|
||||||
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25"/>
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="OrderCheck" Command="{Binding OrderCheckCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<WrapPanel>
|
||||||
|
<Button Content="HistoryDealGetDouble" Command="{Binding HistoryDealGetDoubleCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryDealGetInteger" Command="{Binding HistoryDealGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryDealGetString" Command="{Binding HistoryDealGetStringCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryOrderGetInteger" Command="{Binding HistoryOrderGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryDealMethods" Command="{Binding HistoryDealMethodsCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
</WrapPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -319,32 +312,37 @@
|
|||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Grid Grid.Column="1">
|
<Grid Grid.Column="1" Margin="2">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<Grid.ColumnDefinitions>
|
<Grid Grid.Row="0">
|
||||||
<ColumnDefinition Width="Auto"/>
|
<Grid.RowDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Grid.Row="0" Text="Symbol Name" Margin="1"/>
|
||||||
|
<TextBlock Grid.Row="1" Grid.Column="0" Text="TimeFrame" Margin="1" HorizontalAlignment="Right"/>
|
||||||
|
<TextBlock Grid.Row="2" Grid.Column="0" Text="StartPos" Margin="1" HorizontalAlignment="Right"/>
|
||||||
|
<TextBlock Grid.Row="3" Grid.Column="0" Text="Count" Margin="1" HorizontalAlignment="Right"/>
|
||||||
|
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}" Margin="1"/>
|
||||||
|
<ComboBox Grid.Row="1" Grid.Column="1" Margin="1"
|
||||||
|
ItemsSource="{Binding Source={StaticResource ENUM_TIMEFRAMES_Key}}"
|
||||||
|
SelectedItem="{Binding TimeSeriesValues.TimeFrame}"/>
|
||||||
|
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding TimeSeriesValues.StartPos}" Margin="1"/>
|
||||||
|
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TimeSeriesValues.Count}" Margin="1"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<TextBox Grid.Row="0" Text="symbolName"/>
|
<WrapPanel Grid.Row="1" Grid.Column="0" Margin="5">
|
||||||
<TextBox Grid.Row="1" Grid.Column="0" Text="timeframe"/>
|
|
||||||
<TextBox Grid.Row="2" Grid.Column="0" Text="startPos"/>
|
|
||||||
<TextBox Grid.Row="3" Grid.Column="0" Text="count"/>
|
|
||||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}"/>
|
|
||||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
|
||||||
ItemsSource="{Binding Source={StaticResource ENUM_TIMEFRAMES_Key}}"
|
|
||||||
SelectedItem="{Binding TimeSeriesValues.TimeFrame}"/>
|
|
||||||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding TimeSeriesValues.StartPos}"/>
|
|
||||||
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TimeSeriesValues.Count}"/>
|
|
||||||
|
|
||||||
<WrapPanel Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Margin="10">
|
|
||||||
<Button Command="{Binding CopyRatesCommand}" Margin="1"
|
<Button Command="{Binding CopyRatesCommand}" Margin="1"
|
||||||
Content="CopyRates" HorizontalAlignment="Left" />
|
Content="CopyRates" HorizontalAlignment="Left" />
|
||||||
<Button Command="{Binding CopyTimesCommand}" Margin="1"
|
<Button Command="{Binding CopyTimesCommand}" Margin="1"
|
||||||
@@ -365,11 +363,33 @@
|
|||||||
Content="CopySpread" HorizontalAlignment="Left" />
|
Content="CopySpread" HorizontalAlignment="Left" />
|
||||||
<Button Command="{Binding CopyTicksCommand}" Margin="1"
|
<Button Command="{Binding CopyTicksCommand}" Margin="1"
|
||||||
Content="CopyTicks" HorizontalAlignment="Left" />
|
Content="CopyTicks" HorizontalAlignment="Left" />
|
||||||
|
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
|
|
||||||
|
<Grid Grid.Row="2">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<ComboBox Grid.Row="0" Grid.Column="0"
|
||||||
|
ItemsSource="{Binding Source={StaticResource ENUM_INDICATOR_Key}}"
|
||||||
|
SelectedItem="{Binding TimeSeriesValues.IndicatorType}"/>
|
||||||
|
<Button Grid.Row="0" Grid.Column="1" Command="{Binding IndicatorCreateCommand}" Margin="2"
|
||||||
|
Content="IndicatorCreate" HorizontalAlignment="Left" />
|
||||||
|
<Label Grid.Row="1" Grid.Column="0" Content="Indicator handle:" Margin="2"/>
|
||||||
|
<TextBox Grid.Row="1" Grid.Column="0" Margin="2" Width="30" PreviewTextInput="NumberValidationTextBox" Text="{Binding TimeSeriesValues.IndicatorHandle}"></TextBox>
|
||||||
|
<Button Grid.Row="1" Grid.Column="1" Command="{Binding IndicatorReleaseCommand}" Margin="2"
|
||||||
|
Content="IndicatorRelease" HorizontalAlignment="Left" />
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<ListBox ItemsSource="{Binding TimeSeriesResults}" />
|
<ListBox Grid.Column="0" ItemsSource="{Binding TimeSeriesResults}" />
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
@@ -397,10 +417,25 @@
|
|||||||
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="Indicators">
|
||||||
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
|
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="Time and Date">
|
||||||
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
|
<Button Command="{Binding TimeCurrentCommand}" Content="TimeCurrent" Margin="2"/>
|
||||||
|
<Button Command="{Binding TimeTradeServerCommand}" Content="TimeTradeServer" Margin="2"/>
|
||||||
|
<Button Command="{Binding TimeLocalCommand}" Content="TimeLocal" Margin="2"/>
|
||||||
|
<Button Command="{Binding TimeGMTCommand}" Content="TimeGMT" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|
||||||
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
<Expander Grid.Row="2" Header="Console" IsExpanded="True">
|
||||||
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="200" ItemsSource="{Binding History}"/>
|
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="180" ItemsSource="{Binding History}"/>
|
||||||
</Expander>
|
</Expander>
|
||||||
|
|
||||||
<StatusBar Grid.Row="3">
|
<StatusBar Grid.Row="3">
|
||||||
|
|||||||
@@ -1,37 +1,32 @@
|
|||||||
using System;
|
using System.Text.RegularExpressions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace MtApi5TestClient
|
namespace MtApi5TestClient
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for MainWindow.xaml
|
/// Interaction logic for MainWindow.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow
|
||||||
{
|
{
|
||||||
ViewModel _vm { get; set; }
|
private ViewModel Vm { get; }
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
_vm = new ViewModel();
|
Vm = new ViewModel();
|
||||||
_MainLayout.DataContext = _vm;
|
_MainLayout.DataContext = Vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
{
|
{
|
||||||
_vm.Close();
|
Vm.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
|
||||||
|
{
|
||||||
|
var regex = new Regex("[^0-9]+");
|
||||||
|
e.Handled = regex.IsMatch(e.Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using MtApi5;
|
using MtApi5;
|
||||||
|
|
||||||
@@ -29,7 +26,7 @@ namespace MtApi5TestClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint Magic
|
public ulong Magic
|
||||||
{
|
{
|
||||||
get { return TradeRequest.Magic; }
|
get { return TradeRequest.Magic; }
|
||||||
set
|
set
|
||||||
@@ -109,7 +106,7 @@ namespace MtApi5TestClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint Deviation
|
public ulong Deviation
|
||||||
{
|
{
|
||||||
get { return TradeRequest.Deviation; }
|
get { return TradeRequest.Deviation; }
|
||||||
set
|
set
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
using System;
|
using MtApi5;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using MtApi5;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace MtApi5TestClient
|
namespace MtApi5TestClient
|
||||||
{
|
{
|
||||||
public class TimeSeriesValueViewModel : INotifyPropertyChanged
|
public class TimeSeriesValueViewModel : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private string _SymbolValue;
|
private string _symbolValue;
|
||||||
public string SymbolValue
|
public string SymbolValue
|
||||||
{
|
{
|
||||||
get { return _SymbolValue; }
|
get { return _symbolValue; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_SymbolValue = value;
|
_symbolValue = value;
|
||||||
OnPropertyChanged("SymbolValue");
|
OnPropertyChanged("SymbolValue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,13 +20,36 @@ namespace MtApi5TestClient
|
|||||||
public int StartPos { get; set; }
|
public int StartPos { get; set; }
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
private int _indicatorHandle;
|
||||||
|
public int IndicatorHandle
|
||||||
|
{
|
||||||
|
get { return _indicatorHandle; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_indicatorHandle = value;
|
||||||
|
OnPropertyChanged("IndicatorHandle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ENUM_INDICATOR _indicatorType = ENUM_INDICATOR.IND_MACD;
|
||||||
|
public ENUM_INDICATOR IndicatorType
|
||||||
|
{
|
||||||
|
get { return _indicatorType; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_indicatorType = value;
|
||||||
|
OnPropertyChanged("IndicatorType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region INotifyPropertyChanged
|
#region INotifyPropertyChanged
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged(string propertyName)
|
protected virtual void OnPropertyChanged(string propertyName)
|
||||||
{
|
{
|
||||||
PropertyChangedEventHandler handler = PropertyChanged;
|
var handler = PropertyChanged;
|
||||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -16,6 +17,13 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand DisconnectCommand { get; private set; }
|
public DelegateCommand DisconnectCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand OrderSendCommand { get; private set; }
|
public DelegateCommand OrderSendCommand { get; private set; }
|
||||||
|
public DelegateCommand OrderCheckCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand HistoryOrderGetIntegerCommand { get; private set; }
|
||||||
|
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
||||||
|
public DelegateCommand HistoryDealGetIntegerCommand { get; private set; }
|
||||||
|
public DelegateCommand HistoryDealGetStringCommand { get; private set; }
|
||||||
|
public DelegateCommand HistoryDealMethodsCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand AccountInfoDoubleCommand { get; private set; }
|
public DelegateCommand AccountInfoDoubleCommand { get; private set; }
|
||||||
public DelegateCommand AccountInfoIntegerCommand { get; private set; }
|
public DelegateCommand AccountInfoIntegerCommand { get; private set; }
|
||||||
@@ -27,6 +35,8 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand CopyHighCommand { get; private set; }
|
public DelegateCommand CopyHighCommand { get; private set; }
|
||||||
public DelegateCommand CopyLowCommand { get; private set; }
|
public DelegateCommand CopyLowCommand { get; private set; }
|
||||||
public DelegateCommand CopyCloseCommand { get; private set; }
|
public DelegateCommand CopyCloseCommand { get; private set; }
|
||||||
|
public DelegateCommand IndicatorCreateCommand { get; private set; }
|
||||||
|
public DelegateCommand IndicatorReleaseCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand CopyTickVolumeCommand { get; private set; }
|
public DelegateCommand CopyTickVolumeCommand { get; private set; }
|
||||||
public DelegateCommand CopyRealVolumeCommand { get; private set; }
|
public DelegateCommand CopyRealVolumeCommand { get; private set; }
|
||||||
@@ -50,6 +60,13 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand PositionOpenCommand { get; private set; }
|
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand PrintCommand { get; private set; }
|
public DelegateCommand PrintCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand iCustomCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand TimeCurrentCommand { get; private set; }
|
||||||
|
public DelegateCommand TimeTradeServerCommand { get; private set; }
|
||||||
|
public DelegateCommand TimeLocalCommand { get; private set; }
|
||||||
|
public DelegateCommand TimeGMTCommand { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@@ -157,6 +174,8 @@ namespace MtApi5TestClient
|
|||||||
_mtApiClient.QuoteAdded += mMtApiClient_QuoteAdded;
|
_mtApiClient.QuoteAdded += mMtApiClient_QuoteAdded;
|
||||||
_mtApiClient.QuoteRemoved += mMtApiClient_QuoteRemoved;
|
_mtApiClient.QuoteRemoved += mMtApiClient_QuoteRemoved;
|
||||||
_mtApiClient.QuoteUpdated += mMtApiClient_QuoteUpdated;
|
_mtApiClient.QuoteUpdated += mMtApiClient_QuoteUpdated;
|
||||||
|
_mtApiClient.OnTradeTransaction += mMtApiClient_OnTradeTransaction;
|
||||||
|
_mtApiClient.OnBookEvent += _mtApiClient_OnBookEvent;
|
||||||
|
|
||||||
_quotesMap = new Dictionary<string, QuoteViewModel>();
|
_quotesMap = new Dictionary<string, QuoteViewModel>();
|
||||||
|
|
||||||
@@ -193,6 +212,13 @@ namespace MtApi5TestClient
|
|||||||
DisconnectCommand = new DelegateCommand(ExecuteDisconnect, CanExecuteDisconnect);
|
DisconnectCommand = new DelegateCommand(ExecuteDisconnect, CanExecuteDisconnect);
|
||||||
|
|
||||||
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
||||||
|
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
|
||||||
|
|
||||||
|
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
|
||||||
|
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
||||||
|
HistoryDealGetIntegerCommand = new DelegateCommand(ExecuteHistoryDealGetInteger);
|
||||||
|
HistoryDealGetStringCommand = new DelegateCommand(ExecuteHistoryDealGetString);
|
||||||
|
HistoryDealMethodsCommand = new DelegateCommand(ExecuteHistoryDealMethods);
|
||||||
|
|
||||||
AccountInfoDoubleCommand = new DelegateCommand(ExecuteAccountInfoDouble);
|
AccountInfoDoubleCommand = new DelegateCommand(ExecuteAccountInfoDouble);
|
||||||
AccountInfoIntegerCommand = new DelegateCommand(ExecuteAccountInfoInteger);
|
AccountInfoIntegerCommand = new DelegateCommand(ExecuteAccountInfoInteger);
|
||||||
@@ -204,6 +230,8 @@ namespace MtApi5TestClient
|
|||||||
CopyHighCommand = new DelegateCommand(ExecuteCopyHigh);
|
CopyHighCommand = new DelegateCommand(ExecuteCopyHigh);
|
||||||
CopyLowCommand = new DelegateCommand(ExecuteCopyLow);
|
CopyLowCommand = new DelegateCommand(ExecuteCopyLow);
|
||||||
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
|
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
|
||||||
|
IndicatorCreateCommand = new DelegateCommand(ExecuteIndicatorCreate);
|
||||||
|
IndicatorReleaseCommand = new DelegateCommand(ExecuteIndicatorRelease);
|
||||||
|
|
||||||
CopyTickVolumeCommand = new DelegateCommand(ExecuteCopyTickVolume);
|
CopyTickVolumeCommand = new DelegateCommand(ExecuteCopyTickVolume);
|
||||||
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
|
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
|
||||||
@@ -227,6 +255,13 @@ namespace MtApi5TestClient
|
|||||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||||
|
|
||||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||||
|
|
||||||
|
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||||
|
|
||||||
|
TimeCurrentCommand = new DelegateCommand(ExecuteTimeCurrent);
|
||||||
|
TimeTradeServerCommand = new DelegateCommand(ExecuteTimeTradeServer);
|
||||||
|
TimeLocalCommand = new DelegateCommand(ExecuteTimeLocal);
|
||||||
|
TimeGMTCommand = new DelegateCommand(ExecuteTimeGMT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanExecuteConnect(object o)
|
private bool CanExecuteConnect(object o)
|
||||||
@@ -259,18 +294,91 @@ namespace MtApi5TestClient
|
|||||||
private async void ExecuteOrderSend(object o)
|
private async void ExecuteOrderSend(object o)
|
||||||
{
|
{
|
||||||
var request = TradeRequest.GetMqlTradeRequest();
|
var request = TradeRequest.GetMqlTradeRequest();
|
||||||
|
MqlTradeResult result = null;
|
||||||
var retVal = await Execute(() =>
|
var retVal = await Execute(() =>
|
||||||
{
|
{
|
||||||
MqlTradeResult result;
|
|
||||||
var ok = _mtApiClient.OrderSend(request, out result);
|
var ok = _mtApiClient.OrderSend(request, out result);
|
||||||
return ok ? result : null;
|
return ok;
|
||||||
});
|
});
|
||||||
|
|
||||||
var message = retVal != null ? $"OrderSend successed. {MqlTradeResultToString(retVal)}" : "OrderSend failed.";
|
var message = retVal ? $"OrderSend: success. {result}" : $"OrderSend: fail. {result}";
|
||||||
AddLog(message);
|
AddLog(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async void ExecuteOrderCheck(object obj)
|
||||||
|
{
|
||||||
|
var request = TradeRequest.GetMqlTradeRequest();
|
||||||
|
MqlTradeCheckResult result = null;
|
||||||
|
var retVal = await Execute(() =>
|
||||||
|
{
|
||||||
|
var ok = _mtApiClient.OrderCheck(request, out result);
|
||||||
|
return ok;
|
||||||
|
});
|
||||||
|
|
||||||
|
var message = retVal ? $"OrderCheck: success. {result}" : $"OrderCheck: fail. {result}";
|
||||||
|
AddLog(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryOrderGetInteger(object o)
|
||||||
|
{
|
||||||
|
const ulong ticket = 12345;
|
||||||
|
const ENUM_ORDER_PROPERTY_INTEGER propertyId = ENUM_ORDER_PROPERTY_INTEGER.ORDER_POSITION_ID;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.HistoryOrderGetInteger(ticket, propertyId));
|
||||||
|
|
||||||
|
AddLog($"HistoryOrderGetInteger: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryDealGetDouble(object o)
|
||||||
|
{
|
||||||
|
const ulong ticket = 12345;
|
||||||
|
const ENUM_DEAL_PROPERTY_DOUBLE propertyId = ENUM_DEAL_PROPERTY_DOUBLE.DEAL_PROFIT;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.HistoryDealGetDouble(ticket, propertyId));
|
||||||
|
|
||||||
|
AddLog($"HistoryDealGetDouble: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryDealGetInteger(object o)
|
||||||
|
{
|
||||||
|
const ulong ticket = 12345;
|
||||||
|
const ENUM_DEAL_PROPERTY_INTEGER propertyId = ENUM_DEAL_PROPERTY_INTEGER.DEAL_TICKET;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.HistoryDealGetInteger(ticket, propertyId));
|
||||||
|
|
||||||
|
AddLog($"HistoryDealGetInteger: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryDealGetString(object o)
|
||||||
|
{
|
||||||
|
const ulong ticket = 12345;
|
||||||
|
const ENUM_DEAL_PROPERTY_STRING propertyId = ENUM_DEAL_PROPERTY_STRING.DEAL_SYMBOL;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.HistoryDealGetString(ticket, propertyId));
|
||||||
|
|
||||||
|
AddLog($"HistoryDealGetString: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryDealMethods(object o)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var posId = await Execute(() => _mtApiClient.PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER.POSITION_IDENTIFIER));
|
||||||
|
var history = await Execute(() => _mtApiClient.HistorySelectByPosition(posId));
|
||||||
|
var historyDealsTotal = await Execute(() => _mtApiClient.HistoryDealsTotal());
|
||||||
|
var histDealTicket = await Execute(() => _mtApiClient.HistoryDealGetTicket(0));
|
||||||
|
var histDealPrice = await Execute(() => _mtApiClient.HistoryDealGetDouble(histDealTicket, ENUM_DEAL_PROPERTY_DOUBLE.DEAL_PRICE));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AddLog(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddLog("ExecuteHistoryDealMethods: success.");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecuteAccountInfoDouble(object o)
|
private async void ExecuteAccountInfoDouble(object o)
|
||||||
{
|
{
|
||||||
var result = await Execute(() => _mtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId));
|
var result = await Execute(() => _mtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId));
|
||||||
@@ -446,6 +554,48 @@ namespace MtApi5TestClient
|
|||||||
AddLog("CopyClose: success");
|
AddLog("CopyClose: success");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteIndicatorCreate(object o)
|
||||||
|
{
|
||||||
|
var parameters = new List<MqlParam>
|
||||||
|
{
|
||||||
|
new MqlParam
|
||||||
|
{
|
||||||
|
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||||
|
IntegerValue = 12
|
||||||
|
},
|
||||||
|
new MqlParam
|
||||||
|
{
|
||||||
|
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||||
|
IntegerValue = 26
|
||||||
|
},
|
||||||
|
new MqlParam
|
||||||
|
{
|
||||||
|
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||||
|
IntegerValue = 9
|
||||||
|
},
|
||||||
|
new MqlParam
|
||||||
|
{
|
||||||
|
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||||
|
IntegerValue = (int)ENUM_APPLIED_PRICE.PRICE_CLOSE
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var retVal = await Execute(() =>
|
||||||
|
_mtApiClient.IndicatorCreate(TimeSeriesValues.SymbolValue,
|
||||||
|
TimeSeriesValues.TimeFrame, TimeSeriesValues.IndicatorType, parameters));
|
||||||
|
|
||||||
|
TimeSeriesValues.IndicatorHandle = retVal;
|
||||||
|
AddLog($"IndicatorCreate [IND_MA]: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteIndicatorRelease(object o)
|
||||||
|
{
|
||||||
|
var indicatorHandle = TimeSeriesValues.IndicatorHandle;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.IndicatorRelease(indicatorHandle));
|
||||||
|
AddLog($"IndicatorRelease [{indicatorHandle}]: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecuteCopyRates(object o)
|
private async void ExecuteCopyRates(object o)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
||||||
@@ -705,14 +855,14 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private async void ExecuteMarketBookAdd(object o)
|
private async void ExecuteMarketBookAdd(object o)
|
||||||
{
|
{
|
||||||
var retVal = await Execute(() => _mtApiClient.MarketBookAdd("CHFJPY"));
|
var retVal = await Execute(() => _mtApiClient.MarketBookAdd("EURUSD"));
|
||||||
AddLog($"MarketBookAdd(CHFJPY): result = {retVal}");
|
AddLog($"MarketBookAdd(EURUSD): result = {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ExecuteMarketBookRelease(object o)
|
private async void ExecuteMarketBookRelease(object o)
|
||||||
{
|
{
|
||||||
var retVal = await Execute(() => _mtApiClient.MarketBookRelease("CHFJPY"));
|
var retVal = await Execute(() => _mtApiClient.MarketBookRelease("EURUSD"));
|
||||||
AddLog($"MarketBookRelease(CHFJPY): result = {retVal}");
|
AddLog($"MarketBookRelease(EURUSD): result = {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ExecuteMarketBookGet(object o)
|
private async void ExecuteMarketBookGet(object o)
|
||||||
@@ -730,13 +880,11 @@ namespace MtApi5TestClient
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddLog("MarketBookGet(EURUSD): success");
|
AddLog($"MarketBookGet(EURUSD): success. Count = {result.Length}");
|
||||||
|
|
||||||
for (var i = 0; i < result.Length; i++)
|
for (var i = 0; i < result.Length; i++)
|
||||||
{
|
{
|
||||||
AddLog($"MarketBookGet: book[{i}].price = {result[i].price}");
|
AddLog($"MarketBookGet: [{i}] - {result[i].price} | {result[i].volume} | {result[i].type}");
|
||||||
AddLog($"MarketBookGet: book[{i}].price = {result[i].volume}");
|
|
||||||
AddLog($"MarketBookGet: book[{i}].price = {result[i].type}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,13 +893,14 @@ namespace MtApi5TestClient
|
|||||||
const string symbol = "EURUSD";
|
const string symbol = "EURUSD";
|
||||||
const ENUM_ORDER_TYPE orderType = ENUM_ORDER_TYPE.ORDER_TYPE_BUY;
|
const ENUM_ORDER_TYPE orderType = ENUM_ORDER_TYPE.ORDER_TYPE_BUY;
|
||||||
const double volume = 0.1;
|
const double volume = 0.1;
|
||||||
const double price = 1.013;
|
const double price = 1.18129;
|
||||||
const double sl = 1.00;
|
const double sl = 1.1811;
|
||||||
const double tp = 1.020;
|
const double tp = 1.1814;
|
||||||
const string comment = "Test PositionOpen";
|
const string comment = "Test PositionOpen";
|
||||||
|
MqlTradeResult tradeResult = null;
|
||||||
|
|
||||||
var retVal = await Execute (() => _mtApiClient.PositionOpen(symbol, orderType, volume, price, sl, tp, comment));
|
var retVal = await Execute (() => _mtApiClient.PositionOpen(symbol, orderType, volume, price, sl, tp, comment, out tradeResult));
|
||||||
AddLog($"PositionOpen: symbol EURUSD result = {retVal}");
|
AddLog($"PositionOpen: symbol EURUSD retVal = {retVal}, result = {tradeResult}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ExecutePrint(object obj)
|
private async void ExecutePrint(object obj)
|
||||||
@@ -762,6 +911,41 @@ namespace MtApi5TestClient
|
|||||||
AddLog($"Print: message print in MetaTrader - {retVal}");
|
AddLog($"Print: message print in MetaTrader - {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteICustom(object o)
|
||||||
|
{
|
||||||
|
const string symbol = "EURUSD";
|
||||||
|
const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
|
||||||
|
const string name = @"Examples\Custom Moving Average";
|
||||||
|
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.iCustom(symbol, timeframe, name, parameters));
|
||||||
|
AddLog($"Custom Moving Average: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeCurrent(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
|
||||||
|
AddLog($"TimeCurrent: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeTradeServer(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeTradeServer());
|
||||||
|
AddLog($"TimeTradeServer: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeLocal(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeLocal());
|
||||||
|
AddLog($"TimeLocal: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeGMT(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeGMT());
|
||||||
|
AddLog($"TimeGMT: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
private static void RunOnUiThread(Action action)
|
private static void RunOnUiThread(Action action)
|
||||||
{
|
{
|
||||||
Application.Current?.Dispatcher.Invoke(action);
|
Application.Current?.Dispatcher.Invoke(action);
|
||||||
@@ -826,6 +1010,16 @@ namespace MtApi5TestClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void mMtApiClient_OnTradeTransaction(object sender, Mt5TradeTransactionEventArgs e)
|
||||||
|
{
|
||||||
|
AddLog($"OnTradeTransaction: ExpertHandle = {e.ExpertHandle}.{Environment.NewLine}Transaction = {e.Trans}.{Environment.NewLine}Request = {e.Request}.{Environment.NewLine}Result = {e.Result}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _mtApiClient_OnBookEvent(object sender, Mt5BookEventArgs e)
|
||||||
|
{
|
||||||
|
AddLog($"OnBookEvent: ExpertHandle = {e.ExpertHandle}, Symbol = {e.Symbol}");
|
||||||
|
}
|
||||||
|
|
||||||
private void AddQuote(Mt5Quote quote)
|
private void AddQuote(Mt5Quote quote)
|
||||||
{
|
{
|
||||||
if (quote == null)
|
if (quote == null)
|
||||||
@@ -884,20 +1078,6 @@ namespace MtApi5TestClient
|
|||||||
Quotes.Clear();
|
Quotes.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string MqlTradeResultToString(MqlTradeResult result)
|
|
||||||
{
|
|
||||||
return result != null ?
|
|
||||||
"Retcode = " + result.Retcode + ";"
|
|
||||||
+ " Comment = " + result.Comment + ";"
|
|
||||||
+ " Order = " + result.Order + ";"
|
|
||||||
+ " Volume = " + result.Volume + ";"
|
|
||||||
+ " Price = " + result.Price + ";"
|
|
||||||
+ " Deal = " + result.Deal + ";"
|
|
||||||
+ " Request_id = " + result.Request_id + ";"
|
|
||||||
+ " Bid = " + result.Bid + ";"
|
|
||||||
+ " Ask = " + result.Ask + ";" : string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnSelectedQuoteChanged()
|
private void OnSelectedQuoteChanged()
|
||||||
{
|
{
|
||||||
if (SelectedQuote == null) return;
|
if (SelectedQuote == null) return;
|
||||||
@@ -915,6 +1095,10 @@ namespace MtApi5TestClient
|
|||||||
{
|
{
|
||||||
result = func();
|
result = func();
|
||||||
}
|
}
|
||||||
|
catch (ExecutionException ex)
|
||||||
|
{
|
||||||
|
AddLog($"Exception: {ex.ErrorCode} - {ex.Message}");
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AddLog($"Exception: {ex.Message}");
|
AddLog($"Exception: {ex.Message}");
|
||||||
|
|||||||
+826
-247
File diff suppressed because it is too large
Load Diff
@@ -33,12 +33,17 @@ namespace TestApiClientUI
|
|||||||
comboBox8.DataSource = Enum.GetNames(typeof(MarketInfoModeType));
|
comboBox8.DataSource = Enum.GetNames(typeof(MarketInfoModeType));
|
||||||
comboBox9.DataSource = Enum.GetNames(typeof(EnumTerminalInfoInteger));
|
comboBox9.DataSource = Enum.GetNames(typeof(EnumTerminalInfoInteger));
|
||||||
comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble));
|
comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble));
|
||||||
|
comboBox11.DataSource = Enum.GetNames(typeof(EnumObject));
|
||||||
|
comboBox12.DataSource = Enum.GetNames(typeof(ENUM_TERMINAL_INFO_STRING));
|
||||||
|
comboBoxAccountInfoCmd.DataSource = Enum.GetNames(typeof(TradeOperation));
|
||||||
|
|
||||||
_apiClient.QuoteUpdated += apiClient_QuoteUpdated;
|
_apiClient.QuoteUpdated += apiClient_QuoteUpdated;
|
||||||
|
_apiClient.QuoteUpdate += _apiClient_QuoteUpdate;
|
||||||
_apiClient.QuoteAdded += apiClient_QuoteAdded;
|
_apiClient.QuoteAdded += apiClient_QuoteAdded;
|
||||||
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
|
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
|
||||||
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
|
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
|
||||||
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
||||||
|
_apiClient.OnChartEvent += _apiClient_OnChartEvent;
|
||||||
|
|
||||||
InitOrderCommandsGroup();
|
InitOrderCommandsGroup();
|
||||||
|
|
||||||
@@ -47,6 +52,8 @@ namespace TestApiClientUI
|
|||||||
comboBox3.SelectedIndex = 0;
|
comboBox3.SelectedIndex = 0;
|
||||||
comboBox4.SelectedIndex = 0;
|
comboBox4.SelectedIndex = 0;
|
||||||
comboBox5.SelectedIndex = 0;
|
comboBox5.SelectedIndex = 0;
|
||||||
|
comboBox11.SelectedIndex = 0;
|
||||||
|
comboBoxAccountInfoCmd.SelectedIndex = 0;
|
||||||
|
|
||||||
_timerTradeMonitor = new TimerTradeMonitor(_apiClient) { Interval = 10000 }; // 10 sec
|
_timerTradeMonitor = new TimerTradeMonitor(_apiClient) { Interval = 10000 }; // 10 sec
|
||||||
_timerTradeMonitor.AvailabilityOrdersChanged += _tradeMonitor_AvailabilityOrdersChanged;
|
_timerTradeMonitor.AvailabilityOrdersChanged += _tradeMonitor_AvailabilityOrdersChanged;
|
||||||
@@ -112,18 +119,32 @@ namespace TestApiClientUI
|
|||||||
|
|
||||||
private void apiClient_QuoteRemoved(object sender, MtQuoteEventArgs e)
|
private void apiClient_QuoteRemoved(object sender, MtQuoteEventArgs e)
|
||||||
{
|
{
|
||||||
RunOnUiThread(() => RemoveQuote(e.Quote) );
|
if (e.Quote != null)
|
||||||
|
{
|
||||||
|
RunOnUiThread(() => RemoveQuote(e.Quote));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void apiClient_QuoteAdded(object sender, MtQuoteEventArgs e)
|
private void apiClient_QuoteAdded(object sender, MtQuoteEventArgs e)
|
||||||
{
|
{
|
||||||
RunOnUiThread(() => AddNewQuote(e.Quote));
|
if (e.Quote != null)
|
||||||
|
{
|
||||||
|
RunOnUiThread(() => AddNewQuote(e.Quote));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
||||||
{
|
{
|
||||||
var msg =
|
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);
|
Console.WriteLine(msg);
|
||||||
PrintLog(msg);
|
PrintLog(msg);
|
||||||
}
|
}
|
||||||
@@ -131,72 +152,52 @@ namespace TestApiClientUI
|
|||||||
private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
|
private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
|
||||||
{
|
{
|
||||||
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask);
|
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _apiClient_QuoteUpdate(object sender, MtQuoteEventArgs e)
|
||||||
|
{
|
||||||
//if UI of quite is busy we are skipping this update
|
//if UI of quite is busy we are skipping this update
|
||||||
if (_isUiQuoteUpdateReady)
|
if (_isUiQuoteUpdateReady)
|
||||||
{
|
{
|
||||||
RunOnUiThread(() => ChangeQuote(symbol, bid, ask));
|
RunOnUiThread(() => ChangeQuote(e.Quote));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddNewQuote(MtQuote quote)
|
private void AddNewQuote(MtQuote quote)
|
||||||
{
|
{
|
||||||
if (quote == null)
|
var key = quote.ExpertHandle.ToString();
|
||||||
return;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(quote.Instrument) == false
|
if (listViewQuotes.Items.ContainsKey(key) == false)
|
||||||
&& listViewQuotes.Items.ContainsKey(quote.Instrument) == false)
|
|
||||||
{
|
{
|
||||||
var item = new ListViewItem(quote.Instrument) { Name = quote.Instrument };
|
var item = new ListViewItem(quote.Instrument) { Name = key };
|
||||||
item.SubItems.Add(quote.Bid.ToString(CultureInfo.CurrentCulture));
|
item.SubItems.Add(quote.Bid.ToString(CultureInfo.CurrentCulture));
|
||||||
item.SubItems.Add(quote.Ask.ToString(CultureInfo.CurrentCulture));
|
item.SubItems.Add(quote.Ask.ToString(CultureInfo.CurrentCulture));
|
||||||
item.SubItems.Add("1");
|
item.SubItems.Add(key);
|
||||||
listViewQuotes.Items.Add(item);
|
listViewQuotes.Items.Add(item);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
var item = listViewQuotes.Items[quote.Instrument];
|
|
||||||
int feedCount;
|
|
||||||
int.TryParse(item.SubItems[3].Text, out feedCount);
|
|
||||||
feedCount++;
|
|
||||||
item.SubItems[3].Text = feedCount.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveQuote(MtQuote quote)
|
private void RemoveQuote(MtQuote quote)
|
||||||
{
|
{
|
||||||
if (quote == null)
|
var key = quote.ExpertHandle.ToString();
|
||||||
return;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(quote.Instrument) == false
|
if (listViewQuotes.Items.ContainsKey(key))
|
||||||
&& listViewQuotes.Items.ContainsKey(quote.Instrument))
|
|
||||||
{
|
{
|
||||||
var item = listViewQuotes.Items[quote.Instrument];
|
listViewQuotes.Items.RemoveByKey(key);
|
||||||
int feedCount;
|
|
||||||
int.TryParse(item.SubItems[3].Text, out feedCount);
|
|
||||||
feedCount--;
|
|
||||||
if (feedCount <= 0)
|
|
||||||
{
|
|
||||||
listViewQuotes.Items.RemoveByKey(quote.Instrument);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item.SubItems[3].Text = feedCount.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeQuote(string symbol, double bid, double ask)
|
private void ChangeQuote(MtQuote quote)
|
||||||
{
|
{
|
||||||
_isUiQuoteUpdateReady = false;
|
_isUiQuoteUpdateReady = false;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(symbol) == false)
|
var key = quote.ExpertHandle.ToString();
|
||||||
|
|
||||||
|
if (listViewQuotes.Items.ContainsKey(key))
|
||||||
{
|
{
|
||||||
if (listViewQuotes.Items.ContainsKey(symbol))
|
var item = listViewQuotes.Items[key];
|
||||||
{
|
item.SubItems[1].Text = quote.Bid.ToString(CultureInfo.CurrentCulture);
|
||||||
var item = listViewQuotes.Items[symbol];
|
item.SubItems[2].Text = quote.Ask.ToString(CultureInfo.CurrentCulture);
|
||||||
item.SubItems[1].Text = bid.ToString(CultureInfo.CurrentCulture);
|
|
||||||
item.SubItems[2].Text = ask.ToString(CultureInfo.CurrentCulture);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_isUiQuoteUpdateReady = true;
|
_isUiQuoteUpdateReady = true;
|
||||||
@@ -256,6 +257,12 @@ namespace TestApiClientUI
|
|||||||
textBoxOrderSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
textBoxOrderSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
||||||
txtMarketInfoSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
txtMarketInfoSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
||||||
textBoxSelectedSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
textBoxSelectedSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
||||||
|
textBoxAccountInfoSymbol.Text = listViewQuotes.SelectedItems[0].Text;
|
||||||
|
|
||||||
|
if (checkBox2.Checked)
|
||||||
|
{
|
||||||
|
_apiClient.ExecutorHandle = int.Parse(listViewQuotes.SelectedItems[0].SubItems[3].Text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,206 +533,6 @@ namespace TestApiClientUI
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button3_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
switch (comboBoxStatusCommand.SelectedIndex)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
var result = _apiClient.GetLastError();
|
|
||||||
PrintLog($"GetLastError result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsConnected();
|
|
||||||
PrintLog($"IsConnected result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsDemo();
|
|
||||||
PrintLog($"IsDemo result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsDllsAllowed();
|
|
||||||
PrintLog($"IsDllsAllowed result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsExpertEnabled();
|
|
||||||
PrintLog($"IsExpertEnabled result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsLibrariesAllowed();
|
|
||||||
PrintLog($"IsLibrariesAllowed result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsOptimization();
|
|
||||||
PrintLog($"IsOptimization result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsStopped();
|
|
||||||
PrintLog($"IsStopped result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsTesting();
|
|
||||||
PrintLog($"IsTesting result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsTradeAllowed();
|
|
||||||
PrintLog($"IsTradeAllowed result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsTradeContextBusy();
|
|
||||||
PrintLog($"IsTradeContextBusy result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
{
|
|
||||||
var result = _apiClient.IsVisualMode();
|
|
||||||
PrintLog($"IsVisualMode result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
{
|
|
||||||
var result = _apiClient.UninitializeReason();
|
|
||||||
PrintLog($"UninitializeReason result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 13:
|
|
||||||
{
|
|
||||||
int errorCode;
|
|
||||||
int.TryParse(textBoxErrorCode.Text, out errorCode);
|
|
||||||
var result = _apiClient.ErrorDescription(errorCode);
|
|
||||||
PrintLog($"ErrorDescription result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void button4_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
switch (listBoxAccountInfo.SelectedIndex)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountBalance();
|
|
||||||
PrintLog($"AccountBalance result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountCredit();
|
|
||||||
PrintLog($"AccountCredit result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountCompany();
|
|
||||||
PrintLog($"AccountCompany result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountCurrency();
|
|
||||||
PrintLog($"AccountCurrency result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountEquity();
|
|
||||||
PrintLog($"AccountEquity result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountFreeMargin();
|
|
||||||
PrintLog($"AccountFreeMargin result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountFreeMarginCheck(textBoxAccountInfoSymbol.Text, (TradeOperation)comboBoxAccountInfoCmd.SelectedIndex, int.Parse(textBoxAccountInfoVolume.Text));
|
|
||||||
PrintLog($"AccountFreeMarginCheck result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountFreeMarginMode();
|
|
||||||
PrintLog($"AccountFreeMarginMode result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountLeverage();
|
|
||||||
PrintLog($"AccountLeverage result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountMargin();
|
|
||||||
PrintLog($"AccountMargin result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountName();
|
|
||||||
PrintLog($"AccountName result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountNumber();
|
|
||||||
PrintLog($"AccountNumber result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountProfit();
|
|
||||||
PrintLog($"AccountProfit result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 13:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountServer();
|
|
||||||
PrintLog($"AccountServer result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 14:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountStopoutLevel();
|
|
||||||
PrintLog($"AccountStopoutLevel result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 15:
|
|
||||||
{
|
|
||||||
var result = _apiClient.AccountStopoutMode();
|
|
||||||
PrintLog($"AccountStopoutMode result: {result}");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//MarketInfo
|
//MarketInfo
|
||||||
private async void button5_Click(object sender, EventArgs e)
|
private async void button5_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@@ -753,13 +560,13 @@ namespace TestApiClientUI
|
|||||||
|
|
||||||
Console.WriteLine($"Finished time: {DateTime.Now}");
|
Console.WriteLine($"Finished time: {DateTime.Now}");
|
||||||
|
|
||||||
using (var file = new System.IO.StreamWriter($@"{System.IO.Path.GetTempPath()}\MtApi\test.txt"))
|
//using (var file = new System.IO.StreamWriter($@"{System.IO.Path.GetTempPath()}\MtApi\test.txt"))
|
||||||
{
|
//{
|
||||||
foreach (var value in openPriceList)
|
// foreach (var value in openPriceList)
|
||||||
{
|
// {
|
||||||
file.WriteLine(value);
|
// file.WriteLine(value);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button7_Click(object sender, EventArgs e)
|
private void button7_Click(object sender, EventArgs e)
|
||||||
@@ -809,18 +616,28 @@ namespace TestApiClientUI
|
|||||||
listBoxProceHistory.DataSource = items;
|
listBoxProceHistory.DataSource = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TimeCurrent
|
||||||
private void button13_Click(object sender, EventArgs e)
|
private void button13_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var retVal = _apiClient.TimeCurrent();
|
var retVal = _apiClient.TimeCurrent();
|
||||||
PrintLog($"TimeCurrent result: {retVal}");
|
PrintLog($"TimeCurrent result: {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TimeLocal
|
||||||
private void button14_Click(object sender, EventArgs e)
|
private void button14_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var retVal = _apiClient.TimeLocal();
|
var retVal = _apiClient.TimeLocal();
|
||||||
PrintLog($"TimeLocal result: {retVal}");
|
PrintLog($"TimeLocal result: {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TimeGMT
|
||||||
|
private void button73_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var retVal = _apiClient.TimeGMT();
|
||||||
|
PrintLog($"TimeGMT result: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//RefreshRates
|
||||||
private void buttonRefreshRates_Click(object sender, EventArgs e)
|
private void buttonRefreshRates_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var retVal = _apiClient.RefreshRates();
|
var retVal = _apiClient.RefreshRates();
|
||||||
@@ -832,9 +649,9 @@ namespace TestApiClientUI
|
|||||||
listBoxEventLog.Items.Clear();
|
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);
|
var result = default(TResult);
|
||||||
try
|
try
|
||||||
@@ -854,9 +671,30 @@ 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
|
//OrderSend
|
||||||
private async void button1_Click(object sender, EventArgs e)
|
private async void button1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var ticket = -1;
|
||||||
|
|
||||||
var symbol = textBoxOrderSymbol.Text;
|
var symbol = textBoxOrderSymbol.Text;
|
||||||
|
|
||||||
var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex;
|
var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex;
|
||||||
@@ -877,28 +715,43 @@ namespace TestApiClientUI
|
|||||||
|
|
||||||
var comment = textBoxOrderComment.Text;
|
var comment = textBoxOrderComment.Text;
|
||||||
|
|
||||||
int magic;
|
if (string.IsNullOrEmpty(comment))
|
||||||
int.TryParse(textBoxOrderMagic.Text, out magic);
|
|
||||||
|
|
||||||
var expiration = DateTime.Now;
|
|
||||||
|
|
||||||
Color arrowColor;
|
|
||||||
switch (comboBoxOrderColor.SelectedIndex)
|
|
||||||
{
|
{
|
||||||
case 0:
|
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit));
|
||||||
arrowColor = Color.Green;
|
}
|
||||||
break;
|
else
|
||||||
case 1:
|
{
|
||||||
arrowColor = Color.Blue;
|
int magic;
|
||||||
break;
|
if (!int.TryParse(textBoxOrderMagic.Text, out magic))
|
||||||
case 2:
|
{
|
||||||
arrowColor = Color.Red;
|
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment));
|
||||||
break;
|
}
|
||||||
default:
|
else
|
||||||
return;
|
{
|
||||||
|
if (comboBoxOrderColor.SelectedIndex < 0 || comboBoxOrderColor.SelectedIndex > 2)
|
||||||
|
{
|
||||||
|
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var expiration = DateTime.Now.AddDays(1);
|
||||||
|
Color arrowColor = Color.White;
|
||||||
|
switch (comboBoxOrderColor.SelectedIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
arrowColor = Color.Green;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
arrowColor = Color.Blue;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
arrowColor = Color.Red;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));
|
|
||||||
|
|
||||||
PrintLog($"Sended order result: ticket = {ticket}");
|
PrintLog($"Sended order result: ticket = {ticket}");
|
||||||
}
|
}
|
||||||
@@ -1286,5 +1139,365 @@ namespace TestApiClientUI
|
|||||||
var result = await Execute(() => _apiClient.TerminalInfoDouble(propId));
|
var result = await Execute(() => _apiClient.TerminalInfoDouble(propId));
|
||||||
PrintLog($"TerminalInfoDouble: result = {result}");
|
PrintLog($"TerminalInfoDouble: result = {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TerminalInfoString
|
||||||
|
private async void button72_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ENUM_TERMINAL_INFO_STRING propId;
|
||||||
|
Enum.TryParse(comboBox12.Text, out propId);
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.TerminalInfoString(propId));
|
||||||
|
PrintLog($"TerminalInfoString: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var checkbox = sender as CheckBox;
|
||||||
|
if (checkbox == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int expertHandle = 0;
|
||||||
|
if (checkbox.Checked)
|
||||||
|
{
|
||||||
|
if (listViewQuotes.SelectedItems.Count > 0)
|
||||||
|
{
|
||||||
|
expertHandle = int.Parse(listViewQuotes.SelectedItems[0].SubItems[3].Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_apiClient.ExecutorHandle = expertHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetLastError
|
||||||
|
private async void button40_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.GetLastError);
|
||||||
|
PrintLog($"GetLastError: result = {result}");
|
||||||
|
RunOnUiThread(() => { textBoxErrorCode.Text = result.ToString(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
//ErrorDescription
|
||||||
|
private async void button39_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxErrorCode.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Error code is not defined!");
|
||||||
|
textBoxErrorCode.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int errorCode;
|
||||||
|
if (int.TryParse(textBoxErrorCode.Text, out errorCode) == false)
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Failed to parse error code!");
|
||||||
|
textBoxErrorCode.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.ErrorDescription(errorCode));
|
||||||
|
PrintLog($"ErrorDescription: code = {errorCode}, description = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsConnected
|
||||||
|
private async void button41_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
PrintLog($"IsDemo: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsDllsAllowed
|
||||||
|
private async void button43_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
PrintLog($"IsExpertEnabled: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsLibrariesAllowed
|
||||||
|
private async void button45_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
PrintLog($"IsOptimization: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsStopped
|
||||||
|
private async void button47_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
PrintLog($"IsTesting: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsTradeAllowed
|
||||||
|
private async void button49_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
PrintLog($"IsTradeContextBusy: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsVisualMode
|
||||||
|
private async void button51_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
PrintLog($"UninitializeReason: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountBalance
|
||||||
|
private async void button3_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountBalance);
|
||||||
|
PrintLog($"AccountBalance result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountCredit
|
||||||
|
private async void button53_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountCredit);
|
||||||
|
PrintLog($"AccountCredit result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountCompany
|
||||||
|
private async void button54_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountCompany);
|
||||||
|
PrintLog($"AccountCompany result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountCurrency
|
||||||
|
private async void button55_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountCurrency);
|
||||||
|
PrintLog($"AccountCurrency result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountEquity
|
||||||
|
private async void button56_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountEquity);
|
||||||
|
PrintLog($"AccountEquity result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountFreeMargin
|
||||||
|
private async void button57_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountFreeMargin);
|
||||||
|
PrintLog($"AccountFreeMargin result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountFreeMarginCheck
|
||||||
|
private async void button58_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var symbol = textBoxAccountInfoSymbol.Text;
|
||||||
|
if (string.IsNullOrEmpty(symbol))
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Symbol is not defined!");
|
||||||
|
textBoxAccountInfoSymbol.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double volume;
|
||||||
|
if (double.TryParse(textBoxAccountInfoVolume.Text, out volume) == false)
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Failed to parse volume value!");
|
||||||
|
textBoxAccountInfoVolume.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TradeOperation cmd;
|
||||||
|
Enum.TryParse(comboBoxAccountInfoCmd.Text, out cmd);
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.AccountFreeMarginCheck(symbol, cmd, volume));
|
||||||
|
PrintLog($"AccountFreeMarginCheck result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountFreeMarginMode
|
||||||
|
private async void button59_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountFreeMarginMode);
|
||||||
|
PrintLog($"AccountFreeMarginMode result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountLeverage
|
||||||
|
private async void button60_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountLeverage);
|
||||||
|
PrintLog($"AccountLeverage result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountMargin
|
||||||
|
private async void button61_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountMargin);
|
||||||
|
PrintLog($"AccountMargin result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountName
|
||||||
|
private async void button62_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountName);
|
||||||
|
PrintLog($"AccountName result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountNumber
|
||||||
|
private async void button63_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountNumber);
|
||||||
|
PrintLog($"AccountNumber result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountProfit
|
||||||
|
private async void button64_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountProfit);
|
||||||
|
PrintLog($"AccountProfit result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountServer
|
||||||
|
private async void button65_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountServer);
|
||||||
|
PrintLog($"AccountServer result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountStopoutLevel
|
||||||
|
private async void button66_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var result = await Execute(_apiClient.AccountStopoutLevel);
|
||||||
|
PrintLog($"AccountStopoutLevel result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AccountStopoutMode
|
||||||
|
private async void button67_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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}");
|
||||||
|
RunOnUiThread(() => textBoxChartId.Text = result.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//ChartRedraw
|
||||||
|
private async void button38_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Execute(() => _apiClient.ChartRedraw());
|
||||||
|
PrintLog($"ChartRedraw: called.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//ObjectCreate
|
||||||
|
private async void button4_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
const long chartId = 0;
|
||||||
|
const string objectName = "label_object";
|
||||||
|
EnumObject objectType;
|
||||||
|
Enum.TryParse(comboBox11.Text, out objectType);
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.ObjectCreate(chartId, objectName, objectType, 0, null, 0));
|
||||||
|
PrintLog($"ObjectCreate result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//ObjectName
|
||||||
|
private async void button68_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
const long chartId = 0;
|
||||||
|
const int objectIndex = 0;
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.ObjectName(chartId, objectIndex));
|
||||||
|
PrintLog($"ObjectName result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button69_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_apiClient.UnlockTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void button70_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var login = textBoxAccountLogin.Text;
|
||||||
|
var password = textBoxAccountPassword.Text;
|
||||||
|
var host = textBoxAccountHost.Text;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(login))
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Login is not defined!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
textBoxAccountLogin.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Password is not defined!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
textBoxAccountPassword.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(host))
|
||||||
|
{
|
||||||
|
MessageBox.Show(@"Host is not defined!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
textBoxAccountHost.Focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.ChangeAccount(login, password, host));
|
||||||
|
PrintLog($"ChangeAccount result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//iBarShift
|
||||||
|
private async void button71_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
const string symbol = "EURUSD";
|
||||||
|
const ChartPeriod timeframe = ChartPeriod.PERIOD_D1;
|
||||||
|
|
||||||
|
var time1 = _apiClient.TimeCurrent();
|
||||||
|
var time2 = _apiClient.iTime(symbol, timeframe, 5);
|
||||||
|
|
||||||
|
var result1 = await Execute(() => _apiClient.iBarShift(symbol, timeframe, time1, true));
|
||||||
|
var result2 = await Execute(() => _apiClient.iBarShift(symbol, timeframe, time2, true));
|
||||||
|
|
||||||
|
PrintLog($"iBarShift result1 = {result1}, time = {time1}");
|
||||||
|
PrintLog($"iBarShift result2 = {result2}, time = {time2}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user