diff --git a/MtApi/MtApi.csproj b/MtApi/MtApi.csproj index c3ccf8f4..677110f8 100755 --- a/MtApi/MtApi.csproj +++ b/MtApi/MtApi.csproj @@ -80,6 +80,7 @@ + diff --git a/MtApi/MtApiClient.cs b/MtApi/MtApiClient.cs index 8c347af7..747cfb4d 100755 --- a/MtApi/MtApiClient.cs +++ b/MtApi/MtApiClient.cs @@ -92,6 +92,127 @@ namespace MtApi #endregion + #region Deprecated Methods + [Obsolete("OrderCloseByCurrentPrice is deprecated, please use OrderClose instead.")] + public bool OrderCloseByCurrentPrice(int ticket, int slippage) + { + return OrderClose(ticket, slippage); + } + + [Obsolete("OrderClosePrice is deprecated, please use GetOrder instead.")] + public double OrderClosePrice() + { + return SendCommand(MtCommandType.OrderClosePrice, null); + } + + [Obsolete("OrderClosePrice is deprecated, please use GetOrder instead.")] + public double OrderClosePrice(int ticket) + { + var commandParameters = new ArrayList { ticket }; + double retVal = SendCommand(MtCommandType.OrderClosePriceByTicket, commandParameters); + + return retVal; + } + + [Obsolete("OrderCloseTime is deprecated, please use GetOrder instead.")] + public DateTime OrderCloseTime() + { + var commandResponse = SendCommand(MtCommandType.OrderCloseTime, null); + return MtApiTimeConverter.ConvertFromMtTime(commandResponse); + } + + [Obsolete("OrderComment is deprecated, please use GetOrder instead.")] + public string OrderComment() + { + return SendCommand(MtCommandType.OrderComment, null); + } + + [Obsolete("OrderCommission is deprecated, please use GetOrder instead.")] + public double OrderCommission() + { + return SendCommand(MtCommandType.OrderCommission, null); + } + + [Obsolete("OrderExpiration is deprecated, please use GetOrder instead.")] + public DateTime OrderExpiration() + { + var commandResponse = SendCommand(MtCommandType.OrderExpiration, null); + return MtApiTimeConverter.ConvertFromMtTime(commandResponse); + } + + [Obsolete("OrderLots is deprecated, please use GetOrder instead.")] + public double OrderLots() + { + return SendCommand(MtCommandType.OrderLots, null); + } + + [Obsolete("OrderMagicNumber is deprecated, please use GetOrder instead.")] + public int OrderMagicNumber() + { + return SendCommand(MtCommandType.OrderMagicNumber, null); + } + + [Obsolete("OrderOpenPrice is deprecated, please use GetOrder instead.")] + public double OrderOpenPrice() + { + return SendCommand(MtCommandType.OrderOpenPrice, null); + } + + [Obsolete("OrderOpenPrice is deprecated, please use GetOrder instead.")] + public double OrderOpenPrice(int ticket) + { + var commandParameters = new ArrayList { ticket }; + double retVal = SendCommand(MtCommandType.OrderOpenPriceByTicket, commandParameters); + + return retVal; + } + + [Obsolete("OrderOpenTime is deprecated, please use GetOrder instead.")] + public DateTime OrderOpenTime() + { + var commandResponse = SendCommand(MtCommandType.OrderOpenTime, null); + return MtApiTimeConverter.ConvertFromMtTime(commandResponse); + } + + [Obsolete("OrderProfit is deprecated, please use GetOrder instead.")] + public double OrderProfit() + { + return SendCommand(MtCommandType.OrderProfit, null); + } + + [Obsolete("OrderStopLoss is deprecated, please use GetOrder instead.")] + public double OrderStopLoss() + { + return SendCommand(MtCommandType.OrderStopLoss, null); + } + + [Obsolete("OrderSymbol is deprecated, please use GetOrder instead.")] + public string OrderSymbol() + { + return SendCommand(MtCommandType.OrderSymbol, null); + } + + [Obsolete("OrderTakeProfit is deprecated, please use GetOrder instead.")] + public double OrderTakeProfit() + { + return SendCommand(MtCommandType.OrderTakeProfit, null); + } + + [Obsolete("OrderTicket is deprecated, please use GetOrder instead.")] + public int OrderTicket() + { + return SendCommand(MtCommandType.OrderTicket, null); + } + + [Obsolete("OrderType is deprecated, please use GetOrder instead.")] + public TradeOperation OrderType() + { + int retVal = SendCommand(MtCommandType.OrderType, null); + + return (TradeOperation)retVal; + } + #endregion + #region Trading functions public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit @@ -242,12 +363,6 @@ namespace MtApi return response != null; } - [Obsolete("OrderCloseByCurrentPrice is deprecated, please use OrderClose instead.")] - public bool OrderCloseByCurrentPrice(int ticket, int slippage) - { - return OrderClose(ticket, slippage); - } - public bool OrderCloseBy(int ticket, int opposite, Color color) { var response = SendRequest(new OrderCloseByRequest @@ -269,60 +384,23 @@ namespace MtApi return response != null; } - public double OrderClosePrice() - { - return SendCommand(MtCommandType.OrderClosePrice, null); - } - - public double OrderClosePrice(int ticket) - { - var commandParameters = new ArrayList { ticket }; - double retVal = SendCommand(MtCommandType.OrderClosePriceByTicket, commandParameters); - - return retVal; - } - - public DateTime OrderCloseTime() - { - var commandResponse = SendCommand(MtCommandType.OrderCloseTime, null); - return MtApiTimeConverter.ConvertFromMtTime(commandResponse); - } - - public string OrderComment() - { - return SendCommand(MtCommandType.OrderComment, null); - } - - public double OrderCommission() - { - return SendCommand(MtCommandType.OrderCommission, null); - } - public bool OrderDelete(int ticket, Color color) { - var commandParameters = new ArrayList { ticket, MtApiColorConverter.ConvertToMtColor(color) }; - return SendCommand(MtCommandType.OrderDelete, commandParameters); + var response = SendRequest(new OrderDeleteRequest + { + Ticket = ticket, + ArrowColor = MtApiColorConverter.ConvertToMtColor(color), + }); + return response != null; } public bool OrderDelete(int ticket) { - return OrderDelete(ticket, Color.Empty); - } - - public DateTime OrderExpiration() - { - var commandResponse = SendCommand(MtCommandType.OrderExpiration, null); - return MtApiTimeConverter.ConvertFromMtTime(commandResponse); - } - - public double OrderLots() - { - return SendCommand(MtCommandType.OrderLots, null); - } - - public int OrderMagicNumber() - { - return SendCommand(MtCommandType.OrderMagicNumber, null); + var response = SendRequest(new OrderDeleteRequest + { + Ticket = ticket, + }); + return response != null; } public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrow_color) @@ -336,35 +414,11 @@ namespace MtApi return OrderModify(ticket, price, stoploss, takeprofit, expiration, Color.Empty); } - public double OrderOpenPrice() - { - return SendCommand(MtCommandType.OrderOpenPrice, null); - } - - public double OrderOpenPrice(int ticket) - { - var commandParameters = new ArrayList { ticket }; - double retVal = SendCommand(MtCommandType.OrderOpenPriceByTicket, commandParameters); - - return retVal; - } - - public DateTime OrderOpenTime() - { - var commandResponse = SendCommand(MtCommandType.OrderOpenTime, null); - return MtApiTimeConverter.ConvertFromMtTime(commandResponse); - } - public void OrderPrint() { SendCommand(MtCommandType.OrderPrint, null); } - public double OrderProfit() - { - return SendCommand(MtCommandType.OrderProfit, null); - } - public bool OrderSelect(int index, OrderSelectMode select, OrderSelectSource pool) { var commandParameters = new ArrayList { index, (int)select, (int)pool }; @@ -381,11 +435,6 @@ namespace MtApi return SendCommand(MtCommandType.OrdersHistoryTotal, null); } - public double OrderStopLoss() - { - return SendCommand(MtCommandType.OrderStopLoss, null); - } - public int OrdersTotal() { return SendCommand(MtCommandType.OrdersTotal, null); @@ -396,28 +445,6 @@ namespace MtApi return SendCommand(MtCommandType.OrderSwap, null); } - public string OrderSymbol() - { - return SendCommand(MtCommandType.OrderSymbol, null); - } - - public double OrderTakeProfit() - { - return SendCommand(MtCommandType.OrderTakeProfit, null); - } - - public int OrderTicket() - { - return SendCommand(MtCommandType.OrderTicket, null); - } - - public TradeOperation OrderType() - { - int retVal = SendCommand(MtCommandType.OrderType, null); - - return (TradeOperation) retVal; - } - public bool OrderCloseAll() { return SendCommand(MtCommandType.OrderCloseAll, null); diff --git a/MtApi/Requests/OrderDeleteRequest.cs b/MtApi/Requests/OrderDeleteRequest.cs new file mode 100644 index 00000000..2d205597 --- /dev/null +++ b/MtApi/Requests/OrderDeleteRequest.cs @@ -0,0 +1,14 @@ +namespace MtApi.Requests +{ + public class OrderDeleteRequest: RequestBase + { + public int Ticket { get; set; } + + public int? ArrowColor { get; set; } + + public override RequestType RequestType + { + get { return RequestType.OrderDelete; } + } + } +} \ No newline at end of file diff --git a/MtApi/Requests/RequestType.cs b/MtApi/Requests/RequestType.cs index d4dce25b..a6d92a53 100644 --- a/MtApi/Requests/RequestType.cs +++ b/MtApi/Requests/RequestType.cs @@ -7,6 +7,7 @@ GetOrders = 2, OrderSend = 3, OrderClose = 4, - OrderCloseBy = 5 + OrderCloseBy = 5, + OrderDelete = 6 } } \ No newline at end of file diff --git a/TestApiClientUI/Form1.Designer.cs b/TestApiClientUI/Form1.Designer.cs index a10cb297..c32e19a5 100755 --- a/TestApiClientUI/Form1.Designer.cs +++ b/TestApiClientUI/Form1.Designer.cs @@ -127,6 +127,7 @@ this.button15 = new System.Windows.Forms.Button(); this.textBoxOppositeTicket = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); + this.button21 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -307,6 +308,7 @@ // // tabPage2 // + this.tabPage2.Controls.Add(this.button21); this.tabPage2.Controls.Add(this.label3); this.tabPage2.Controls.Add(this.textBoxOppositeTicket); this.tabPage2.Controls.Add(this.button15); @@ -1216,6 +1218,16 @@ this.label3.TabIndex = 17; this.label3.Text = "Opposite ticket"; // + // button21 + // + this.button21.Location = new System.Drawing.Point(216, 264); + this.button21.Name = "button21"; + this.button21.Size = new System.Drawing.Size(75, 23); + this.button21.TabIndex = 18; + this.button21.Text = "OrderDelete"; + this.button21.UseVisualStyleBackColor = true; + this.button21.Click += new System.EventHandler(this.button21_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1355,6 +1367,7 @@ private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBoxOppositeTicket; private System.Windows.Forms.Button button15; + private System.Windows.Forms.Button button21; } } diff --git a/TestApiClientUI/Form1.cs b/TestApiClientUI/Form1.cs index 19b2b85f..349b284f 100755 --- a/TestApiClientUI/Form1.cs +++ b/TestApiClientUI/Form1.cs @@ -969,5 +969,15 @@ namespace TestApiClientUI AddToLog(string.Format("Close order result: {0}, ticket = {1}", closed, ticket)); } + + //OrderDelete + private async void button21_Click(object sender, EventArgs e) + { + var ticket = int.Parse(textBoxIndexTicket.Text); + + var deleted = await Execute(() => _apiClient.OrderDelete(ticket)); + + AddToLog(string.Format("Delete order result: {0}, ticket = {1}", deleted, ticket)); + } } } diff --git a/mq4/MtApi.ex4 b/mq4/MtApi.ex4 index cd0b6fc8..81b306db 100755 Binary files a/mq4/MtApi.ex4 and b/mq4/MtApi.ex4 differ diff --git a/mq4/MtApi.mq4 b/mq4/MtApi.mq4 index 5e765c97..8ef216c2 100755 --- a/mq4/MtApi.mq4 +++ b/mq4/MtApi.mq4 @@ -3422,6 +3422,9 @@ string OnRequest(string json) case 5: //OrderCloseBy response = ExecuteRequestOrderCloseBy(jo); break; + case 6: + response = ExecuteRequestOrderDelete(jo); + break; default: Print("OnRequest [WARNING]: Unknown request type ", requestType); response = CreateErrorResponse(-1, "Unknown request type"); @@ -3645,4 +3648,19 @@ string ExecuteRequestOrderCloseBy(JSONObject *jo) if (!OrderCloseBy(ticket, opposite, arrowcolor)) return CreateErrorResponse(GetLastError(), "OrderCloseBy failed"); return CreateSuccessResponse("", NULL); +} + +string ExecuteRequestOrderDelete(JSONObject *jo) +{ + if (jo.getValue("Ticket") == NULL) + return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket"); + + int ticket = jo.getInt("Ticket"); + + JSONValue *jvArrowColor = jo.getValue("ArrowColor"); + int arrowcolor = (jvArrowColor != NULL) ? jvArrowColor.getInt() : CLR_NONE; + + if (!OrderDelete(ticket, arrowcolor)) + return CreateErrorResponse(GetLastError(), "OrderDelete failed"); + return CreateSuccessResponse("", NULL); } \ No newline at end of file