diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index b75bd2a0..613f2255 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -860,6 +860,157 @@ public bool Sell(out MqlTradeResult? result, double volume, string? symbol = nul result = response?.Result; return response != null && response.RetVal; } + + /// + /// Places a Buy Limit pending order (buy at a price lower than the current market price) with specified parameters + /// + /// output result + /// Requested order volume. + /// Order execution price. + /// Order symbol. If it is not specified, the current symbol will be used. + /// Stop Loss price. + /// Take Profit price. + /// Order expiration type. + /// Order expiration time (used with typeTime ORDER_TIME_SPECIFIED or ORDER_TIME_SPECIFIED_DAY). + /// Comment. + /// true - successful check of the structures, otherwise - false. + public bool BuyLimit(out MqlTradeResult? result, double volume, double price, string? symbol = null, double sl = 0.0, double tp = 0.0, ENUM_ORDER_TYPE_TIME typeTime = ENUM_ORDER_TYPE_TIME.ORDER_TIME_GTC, DateTime? expiration = null, string? comment = null) + { + Dictionary cmdParams = new() { { "Volume", volume }, { "Price", price }, { "Sl", sl }, { "Tp", tp }, + { "TypeTime", (int)typeTime }, { "Expiration", Mt5TimeConverter.ConvertToMtTime(expiration) } }; + if (symbol != null) + cmdParams["Symbol"] = symbol; + if (comment != null) + cmdParams["Comment"] = comment; + + var response = SendCommand>(ExecutorHandle, Mt5CommandType.BuyLimit, cmdParams); + + result = response?.Result; + return response != null && response.RetVal; + } + + /// + /// Places a Sell Limit pending order (sell at a price higher than the current market price) with specified parameters + /// + /// output result + /// Requested order volume. + /// Order execution price. + /// Order symbol. If it is not specified, the current symbol will be used. + /// Stop Loss price. + /// Take Profit price. + /// Order expiration type. + /// Order expiration time (used with typeTime ORDER_TIME_SPECIFIED or ORDER_TIME_SPECIFIED_DAY). + /// Comment. + /// true - successful check of the structures, otherwise - false. + public bool SellLimit(out MqlTradeResult? result, double volume, double price, string? symbol = null, double sl = 0.0, double tp = 0.0, ENUM_ORDER_TYPE_TIME typeTime = ENUM_ORDER_TYPE_TIME.ORDER_TIME_GTC, DateTime? expiration = null, string? comment = null) + { + Dictionary cmdParams = new() { { "Volume", volume }, { "Price", price }, { "Sl", sl }, { "Tp", tp }, + { "TypeTime", (int)typeTime }, { "Expiration", Mt5TimeConverter.ConvertToMtTime(expiration) } }; + if (symbol != null) + cmdParams["Symbol"] = symbol; + if (comment != null) + cmdParams["Comment"] = comment; + + var response = SendCommand>(ExecutorHandle, Mt5CommandType.SellLimit, cmdParams); + + result = response?.Result; + return response != null && response.RetVal; + } + + /// + /// Places a Buy Stop pending order (buy at a price higher than the current market price) with specified parameters + /// + /// output result + /// Requested order volume. + /// Order execution price. + /// Order symbol. If it is not specified, the current symbol will be used. + /// Stop Loss price. + /// Take Profit price. + /// Order expiration type. + /// Order expiration time (used with typeTime ORDER_TIME_SPECIFIED or ORDER_TIME_SPECIFIED_DAY). + /// Comment. + /// true - successful check of the structures, otherwise - false. + public bool BuyStop(out MqlTradeResult? result, double volume, double price, string? symbol = null, double sl = 0.0, double tp = 0.0, ENUM_ORDER_TYPE_TIME typeTime = ENUM_ORDER_TYPE_TIME.ORDER_TIME_GTC, DateTime? expiration = null, string? comment = null) + { + Dictionary cmdParams = new() { { "Volume", volume }, { "Price", price }, { "Sl", sl }, { "Tp", tp }, + { "TypeTime", (int)typeTime }, { "Expiration", Mt5TimeConverter.ConvertToMtTime(expiration) } }; + if (symbol != null) + cmdParams["Symbol"] = symbol; + if (comment != null) + cmdParams["Comment"] = comment; + + var response = SendCommand>(ExecutorHandle, Mt5CommandType.BuyStop, cmdParams); + + result = response?.Result; + return response != null && response.RetVal; + } + + /// + /// Places a Sell Stop pending order (sell at a price lower than the current market price) with specified parameters + /// + /// output result + /// Requested order volume. + /// Order execution price. + /// Order symbol. If it is not specified, the current symbol will be used. + /// Stop Loss price. + /// Take Profit price. + /// Order expiration type. + /// Order expiration time (used with typeTime ORDER_TIME_SPECIFIED or ORDER_TIME_SPECIFIED_DAY). + /// Comment. + /// true - successful check of the structures, otherwise - false. + public bool SellStop(out MqlTradeResult? result, double volume, double price, string? symbol = null, double sl = 0.0, double tp = 0.0, ENUM_ORDER_TYPE_TIME typeTime = ENUM_ORDER_TYPE_TIME.ORDER_TIME_GTC, DateTime? expiration = null, string? comment = null) + { + Dictionary cmdParams = new() { { "Volume", volume }, { "Price", price }, { "Sl", sl }, { "Tp", tp }, + { "TypeTime", (int)typeTime }, { "Expiration", Mt5TimeConverter.ConvertToMtTime(expiration) } }; + if (symbol != null) + cmdParams["Symbol"] = symbol; + if (comment != null) + cmdParams["Comment"] = comment; + + var response = SendCommand>(ExecutorHandle, Mt5CommandType.SellStop, cmdParams); + + result = response?.Result; + return response != null && response.RetVal; + } + + /// + /// Modifies the parameters of a previously placed pending order + /// + /// output result + /// Ticket of the pending order to be modified. + /// New order execution price. + /// New Stop Loss price. + /// New Take Profit price. + /// Order expiration type. + /// Order expiration time (used with typeTime ORDER_TIME_SPECIFIED or ORDER_TIME_SPECIFIED_DAY). + /// Limit order price for the StopLimit order. + /// true - successful check of the structures, otherwise - false. + public bool OrderModify(out MqlTradeResult? result, ulong ticket, double price, double sl, double tp, ENUM_ORDER_TYPE_TIME typeTime = ENUM_ORDER_TYPE_TIME.ORDER_TIME_GTC, DateTime? expiration = null, double stoplimit = 0.0) + { + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Price", price }, { "Sl", sl }, { "Tp", tp }, + { "TypeTime", (int)typeTime }, { "Expiration", Mt5TimeConverter.ConvertToMtTime(expiration) }, { "Stoplimit", stoplimit } }; + + var response = SendCommand>(ExecutorHandle, Mt5CommandType.OrderModify, cmdParams); + + result = response?.Result; + return response != null && response.RetVal; + } + + /// + /// Removes a previously placed pending order + /// + /// output result + /// Ticket of the pending order to be deleted. + /// true - successful check of the structures, otherwise - false. + public bool OrderDelete(out MqlTradeResult? result, ulong ticket) + { + Dictionary cmdParams = new() { { "Ticket", ticket } }; + + var response = SendCommand>(ExecutorHandle, Mt5CommandType.OrderDelete, cmdParams); + + result = response?.Result; + return response != null && response.RetVal; + } #endregion #region Account Information functions diff --git a/MtApi5/MtProtocol/Mt5CommandType.cs b/MtApi5/MtProtocol/Mt5CommandType.cs index 4af91bdb..1edc5a70 100755 --- a/MtApi5/MtProtocol/Mt5CommandType.cs +++ b/MtApi5/MtProtocol/Mt5CommandType.cs @@ -260,6 +260,13 @@ internal enum Mt5CommandType OrderCheck = 303, Buy = 304, Sell = 305, - GetSymbols = 306 + GetSymbols = 306, + + BuyLimit = 320, + SellLimit = 321, + BuyStop = 322, + SellStop = 323, + OrderModify = 324, + OrderDelete = 325 } } diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml index c30fe43e..32bb5a04 100755 --- a/TestClients/MtApi5TestClient/MainWindow.xaml +++ b/TestClients/MtApi5TestClient/MainWindow.xaml @@ -529,6 +529,8 @@