Added function SymbolInfoInteger into MtApi (MT4). Added function sendLongResponse into library MTConnector

This commit is contained in:
DW
2016-11-01 12:49:39 +02:00
parent 834b0af430
commit 09b72fc64d
8 changed files with 268 additions and 183 deletions
+183 -169
View File
@@ -19,56 +19,56 @@ using namespace System::Diagnostics;
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);
memcpy(dest, wch, wcslen(wch) * sizeof(wchar_t)); memcpy(dest, wch, wcslen(wch) * sizeof(wchar_t));
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) int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
{ {
try try
{ {
MT4Handler^ mtHandler = gcnew MT4Handler(); MT4Handler^ mtHandler = gcnew MT4Handler();
MtServerInstance::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHandler); 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); Debug::WriteLine("[ERROR] MTConnector:initExpert(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall deinitExpert(int expertHandle, wchar_t* err) int _stdcall deinitExpert(int expertHandle, wchar_t* err)
{ {
try try
{ {
MtServerInstance::GetInstance()->DeinitExpert(expertHandle); MtServerInstance::GetInstance()->DeinitExpert(expertHandle);
} }
catch (Exception^ e) catch (Exception^ e)
{ {
convertSystemString(err, e->Message); convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MTConnector:deinitExpert(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:deinitExpert(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err) int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
{ {
try try
{ {
MtServerInstance::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask); MtServerInstance::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
} }
catch (Exception^ e) catch (Exception^ e)
{ {
convertSystemString(err, e->Message); convertSystemString(err, e->Message);
Debug::WriteLine("[ERROR] MTConnector:updateQuote(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:updateQuote(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
@@ -89,185 +89,199 @@ int _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_
int _stdcall sendIntResponse(int expertHandle, int response) int _stdcall sendIntResponse(int expertHandle, int response)
{ {
try try
{ {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response)); MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendIntResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendIntResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall sendBooleanResponse(int expertHandle, int response) int _stdcall sendBooleanResponse(int expertHandle, int response)
{ {
try try
{ {
bool value = (response != 0) ? true : false; bool value = (response != 0) ? true : false;
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value)); MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendBooleanResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendBooleanResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall sendDoubleResponse(int expertHandle, double response) int _stdcall sendDoubleResponse(int expertHandle, double response)
{ {
try try
{ {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response)); MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendDoubleResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendDoubleResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall sendStringResponse(int expertHandle, wchar_t* response) int _stdcall sendStringResponse(int expertHandle, wchar_t* response)
{ {
try try
{ {
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response))); MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendStringResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendStringResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall sendVoidResponse(int expertHandle) int _stdcall sendVoidResponse(int expertHandle)
{ {
try try
{ {
MtServerInstance::GetInstance()->SendResponse(expertHandle, nullptr); MtServerInstance::GetInstance()->SendResponse(expertHandle, nullptr);
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendVoidResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendVoidResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size) int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size)
{ {
try try
{ {
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];
} }
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list)); MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendDoubleArrayResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendDoubleArrayResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size) int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size)
{ {
try try
{ {
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];
} }
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list)); MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:sendIntArrayResponse(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:sendIntArrayResponse(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
}
int _stdcall sendLongResponse(int expertHandle, __int64 response)
{
try
{
MtServerInstance::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
}
catch (Exception^ e)
{
Debug::WriteLine("[ERROR] MTConnector:sendLongResponse(): " + e->Message);
return 0;
}
return 1;
} }
int _stdcall getCommandType(int expertHandle, int* res) int _stdcall getCommandType(int expertHandle, int* res)
{ {
try try
{ {
*res = MtServerInstance::GetInstance()->GetCommandType(expertHandle); *res = MtServerInstance::GetInstance()->GetCommandType(expertHandle);
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:getCommandType(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:getCommandType(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall getIntValue(int expertHandle, int paramIndex, int* res) int _stdcall getIntValue(int expertHandle, int paramIndex, int* res)
{ {
try try
{ {
*res = (int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex); *res = (int)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:getIntValue(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:getIntValue(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res) int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res)
{ {
try try
{ {
*res = (double)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex); *res = (double)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:getDoubleValue(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:getDoubleValue(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res) int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res)
{ {
try try
{ {
convertSystemString(res, (String^)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex)); convertSystemString(res, (String^)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MTConnector:getStringValue(): " + e->Message); Debug::WriteLine("[ERROR] MTConnector:getStringValue(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res) int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
{ {
try try
{ {
bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex); bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
*res = val == true ? 1 : 0; *res = val == true ? 1 : 0;
} }
catch (Exception^ e) catch (Exception^ e)
{ {
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message); Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
return 0; return 0;
} }
return 1; return 1;
} }
+14 -13
View File
@@ -3,16 +3,17 @@ LIBRARY MTConnector
EXPORTS initExpert EXPORTS initExpert
deinitExpert deinitExpert
updateQuote updateQuote
sendEvent sendEvent
sendIntResponse sendIntResponse
sendBooleanResponse sendBooleanResponse
sendDoubleResponse sendDoubleResponse
sendStringResponse sendStringResponse
sendVoidResponse sendVoidResponse
sendDoubleArrayResponse sendDoubleArrayResponse
sendIntArrayResponse sendIntArrayResponse
getCommandType sendLongResponse
getIntValue getCommandType
getDoubleValue getIntValue
getStringValue getDoubleValue
getBooleanValue getStringValue
getBooleanValue
+31
View File
@@ -0,0 +1,31 @@
namespace MtApi
{
//MQL4: ENUM_SYMBOL_INFO_INTEGER
public enum EnumSymbolInfoInteger
{
SYMBOL_SELECT = 0,
SYMBOL_VISIBLE = 76,
SYMBOL_SESSION_DEALS = 56,
SYMBOL_SESSION_BUY_ORDERS = 60,
SYMBOL_SESSION_SELL_ORDERS = 62,
SYMBOL_VOLUME = 10,
SYMBOL_VOLUMEHIGH = 11,
SYMBOL_VOLUMELOW = 12,
SYMBOL_TIME = 15,
SYMBOL_DIGITS = 17,
SYMBOL_SPREAD = 18,
SYMBOL_SPREAD_FLOAT = 41,
SYMBOL_TRADE_CALC_MODE = 29,
SYMBOL_TRADE_MODE = 30,
SYMBOL_START_TIME = 51,
SYMBOL_EXPIRATION_TIME = 52,
SYMBOL_TRADE_STOPS_LEVEL = 31,
SYMBOL_TRADE_FREEZE_LEVEL = 32,
SYMBOL_TRADE_EXEMODE = 33,
SYMBOL_SWAP_MODE = 37,
SYMBOL_SWAP_ROLLOVER3DAYS = 40,
SYMBOL_EXPIRATION_MODE = 49,
SYMBOL_FILLING_MODE = 50,
SYMBOL_ORDER_MODE = 71
}
}
+1
View File
@@ -59,6 +59,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ChartPeriod.cs" /> <Compile Include="ChartPeriod.cs" />
<Compile Include="EnumSymbolInfoInteger.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" /> <Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
<Compile Include="MqlRates.cs" /> <Compile Include="MqlRates.cs" />
+37
View File
@@ -659,23 +659,60 @@ namespace MtApi
#endregion #endregion
#region Symbols #region Symbols
///<summary>
///Returns the number of available (selected in Market Watch or all) symbols.
///</summary>
///<param name="selected">Request mode. Can be true or false.</param>
///<returns>
///If the 'selected' parameter is true, the function returns the number of symbols selected in MarketWatch. If the value is false, it returns the total number of all symbols.
///</returns>
public int SymbolsTotal(bool selected) public int SymbolsTotal(bool selected)
{ {
var commandParameters = new ArrayList { selected }; var commandParameters = new ArrayList { selected };
return SendCommand<int>(MtCommandType.SymbolsTotal, commandParameters); return SendCommand<int>(MtCommandType.SymbolsTotal, commandParameters);
} }
///<summary>
///Returns the name of a symbol.
///</summary>
///<param name="pos">Order number of a symbol.</param>
///<param name="selected">Request mode. If the value is true, the symbol is taken from the list of symbols selected in MarketWatch. If the value is false, the symbol is taken from the general list.</param>
///<returns>
///Value of string type with the symbol name.
///</returns>
public string SymbolName(int pos, bool selected) public string SymbolName(int pos, bool selected)
{ {
var commandParameters = new ArrayList { pos, selected }; var commandParameters = new ArrayList { pos, selected };
return SendCommand<string>(MtCommandType.SymbolName, commandParameters); return SendCommand<string>(MtCommandType.SymbolName, commandParameters);
} }
///<summary>
///Selects a symbol in the Market Watch window or removes a symbol from the window.
///</summary>
///<param name="name">Symbol name</param>
///<param name="select">Switch. If the value is false, a symbol should be removed from MarketWatch, otherwise a symbol should be selected in this window. A symbol can't be removed if the symbol chart is open, or there are open orders for this symbol.</param>
///<returns>
///In case of failure returns false.
///</returns>
public bool SymbolSelect(string name, bool select) public bool SymbolSelect(string name, bool select)
{ {
var commandParameters = new ArrayList { name, select }; var commandParameters = new ArrayList { name, select };
return SendCommand<bool>(MtCommandType.SymbolSelect, commandParameters); return SendCommand<bool>(MtCommandType.SymbolSelect, commandParameters);
} }
///<summary>
///Returns the corresponding property of a specified symbol.
///</summary>
///<param name="name">Symbol name</param>
///<param name="propId">Identifier of a symbol property. The value can be one of the values of the EnumSymbolInfoInteger enumeration</param>
///<returns>
///The value of long type.
///</returns>
public long SymbolInfoInteger(string name, EnumSymbolInfoInteger propId)
{
var commandParameters = new ArrayList { name, (int)propId };
return SendCommand<long>(MtCommandType.SymbolInfoInteger, commandParameters);
}
#endregion #endregion
#region Common Function #region Common Function
+2 -1
View File
@@ -200,6 +200,7 @@ namespace MtApi
//Symbols //Symbols
SymbolsTotal = 200, SymbolsTotal = 200,
SymbolName = 201, SymbolName = 201,
SymbolSelect = 202 SymbolSelect = 202,
SymbolInfoInteger = 203
} }
} }
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.