Added OrderDeleteRequest. Changed functions OrderDelete to use request pattern. Mark some order functions as obsolete.

This commit is contained in:
DW
2016-04-29 19:10:02 +03:00
parent a52cc001c8
commit 36965bd02c
8 changed files with 190 additions and 106 deletions
+1
View File
@@ -80,6 +80,7 @@
<Compile Include="Requests\GetOrdersRequest.cs" /> <Compile Include="Requests\GetOrdersRequest.cs" />
<Compile Include="Requests\OrderCloseByRequest.cs" /> <Compile Include="Requests\OrderCloseByRequest.cs" />
<Compile Include="Requests\OrderCloseRequest.cs" /> <Compile Include="Requests\OrderCloseRequest.cs" />
<Compile Include="Requests\OrderDeleteRequest.cs" />
<Compile Include="Requests\OrderSendRequest.cs" /> <Compile Include="Requests\OrderSendRequest.cs" />
<Compile Include="Requests\RequestBase.cs" /> <Compile Include="Requests\RequestBase.cs" />
<Compile Include="Requests\RequestType.cs" /> <Compile Include="Requests\RequestType.cs" />
+131 -104
View File
@@ -92,6 +92,127 @@ namespace MtApi
#endregion #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<double>(MtCommandType.OrderClosePrice, null);
}
[Obsolete("OrderClosePrice is deprecated, please use GetOrder instead.")]
public double OrderClosePrice(int ticket)
{
var commandParameters = new ArrayList { ticket };
double retVal = SendCommand<double>(MtCommandType.OrderClosePriceByTicket, commandParameters);
return retVal;
}
[Obsolete("OrderCloseTime is deprecated, please use GetOrder instead.")]
public DateTime OrderCloseTime()
{
var commandResponse = SendCommand<int>(MtCommandType.OrderCloseTime, null);
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
}
[Obsolete("OrderComment is deprecated, please use GetOrder instead.")]
public string OrderComment()
{
return SendCommand<string>(MtCommandType.OrderComment, null);
}
[Obsolete("OrderCommission is deprecated, please use GetOrder instead.")]
public double OrderCommission()
{
return SendCommand<double>(MtCommandType.OrderCommission, null);
}
[Obsolete("OrderExpiration is deprecated, please use GetOrder instead.")]
public DateTime OrderExpiration()
{
var commandResponse = SendCommand<int>(MtCommandType.OrderExpiration, null);
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
}
[Obsolete("OrderLots is deprecated, please use GetOrder instead.")]
public double OrderLots()
{
return SendCommand<double>(MtCommandType.OrderLots, null);
}
[Obsolete("OrderMagicNumber is deprecated, please use GetOrder instead.")]
public int OrderMagicNumber()
{
return SendCommand<int>(MtCommandType.OrderMagicNumber, null);
}
[Obsolete("OrderOpenPrice is deprecated, please use GetOrder instead.")]
public double OrderOpenPrice()
{
return SendCommand<double>(MtCommandType.OrderOpenPrice, null);
}
[Obsolete("OrderOpenPrice is deprecated, please use GetOrder instead.")]
public double OrderOpenPrice(int ticket)
{
var commandParameters = new ArrayList { ticket };
double retVal = SendCommand<double>(MtCommandType.OrderOpenPriceByTicket, commandParameters);
return retVal;
}
[Obsolete("OrderOpenTime is deprecated, please use GetOrder instead.")]
public DateTime OrderOpenTime()
{
var commandResponse = SendCommand<int>(MtCommandType.OrderOpenTime, null);
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
}
[Obsolete("OrderProfit is deprecated, please use GetOrder instead.")]
public double OrderProfit()
{
return SendCommand<double>(MtCommandType.OrderProfit, null);
}
[Obsolete("OrderStopLoss is deprecated, please use GetOrder instead.")]
public double OrderStopLoss()
{
return SendCommand<double>(MtCommandType.OrderStopLoss, null);
}
[Obsolete("OrderSymbol is deprecated, please use GetOrder instead.")]
public string OrderSymbol()
{
return SendCommand<string>(MtCommandType.OrderSymbol, null);
}
[Obsolete("OrderTakeProfit is deprecated, please use GetOrder instead.")]
public double OrderTakeProfit()
{
return SendCommand<double>(MtCommandType.OrderTakeProfit, null);
}
[Obsolete("OrderTicket is deprecated, please use GetOrder instead.")]
public int OrderTicket()
{
return SendCommand<int>(MtCommandType.OrderTicket, null);
}
[Obsolete("OrderType is deprecated, please use GetOrder instead.")]
public TradeOperation OrderType()
{
int retVal = SendCommand<int>(MtCommandType.OrderType, null);
return (TradeOperation)retVal;
}
#endregion
#region Trading functions #region Trading functions
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit 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; 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) public bool OrderCloseBy(int ticket, int opposite, Color color)
{ {
var response = SendRequest<ResponseBase>(new OrderCloseByRequest var response = SendRequest<ResponseBase>(new OrderCloseByRequest
@@ -269,60 +384,23 @@ namespace MtApi
return response != null; return response != null;
} }
public double OrderClosePrice()
{
return SendCommand<double>(MtCommandType.OrderClosePrice, null);
}
public double OrderClosePrice(int ticket)
{
var commandParameters = new ArrayList { ticket };
double retVal = SendCommand<double>(MtCommandType.OrderClosePriceByTicket, commandParameters);
return retVal;
}
public DateTime OrderCloseTime()
{
var commandResponse = SendCommand<int>(MtCommandType.OrderCloseTime, null);
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
}
public string OrderComment()
{
return SendCommand<string>(MtCommandType.OrderComment, null);
}
public double OrderCommission()
{
return SendCommand<double>(MtCommandType.OrderCommission, null);
}
public bool OrderDelete(int ticket, Color color) public bool OrderDelete(int ticket, Color color)
{ {
var commandParameters = new ArrayList { ticket, MtApiColorConverter.ConvertToMtColor(color) }; var response = SendRequest<ResponseBase>(new OrderDeleteRequest
return SendCommand<bool>(MtCommandType.OrderDelete, commandParameters); {
Ticket = ticket,
ArrowColor = MtApiColorConverter.ConvertToMtColor(color),
});
return response != null;
} }
public bool OrderDelete(int ticket) public bool OrderDelete(int ticket)
{ {
return OrderDelete(ticket, Color.Empty); var response = SendRequest<ResponseBase>(new OrderDeleteRequest
}
public DateTime OrderExpiration()
{ {
var commandResponse = SendCommand<int>(MtCommandType.OrderExpiration, null); Ticket = ticket,
return MtApiTimeConverter.ConvertFromMtTime(commandResponse); });
} return response != null;
public double OrderLots()
{
return SendCommand<double>(MtCommandType.OrderLots, null);
}
public int OrderMagicNumber()
{
return SendCommand<int>(MtCommandType.OrderMagicNumber, null);
} }
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrow_color) 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); return OrderModify(ticket, price, stoploss, takeprofit, expiration, Color.Empty);
} }
public double OrderOpenPrice()
{
return SendCommand<double>(MtCommandType.OrderOpenPrice, null);
}
public double OrderOpenPrice(int ticket)
{
var commandParameters = new ArrayList { ticket };
double retVal = SendCommand<double>(MtCommandType.OrderOpenPriceByTicket, commandParameters);
return retVal;
}
public DateTime OrderOpenTime()
{
var commandResponse = SendCommand<int>(MtCommandType.OrderOpenTime, null);
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
}
public void OrderPrint() public void OrderPrint()
{ {
SendCommand<object>(MtCommandType.OrderPrint, null); SendCommand<object>(MtCommandType.OrderPrint, null);
} }
public double OrderProfit()
{
return SendCommand<double>(MtCommandType.OrderProfit, null);
}
public bool OrderSelect(int index, OrderSelectMode select, OrderSelectSource pool) public bool OrderSelect(int index, OrderSelectMode select, OrderSelectSource pool)
{ {
var commandParameters = new ArrayList { index, (int)select, (int)pool }; var commandParameters = new ArrayList { index, (int)select, (int)pool };
@@ -381,11 +435,6 @@ namespace MtApi
return SendCommand<int>(MtCommandType.OrdersHistoryTotal, null); return SendCommand<int>(MtCommandType.OrdersHistoryTotal, null);
} }
public double OrderStopLoss()
{
return SendCommand<double>(MtCommandType.OrderStopLoss, null);
}
public int OrdersTotal() public int OrdersTotal()
{ {
return SendCommand<int>(MtCommandType.OrdersTotal, null); return SendCommand<int>(MtCommandType.OrdersTotal, null);
@@ -396,28 +445,6 @@ namespace MtApi
return SendCommand<double>(MtCommandType.OrderSwap, null); return SendCommand<double>(MtCommandType.OrderSwap, null);
} }
public string OrderSymbol()
{
return SendCommand<string>(MtCommandType.OrderSymbol, null);
}
public double OrderTakeProfit()
{
return SendCommand<double>(MtCommandType.OrderTakeProfit, null);
}
public int OrderTicket()
{
return SendCommand<int>(MtCommandType.OrderTicket, null);
}
public TradeOperation OrderType()
{
int retVal = SendCommand<int>(MtCommandType.OrderType, null);
return (TradeOperation) retVal;
}
public bool OrderCloseAll() public bool OrderCloseAll()
{ {
return SendCommand<bool>(MtCommandType.OrderCloseAll, null); return SendCommand<bool>(MtCommandType.OrderCloseAll, null);
+14
View File
@@ -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; }
}
}
}
+2 -1
View File
@@ -7,6 +7,7 @@
GetOrders = 2, GetOrders = 2,
OrderSend = 3, OrderSend = 3,
OrderClose = 4, OrderClose = 4,
OrderCloseBy = 5 OrderCloseBy = 5,
OrderDelete = 6
} }
} }
+13
View File
@@ -127,6 +127,7 @@
this.button15 = new System.Windows.Forms.Button(); this.button15 = new System.Windows.Forms.Button();
this.textBoxOppositeTicket = new System.Windows.Forms.TextBox(); this.textBoxOppositeTicket = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.button21 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@@ -307,6 +308,7 @@
// //
// tabPage2 // tabPage2
// //
this.tabPage2.Controls.Add(this.button21);
this.tabPage2.Controls.Add(this.label3); this.tabPage2.Controls.Add(this.label3);
this.tabPage2.Controls.Add(this.textBoxOppositeTicket); this.tabPage2.Controls.Add(this.textBoxOppositeTicket);
this.tabPage2.Controls.Add(this.button15); this.tabPage2.Controls.Add(this.button15);
@@ -1216,6 +1218,16 @@
this.label3.TabIndex = 17; this.label3.TabIndex = 17;
this.label3.Text = "Opposite ticket"; 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1355,6 +1367,7 @@
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxOppositeTicket; private System.Windows.Forms.TextBox textBoxOppositeTicket;
private System.Windows.Forms.Button button15; private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button21;
} }
} }
+10
View File
@@ -969,5 +969,15 @@ namespace TestApiClientUI
AddToLog(string.Format("Close order result: {0}, ticket = {1}", closed, ticket)); 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));
}
} }
} }
BIN
View File
Binary file not shown.
+18
View File
@@ -3422,6 +3422,9 @@ string OnRequest(string json)
case 5: //OrderCloseBy case 5: //OrderCloseBy
response = ExecuteRequestOrderCloseBy(jo); response = ExecuteRequestOrderCloseBy(jo);
break; break;
case 6:
response = ExecuteRequestOrderDelete(jo);
break;
default: default:
Print("OnRequest [WARNING]: Unknown request type ", requestType); Print("OnRequest [WARNING]: Unknown request type ", requestType);
response = CreateErrorResponse(-1, "Unknown request type"); response = CreateErrorResponse(-1, "Unknown request type");
@@ -3646,3 +3649,18 @@ string ExecuteRequestOrderCloseBy(JSONObject *jo)
return CreateErrorResponse(GetLastError(), "OrderCloseBy failed"); return CreateErrorResponse(GetLastError(), "OrderCloseBy failed");
return CreateSuccessResponse("", NULL); 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);
}