mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 02:57:56 +00:00
Added OrderDeleteRequest. Changed functions OrderDelete to use request pattern. Mark some order functions as obsolete.
This commit is contained in:
@@ -80,6 +80,7 @@
|
||||
<Compile Include="Requests\GetOrdersRequest.cs" />
|
||||
<Compile Include="Requests\OrderCloseByRequest.cs" />
|
||||
<Compile Include="Requests\OrderCloseRequest.cs" />
|
||||
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||
<Compile Include="Requests\RequestBase.cs" />
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
|
||||
+132
-105
@@ -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<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
|
||||
|
||||
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<ResponseBase>(new OrderCloseByRequest
|
||||
@@ -269,60 +384,23 @@ namespace MtApi
|
||||
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)
|
||||
{
|
||||
var commandParameters = new ArrayList { ticket, MtApiColorConverter.ConvertToMtColor(color) };
|
||||
return SendCommand<bool>(MtCommandType.OrderDelete, commandParameters);
|
||||
var response = SendRequest<ResponseBase>(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<int>(MtCommandType.OrderExpiration, null);
|
||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||
}
|
||||
|
||||
public double OrderLots()
|
||||
{
|
||||
return SendCommand<double>(MtCommandType.OrderLots, null);
|
||||
}
|
||||
|
||||
public int OrderMagicNumber()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.OrderMagicNumber, null);
|
||||
var response = SendRequest<ResponseBase>(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<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()
|
||||
{
|
||||
SendCommand<object>(MtCommandType.OrderPrint, null);
|
||||
}
|
||||
|
||||
public double OrderProfit()
|
||||
{
|
||||
return SendCommand<double>(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<int>(MtCommandType.OrdersHistoryTotal, null);
|
||||
}
|
||||
|
||||
public double OrderStopLoss()
|
||||
{
|
||||
return SendCommand<double>(MtCommandType.OrderStopLoss, null);
|
||||
}
|
||||
|
||||
public int OrdersTotal()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.OrdersTotal, null);
|
||||
@@ -396,28 +445,6 @@ namespace MtApi
|
||||
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()
|
||||
{
|
||||
return SendCommand<bool>(MtCommandType.OrderCloseAll, null);
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
GetOrders = 2,
|
||||
OrderSend = 3,
|
||||
OrderClose = 4,
|
||||
OrderCloseBy = 5
|
||||
OrderCloseBy = 5,
|
||||
OrderDelete = 6
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user