diff --git a/MT5Connector/MT5Connector.cpp b/MT5Connector/MT5Connector.cpp index 68dfe1f4..e79b3628 100755 --- a/MT5Connector/MT5Connector.cpp +++ b/MT5Connector/MT5Connector.cpp @@ -31,22 +31,6 @@ public struct CMqlRates int spread; // Spread __int64 real_volume; // Trade volume }; - -public struct CMqlTick -{ - __int64 time; // Time of the last prices update - double bid; // Current Bid price - double ask; // Current Ask price - double last; // Price of the last deal (Last) - unsigned __int64 volume; // Volume for the current Last price -}; - -public struct CMqlBookInfo -{ - int type; // Order type from ENUM_BOOK_TYPE enumeration - double price; // Price - __int64 volume; // Volume -}; #pragma pack(pop) void convertSystemString(wchar_t* dest, String^ src) @@ -224,37 +208,6 @@ _DLLAPI int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates value }, err, 0); } -_DLLAPI int _stdcall sendMqlTickResponse(int expertHandle, CMqlTick* response, wchar_t* err) -{ - return Execute([&expertHandle, response]() { - MtMqlTick^ mtResponse = gcnew MtMqlTick(); - mtResponse->time = response->time; - mtResponse->bid = response->bid; - mtResponse->ask = response->ask; - mtResponse->last = response->last; - mtResponse->volume = response->volume; - MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse)); - return 1; - }, err, 0); -} - -_DLLAPI int _stdcall sendMqlBookInfoArrayResponse(int expertHandle, CMqlBookInfo values[], int size, wchar_t* err) -{ - return Execute([&expertHandle, values, &size]() { - array^ list = gcnew array(size); - for (int i = 0; i < size; i++) - { - MtMqlBookInfo^ info = gcnew MtMqlBookInfo(); - info->type = values[i].type; - info->price = values[i].price; - info->volume = values[i].volume; - list[i] = info; - } - MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list)); - return 1; - }, err, 0); -} - //----------- get values ------------------------------- _DLLAPI int _stdcall getCommandType(int expertHandle, int* res, wchar_t* err) diff --git a/MTApiService/MTApiService.csproj b/MTApiService/MTApiService.csproj index 1e7f802b..6b70d0b6 100755 --- a/MTApiService/MTApiService.csproj +++ b/MTApiService/MTApiService.csproj @@ -72,9 +72,7 @@ - - diff --git a/MTApiService/MtMqlBookInfo.cs b/MTApiService/MtMqlBookInfo.cs deleted file mode 100755 index ca07912f..00000000 --- a/MTApiService/MtMqlBookInfo.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Runtime.Serialization; - -namespace MTApiService -{ - [DataContract] - public class MtMqlBookInfo - { - [DataMember] - public int type { get; set; } - - [DataMember] - public double price { get; set; } - - [DataMember] - public long volume { get; set; } - } -} diff --git a/MTApiService/MtMqlTick.cs b/MTApiService/MtMqlTick.cs deleted file mode 100755 index 1e2d0895..00000000 --- a/MTApiService/MtMqlTick.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Runtime.Serialization; - -namespace MTApiService -{ - [DataContract] - public class MtMqlTick - { - [DataMember] - public long time { get; set; } // Time of the last prices update - - [DataMember] - public double bid { get; set; } // Current Bid price - - [DataMember] - public double ask { get; set; } // Current Ask price - - [DataMember] - public double last { get; set; } // Price of the last deal (Last) - - [DataMember] - public ulong volume { get; set; } // Volume for the current Last price - } -} diff --git a/MTApiService/MtResponse.cs b/MTApiService/MtResponse.cs index 1305dae7..732163d9 100755 --- a/MTApiService/MtResponse.cs +++ b/MTApiService/MtResponse.cs @@ -17,9 +17,8 @@ namespace MTApiService typeof(MtResponseString), typeof(MtResponseBool), typeof(MtResponseLong), typeof(MtResponseULong), typeof(MtResponseDoubleArray), typeof(MtResponseIntArray), - typeof(MtResponseLongArray), typeof(MtResponseMqlTick), - typeof(MtResponseArrayList), typeof(MtResponseMqlRatesArray), - typeof(MtResponseMqlBookInfoArray)}; + typeof(MtResponseLongArray), + typeof(MtResponseArrayList), typeof(MtResponseMqlRatesArray)}; } public abstract object GetValue(); @@ -255,43 +254,4 @@ namespace MTApiService return Value.ToString(); } } - - [DataContract] - public class MtResponseMqlTick : MtResponse - { - public MtResponseMqlTick(MtMqlTick value) - { - Value = value; - } - - [DataMember] - public MtMqlTick Value { get; private set; } - - public override object GetValue() { return Value; } - - public override string ToString() - { - return Value.ToString(); - } - } - - [DataContract] - public class MtResponseMqlBookInfoArray : MtResponse - { - public MtResponseMqlBookInfoArray(MtMqlBookInfo[] value) - { - Value = value; - } - - [DataMember] - public MtMqlBookInfo[] Value { get; private set; } - - public override object GetValue() { return Value; } - - public override string ToString() - { - return Value.ToString(); - } - } - } diff --git a/MTApiService/Properties/AssemblyInfo.cs b/MTApiService/Properties/AssemblyInfo.cs index 48620e3e..fbc0afb7 100644 --- a/MTApiService/Properties/AssemblyInfo.cs +++ b/MTApiService/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.30.0")] -[assembly: AssemblyFileVersion("1.0.30.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.31.0")] +[assembly: AssemblyFileVersion("1.0.31.0")] \ No newline at end of file diff --git a/MtApi5/MqlBookInfo.cs b/MtApi5/MqlBookInfo.cs index d1e4be8e..39d1de8a 100755 --- a/MtApi5/MqlBookInfo.cs +++ b/MtApi5/MqlBookInfo.cs @@ -16,6 +16,7 @@ namespace MtApi5 public ENUM_BOOK_TYPE type { get; set; } // Order type from ENUM_BOOK_TYPE enumeration public double price { get; set; } // Price public long volume { get; set; } // Volume + public double volume_real { get; set; } // Volume for the current Last price with greater accuracy public override string ToString() { diff --git a/MtApi5/MqlTick.cs b/MtApi5/MqlTick.cs index 32125d8a..6cb4c07a 100755 --- a/MtApi5/MqlTick.cs +++ b/MtApi5/MqlTick.cs @@ -23,7 +23,8 @@ namespace MtApi5 public double bid { get; set; } // Current Bid price public double ask { get; set; } // Current Ask price public double last { get; set; } // Price of the last deal (Last) - public ulong volume { get; set; } // Volume for the current Last price + public ulong volume { get; set; } // Volume for the current Last price + public double volume_real { get; set; } // Volume for the current Last price with greater accuracy public DateTime time => Mt5TimeConverter.ConvertFromMtTime(MtTime); } diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj index 27cb2f9a..2c0fa788 100755 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -98,6 +98,7 @@ + diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 0b6bbdf9..9ec3e965 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -1476,19 +1476,27 @@ namespace MtApi5 /// Link to the structure of the MqlTick type, to which the current prices and time of the last price update will be placed. public bool SymbolInfoTick(string symbol, out MqlTick tick) { - var commandParameters = new ArrayList { symbol }; - - var retVal = SendCommand(Mt5CommandType.SymbolInfoTick, commandParameters); - - tick = null; - if (retVal != null) + tick = SendRequest(new SymbolInfoTickRequest { - tick = new MqlTick { MtTime = retVal.time, ask = retVal.ask, bid = retVal.bid, last = retVal.last, volume = retVal.volume }; - } + SymbolName = symbol + }); return tick != null; } + /// + ///The function returns current prices of a specified symbol in a variable of the MqlTick type. + /// + ///Symbol name. + public MqlTick SymbolInfoTick(string symbol) + { + var tick = SendRequest(new SymbolInfoTickRequest + { + SymbolName = symbol + }); + + return tick; + } /// ///Allows receiving time of beginning and end of the specified quoting sessions for a specified symbol and weekday. diff --git a/MtApi5/Requests/RequestType.cs b/MtApi5/Requests/RequestType.cs index 6f3ab373..1355b273 100755 --- a/MtApi5/Requests/RequestType.cs +++ b/MtApi5/Requests/RequestType.cs @@ -15,6 +15,7 @@ namespace MtApi5.Requests SymbolInfoString = 8, ChartTimePriceToXY = 9, ChartXYToTimePrice = 10, - PositionClose = 11 + PositionClose = 11, + SymbolInfoTick = 12 } } \ No newline at end of file diff --git a/MtApi5/Requests/SymbolInfoTickRequest.cs b/MtApi5/Requests/SymbolInfoTickRequest.cs new file mode 100644 index 00000000..17131c88 --- /dev/null +++ b/MtApi5/Requests/SymbolInfoTickRequest.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MtApi5.Requests +{ + internal class SymbolInfoTickRequest : RequestBase + { + public override RequestType RequestType => RequestType.SymbolInfoTick; + + public string SymbolName { get; set; } + } +} diff --git a/TestClients/MtApi5TestClient/ViewModel.cs b/TestClients/MtApi5TestClient/ViewModel.cs index ec356a87..2bf99e9d 100755 --- a/TestClients/MtApi5TestClient/ViewModel.cs +++ b/TestClients/MtApi5TestClient/ViewModel.cs @@ -1030,6 +1030,7 @@ namespace MtApi5TestClient AddLog($"SymbolInfoTick(EURUSD) tick.ask = {result.ask}"); AddLog($"SymbolInfoTick(EURUSD) tick.last = {result.last}"); AddLog($"SymbolInfoTick(EURUSD) tick.volume = {result.volume}"); + AddLog($"SymbolInfoTick(EURUSD) tick.volume_real = {result.volume_real}"); } private async void ExecuteSymbolInfoSessionQuote(object o) @@ -1100,7 +1101,7 @@ namespace MtApi5TestClient for (var i = 0; i < result.Length; i++) { - AddLog($"MarketBookGet: [{i}] - {result[i].price} | {result[i].volume} | {result[i].type}"); + AddLog($"MarketBookGet: [{i}] - {result[i].price} | {result[i].volume} | {result[i].type} | {result[i].volume_real}"); } } diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5 index 1d7dd9d0..b6a27a6b 100755 Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index 90dea82c..9b1c60c6 100644 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -1,7 +1,7 @@ #property copyright "Vyacheslav Demidyuk" #property link "" -#property version "1.7" +#property version "1.6" #property description "MtApi (MT5) connection expert" #include @@ -25,8 +25,6 @@ bool sendULongResponse(int expertHandle, ulong response, string& err); bool sendLongArrayResponse(int expertHandle, long& values[], int size, string& err); bool sendMqlRatesArrayResponse(int expertHandle, MqlRates& values[], int size, string& err); - bool sendMqlTickResponse(int expertHandle, MqlTick& response, string& err); - bool sendMqlBookInfoArrayResponse(int expertHandle, MqlBookInfo& values[], int size, string& err); bool sendErrorResponse(int expertHandle, int code, string message, string& err); bool sendEvent(int expertHandle, int eventType, string payload, string& err); @@ -41,7 +39,7 @@ bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err); #import -//#define __DEBUG_LOG__ +#define __DEBUG_LOG__ enum LockTickType { @@ -532,9 +530,8 @@ int executeCommand() case 56: //SymbolInfoString Execute_SymbolInfoString(); break; - case 57: //SymbolInfoTick - Execute_SymbolInfoTick(); - break; +// case 57: //SymbolInfoTick +// break; case 58: //SymbolInfoSessionQuote Execute_SymbolInfoSessionQuote(); break; @@ -3150,37 +3147,6 @@ void Execute_SymbolInfoString() } } -void Execute_SymbolInfoTick() -{ - string symbol; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolInfoTick", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - MqlTick tick={0}; - bool ok = SymbolInfoTick(symbol, tick); - - if (ok) - { - if (!sendMqlTickResponse(ExpertHandle, tick, _response_error)) - { - PrintResponseError("SymbolInfoTick", _response_error); - } - } - else - { - if (!sendVoidResponse(ExpertHandle, _response_error)) - { - PrintResponseError("SymbolInfoTick", _response_error); - } - } -} - void Execute_SymbolInfoSessionQuote() { string symbol; @@ -3433,87 +3399,52 @@ void Execute_PositionSelectByTicket() void Execute_ObjectCreate() { - int nParameter = 0; long chartId; string name; int type; int nwin; - int time1; - double price1; - int arrTime[29]; - double arrPrice[29]; + int time; + double price; StringInit(name, 200, 0); - if (!getIntValue(ExpertHandle, 0, nParameter, _error)) - { - PrintParamError("ObjectCreate", "nParameter", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!getLongValue(ExpertHandle, 1, chartId, _error)) + if (!getLongValue(ExpertHandle, 0, chartId, _error)) { PrintParamError("ObjectCreate", "chartId", _error); sendErrorResponse(ExpertHandle, -1, _error, _response_error); return; } - if (!getStringValue(ExpertHandle, 2, name, _error)) + if (!getStringValue(ExpertHandle, 1, name, _error)) { PrintParamError("ObjectCreate", "name", _error); sendErrorResponse(ExpertHandle, -1, _error, _response_error); return; } - if (!getIntValue(ExpertHandle, 3, type, _error)) + if (!getIntValue(ExpertHandle, 2, type, _error)) { PrintParamError("ObjectCreate", "type", _error); sendErrorResponse(ExpertHandle, -1, _error, _response_error); return; } - if (!getIntValue(ExpertHandle, 4, nwin, _error)) + if (!getIntValue(ExpertHandle, 3, nwin, _error)) { PrintParamError("ObjectCreate", "nwin", _error); sendErrorResponse(ExpertHandle, -1, _error, _response_error); return; } - if (!getIntValue(ExpertHandle, 5, time1, _error)) + if (!getIntValue(ExpertHandle, 4, time, _error)) { - PrintParamError("ObjectCreate", "time1", _error); + PrintParamError("ObjectCreate", "time", _error); sendErrorResponse(ExpertHandle, -1, _error, _response_error); return; } - if (!getDoubleValue(ExpertHandle, 6, price1, _error)) + if (!getDoubleValue(ExpertHandle, 5, price, _error)) { - PrintParamError("ObjectCreate", "price1", _error); + PrintParamError("ObjectCreate", "price", _error); sendErrorResponse(ExpertHandle, -1, _error, _response_error); return; } - ArrayInitialize(arrTime, 0); - ArrayInitialize(arrPrice, 0); - for(int i = 0; i * 2 + 6 < nParameter; i++) - { - if (!getIntValue(ExpertHandle, i * 2 + 7, arrTime[i], _error)) - { - PrintParamError("ObjectCreate", "time" + IntegerToString(i * 2 + 7), _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - else if (!getDoubleValue(ExpertHandle, i * 2 + 8, arrPrice[i], _error)) - { - PrintParamError("ObjectCreate", "price" + IntegerToString(i * 2 + 8), _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - } - - if (!sendBooleanResponse(ExpertHandle - ,ObjectCreate(chartId, name, (ENUM_OBJECT)type, nwin, (datetime)time1, price1 - ,(datetime)arrTime[0], arrPrice[0],(datetime)arrTime[1], arrPrice[1],(datetime)arrTime[2], arrPrice[2],(datetime)arrTime[3], arrPrice[3],(datetime)arrTime[4], arrPrice[4],(datetime)arrTime[5], arrPrice[5] - ,(datetime)arrTime[6], arrPrice[6],(datetime)arrTime[7], arrPrice[7],(datetime)arrTime[8], arrPrice[8],(datetime)arrTime[9], arrPrice[9],(datetime)arrTime[10], arrPrice[10],(datetime)arrTime[11], arrPrice[11] - ,(datetime)arrTime[12], arrPrice[12],(datetime)arrTime[13], arrPrice[13],(datetime)arrTime[14], arrPrice[14],(datetime)arrTime[15], arrPrice[15],(datetime)arrTime[16], arrPrice[16],(datetime)arrTime[17], arrPrice[17] - ,(datetime)arrTime[18], arrPrice[18],(datetime)arrTime[19], arrPrice[19],(datetime)arrTime[20], arrPrice[20],(datetime)arrTime[21], arrPrice[21],(datetime)arrTime[22], arrPrice[22],(datetime)arrTime[23], arrPrice[23] - ,(datetime)arrTime[24], arrPrice[24],(datetime)arrTime[25], arrPrice[25],(datetime)arrTime[26], arrPrice[26],(datetime)arrTime[27], arrPrice[27],(datetime)arrTime[28], arrPrice[28]) - , _response_error)) + if (!sendBooleanResponse(ExpertHandle, ObjectCreate(chartId, name, (ENUM_OBJECT)type, nwin, (datetime)time, price), _response_error)) { PrintResponseError("ObjectCreate", _response_error); } @@ -6830,6 +6761,9 @@ string OnRequest(string json) case 11: //PositionClose response = ExecuteRequest_PositionClose(jo); break; + case 12: //SymbolInfoTick + response = ExecuteRequest_SymbolInfoTick(jo); + break; default: PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType); response = CreateErrorResponse(-1, "Unknown request type"); @@ -7118,6 +7052,7 @@ JSONObject* MqlBookInfoToJson(MqlBookInfo& info) jo.put("type", new JSONNumber((int)info.type)); jo.put("price", new JSONNumber(info.price)); jo.put("volume", new JSONNumber(info.volume)); + jo.put("volume_real", new JSONNumber(info.volume_real)); return jo; } @@ -7341,6 +7276,25 @@ string ExecuteRequest_PositionClose(JSONObject *jo) return CreateSuccessResponse("Value", result_value_jo); } +string ExecuteRequest_SymbolInfoTick(JSONObject *jo) +{ + CHECK_JSON_VALUE(jo, "SymbolName", CreateErrorResponse(-1, "Undefinded mandatory parameter SymbolName")); + string symbol_name = jo.getString("SymbolName"); + +#ifdef __DEBUG_LOG__ + PrintFormat("%s: symbol_name = %s", __FUNCTION__, symbol_name); +#endif + + MqlTick tick={0}; + bool ok = SymbolInfoTick(symbol_name, tick); + +#ifdef __DEBUG_LOG__ + PrintFormat("%s: ok = %s", __FUNCTION__, BoolToString(ok)); +#endif + + return CreateSuccessResponse("Value", MqlTickToJson(tick)); +} + //------------ Events ------------------------------------------------------- enum MtEventTypes @@ -7572,6 +7526,7 @@ JSONObject* MqlTickToJson(MqlTick& tick) jo.put("ask", new JSONNumber(tick.ask)); jo.put("last", new JSONNumber(tick.last)); jo.put("volume", new JSONNumber(tick.volume)); + jo.put("volume_real", new JSONNumber(tick.volume_real)); return jo; }