diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj
index 6d71bd26..8596a9c9 100755
--- a/MtApi5/MtApi5.csproj
+++ b/MtApi5/MtApi5.csproj
@@ -89,6 +89,7 @@
+
diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs
index 6355fa45..3a95a846 100755
--- a/MtApi5/MtApi5Client.cs
+++ b/MtApi5/MtApi5Client.cs
@@ -134,6 +134,38 @@ namespace MtApi5
return response != null && response.RetVal;
}
+ ///
+ ///Function is used for conducting asynchronous trade operations without waiting for the trade server's response to a sent request.
+ ///
+ ///Reference to a object of MqlTradeRequest type describing the trade activity of the client.
+ ///Reference to a object of MqlTradeResult type describing the result of trade operation in case of a successful completion (if true is returned).
+ ///
+ /// Returns true if the request is sent to a trade server. In case the request is not sent, it returns false.
+ /// In case the request is sent, in the result variable the response code contains TRADE_RETCODE_PLACED value (code 10008) – "order placed".
+ /// Successful execution means only the fact of sending, but does not give any guarantee that the request has reached the trade server and has been accepted for processing.
+ /// When processing the received request, a trade server sends a reply to a client terminal notifying of change in the current state of positions,
+ /// orders and deals, which leads to the generation of the Trade event.
+ ///
+ public bool OrderSendAsync(MqlTradeRequest request, out MqlTradeResult result)
+ {
+ Log.Debug($"OrderSend: request = {request}");
+
+ if (request == null)
+ {
+ Log.Warn("OrderSend: request is not defined!");
+ result = null;
+ return false;
+ }
+
+ var response = SendRequest(new OrderSendAsyncRequest
+ {
+ TradeRequest = request
+ });
+
+ result = response?.TradeResult;
+ return response != null && response.RetVal;
+ }
+
///
///The function calculates the margin required for the specified order type, on the current account
///, in the current market environment not taking into account current pending orders and open positions
diff --git a/MtApi5/Requests/OrderSendAsyncRequest.cs b/MtApi5/Requests/OrderSendAsyncRequest.cs
new file mode 100644
index 00000000..d4fa43a9
--- /dev/null
+++ b/MtApi5/Requests/OrderSendAsyncRequest.cs
@@ -0,0 +1,9 @@
+namespace MtApi5.Requests
+{
+ internal class OrderSendAsyncRequest : RequestBase
+ {
+ public override RequestType RequestType => RequestType.OrderSendAsync;
+
+ public MqlTradeRequest TradeRequest { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/MtApi5/Requests/RequestType.cs b/MtApi5/Requests/RequestType.cs
index 38c7dfd3..44acac1f 100755
--- a/MtApi5/Requests/RequestType.cs
+++ b/MtApi5/Requests/RequestType.cs
@@ -18,6 +18,7 @@ namespace MtApi5.Requests
PositionClose = 11,
SymbolInfoTick = 12,
Buy = 13,
- Sell = 14
+ Sell = 14,
+ OrderSendAsync = 15
}
}
\ No newline at end of file
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index 8b946f38..ff798453 100644
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index 4baafd49..680ad303 100644
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -1,7 +1,7 @@
#property copyright "Vyacheslav Demidyuk"
#property link ""
-#property version "1.8"
+#property version "1.9"
#property description "MtApi (MT5) connection expert"
#include
@@ -6961,7 +6961,10 @@ string OnRequest(string json)
break;
case 14: //Sell
response = ExecuteRequest_Sell(jo);
- break;
+ break;
+ case 15: //OrderSendAsync
+ response = ExecuteRequest_OrderSendAsync(jo);
+ break;
default:
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
response = CreateErrorResponse(-1, "Unknown request type");
@@ -7171,6 +7174,30 @@ string ExecuteRequest_OrderSend(JSONObject *jo)
return CreateSuccessResponse("Value", result_value_jo);
}
+string ExecuteRequest_OrderSendAsync(JSONObject *jo)
+{
+ CHECK_JSON_VALUE(jo, "TradeRequest", CreateErrorResponse(-1, "Undefinded mandatory parameter TradeRequest"));
+ JSONObject* trade_request_jo = jo.getObject("TradeRequest");
+
+ MqlTradeRequest trade_request = {0};
+ bool converted = JsonToMqlTradeRequest(trade_request_jo, trade_request);
+ if (converted == false)
+ return CreateErrorResponse(-1, "Failed to parse parameter TradeRequest");
+
+ MqlTradeResult trade_result = {0};
+ bool ok = OrderSendAsync(trade_request, trade_result);
+
+ JSONObject* result_value_jo = new JSONObject();
+ result_value_jo.put("RetVal", new JSONBool(ok));
+ result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: return value = %s", __FUNCTION__, ok ? "true" : "false");
+#endif
+
+ return CreateSuccessResponse("Value", result_value_jo);
+}
+
string ExecuteRequest_PositionOpen(JSONObject *jo)
{
//Symbol