Added OrderCloseRequest. Changed functions OrderClose to use request pattern

This commit is contained in:
DW
2016-04-29 15:05:37 +03:00
parent ace3764317
commit 4328fcb050
9 changed files with 559 additions and 724 deletions
+1
View File
@@ -78,6 +78,7 @@
<Compile Include="OrderSelectSource.cs" />
<Compile Include="Requests\GetOrderRequest.cs" />
<Compile Include="Requests\GetOrdersRequest.cs" />
<Compile Include="Requests\OrderCloseRequest.cs" />
<Compile Include="Requests\OrderSendRequest.cs" />
<Compile Include="Requests\RequestBase.cs" />
<Compile Include="Requests\RequestType.cs" />
+215 -189
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -13,8 +13,9 @@ namespace MtApi
// OrderSend = 1,
// OrderSendBuy = 1001,
// OrderSendSell = 1002,
OrderClose = 2,
OrderCloseByCurrentPrice = 152,
// OrderClose = 2,
// OrderCloseByCurrentPrice = 152,
OrderCloseBy = 3,
OrderClosePrice = 4,
OrderClosePriceByTicket = 1004,
+17
View File
@@ -0,0 +1,17 @@
namespace MtApi.Requests
{
public class OrderCloseRequest: RequestBase
{
public int Ticket { get; set; }
public double? Lots { get; set; }
public double? Price { get; set; }
public int? Slippage { get; set; }
public int? ArrowColor { get; set; }
public override RequestType RequestType
{
get { return RequestType.OrderClose; }
}
}
}
+2 -1
View File
@@ -5,6 +5,7 @@
Unknown = 0,
GetOrder = 1,
GetOrders = 2,
OrderSend = 3
OrderSend = 3,
OrderClose = 4,
}
}
+64 -51
View File
@@ -48,6 +48,7 @@
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button20 = new System.Windows.Forms.Button();
this.button17 = new System.Windows.Forms.Button();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
@@ -60,6 +61,8 @@
this.listBoxClosedOrders = new System.Windows.Forms.ListBox();
this.button2 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button19 = new System.Windows.Forms.Button();
this.button18 = new System.Windows.Forms.Button();
this.comboBoxOrderColor = new System.Windows.Forms.ComboBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBoxOrderMagic = new System.Windows.Forms.TextBox();
@@ -118,11 +121,9 @@
this.button6 = new System.Windows.Forms.Button();
this.listBoxProceHistory = new System.Windows.Forms.ListBox();
this.tabPage6 = new System.Windows.Forms.TabPage();
this.button15 = new System.Windows.Forms.Button();
this.button14 = new System.Windows.Forms.Button();
this.button13 = new System.Windows.Forms.Button();
this.button18 = new System.Windows.Forms.Button();
this.button19 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.groupBox2.SuspendLayout();
@@ -303,6 +304,8 @@
//
// tabPage2
//
this.tabPage2.Controls.Add(this.checkBox1);
this.tabPage2.Controls.Add(this.button20);
this.tabPage2.Controls.Add(this.button17);
this.tabPage2.Controls.Add(this.comboBox2);
this.tabPage2.Controls.Add(this.comboBox1);
@@ -324,9 +327,19 @@
this.tabPage2.Text = "Trade Operations";
this.tabPage2.UseVisualStyleBackColor = true;
//
// button20
//
this.button20.Location = new System.Drawing.Point(216, 185);
this.button20.Name = "button20";
this.button20.Size = new System.Drawing.Size(75, 23);
this.button20.TabIndex = 13;
this.button20.Text = "CloseOrder";
this.button20.UseVisualStyleBackColor = true;
this.button20.Click += new System.EventHandler(this.button20_Click);
//
// button17
//
this.button17.Location = new System.Drawing.Point(601, 290);
this.button17.Location = new System.Drawing.Point(601, 158);
this.button17.Name = "button17";
this.button17.Size = new System.Drawing.Size(75, 23);
this.button17.TabIndex = 12;
@@ -341,7 +354,7 @@
this.comboBox2.Items.AddRange(new object[] {
"MODE_TRADES",
"MODE_HISTORY"});
this.comboBox2.Location = new System.Drawing.Point(481, 261);
this.comboBox2.Location = new System.Drawing.Point(341, 158);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(114, 21);
this.comboBox2.TabIndex = 11;
@@ -353,14 +366,14 @@
this.comboBox1.Items.AddRange(new object[] {
"SELECT_BY_POS",
"SELECT_BY_TICKET"});
this.comboBox1.Location = new System.Drawing.Point(356, 261);
this.comboBox1.Location = new System.Drawing.Point(216, 158);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(119, 21);
this.comboBox1.TabIndex = 10;
//
// button16
//
this.button16.Location = new System.Drawing.Point(601, 261);
this.button16.Location = new System.Drawing.Point(461, 158);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(75, 23);
this.button16.TabIndex = 9;
@@ -371,7 +384,7 @@
// label21
//
this.label21.AutoSize = true;
this.label21.Location = new System.Drawing.Point(213, 264);
this.label21.Location = new System.Drawing.Point(213, 135);
this.label21.Name = "label21";
this.label21.Size = new System.Drawing.Size(71, 13);
this.label21.TabIndex = 8;
@@ -379,9 +392,9 @@
//
// textBoxIndexTicket
//
this.textBoxIndexTicket.Location = new System.Drawing.Point(290, 261);
this.textBoxIndexTicket.Location = new System.Drawing.Point(290, 132);
this.textBoxIndexTicket.Name = "textBoxIndexTicket";
this.textBoxIndexTicket.Size = new System.Drawing.Size(60, 20);
this.textBoxIndexTicket.Size = new System.Drawing.Size(109, 20);
this.textBoxIndexTicket.TabIndex = 7;
this.textBoxIndexTicket.Text = "0";
//
@@ -413,7 +426,7 @@
"OrderTakeProfit",
"OrderTicket",
"OrderType"});
this.comboBoxSelectedCommand.Location = new System.Drawing.Point(216, 292);
this.comboBoxSelectedCommand.Location = new System.Drawing.Point(213, 344);
this.comboBoxSelectedCommand.Name = "comboBoxSelectedCommand";
this.comboBoxSelectedCommand.Size = new System.Drawing.Size(121, 21);
this.comboBoxSelectedCommand.TabIndex = 6;
@@ -430,7 +443,7 @@
// label16
//
this.label16.AutoSize = true;
this.label16.Location = new System.Drawing.Point(213, 135);
this.label16.Location = new System.Drawing.Point(210, 69);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(42, 13);
this.label16.TabIndex = 4;
@@ -441,14 +454,14 @@
this.listBoxClosedOrders.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listBoxClosedOrders.FormattingEnabled = true;
this.listBoxClosedOrders.Location = new System.Drawing.Point(213, 151);
this.listBoxClosedOrders.Location = new System.Drawing.Point(213, 85);
this.listBoxClosedOrders.Name = "listBoxClosedOrders";
this.listBoxClosedOrders.Size = new System.Drawing.Size(463, 108);
this.listBoxClosedOrders.Size = new System.Drawing.Size(463, 43);
this.listBoxClosedOrders.TabIndex = 5;
//
// button2
//
this.button2.Location = new System.Drawing.Point(343, 292);
this.button2.Location = new System.Drawing.Point(356, 342);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(87, 23);
this.button2.TabIndex = 2;
@@ -490,6 +503,26 @@
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Send Order";
//
// button19
//
this.button19.Location = new System.Drawing.Point(87, 336);
this.button19.Name = "button19";
this.button19.Size = new System.Drawing.Size(75, 23);
this.button19.TabIndex = 15;
this.button19.Text = "Sell";
this.button19.UseVisualStyleBackColor = true;
this.button19.Click += new System.EventHandler(this.button19_Click);
//
// button18
//
this.button18.Location = new System.Drawing.Point(6, 336);
this.button18.Name = "button18";
this.button18.Size = new System.Drawing.Size(75, 23);
this.button18.TabIndex = 14;
this.button18.Text = "Buy";
this.button18.UseVisualStyleBackColor = true;
this.button18.Click += new System.EventHandler(this.button18_Click);
//
// comboBoxOrderColor
//
this.comboBoxOrderColor.FormattingEnabled = true;
@@ -708,7 +741,7 @@
this.listBoxSendedOrders.Location = new System.Drawing.Point(213, 23);
this.listBoxSendedOrders.Name = "listBoxSendedOrders";
this.listBoxSendedOrders.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
this.listBoxSendedOrders.Size = new System.Drawing.Size(463, 121);
this.listBoxSendedOrders.Size = new System.Drawing.Size(463, 43);
this.listBoxSendedOrders.TabIndex = 1;
//
// tabPage1
@@ -721,7 +754,7 @@
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(682, 362);
this.tabPage1.Size = new System.Drawing.Size(682, 377);
this.tabPage1.TabIndex = 2;
this.tabPage1.Text = "Check Status";
this.tabPage1.UseVisualStyleBackColor = true;
@@ -799,7 +832,7 @@
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
this.tabPage3.Size = new System.Drawing.Size(682, 362);
this.tabPage3.Size = new System.Drawing.Size(682, 377);
this.tabPage3.TabIndex = 3;
this.tabPage3.Text = "Account Information";
this.tabPage3.UseVisualStyleBackColor = true;
@@ -910,7 +943,7 @@
this.tabPage4.Location = new System.Drawing.Point(4, 22);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(682, 362);
this.tabPage4.Size = new System.Drawing.Size(682, 377);
this.tabPage4.TabIndex = 4;
this.tabPage4.Text = "MarketInfo";
this.tabPage4.UseVisualStyleBackColor = true;
@@ -992,7 +1025,7 @@
this.tabPage5.Location = new System.Drawing.Point(4, 22);
this.tabPage5.Name = "tabPage5";
this.tabPage5.Padding = new System.Windows.Forms.Padding(3);
this.tabPage5.Size = new System.Drawing.Size(682, 362);
this.tabPage5.Size = new System.Drawing.Size(682, 377);
this.tabPage5.TabIndex = 5;
this.tabPage5.Text = "Timeframes";
this.tabPage5.UseVisualStyleBackColor = true;
@@ -1110,27 +1143,16 @@
//
// tabPage6
//
this.tabPage6.Controls.Add(this.button15);
this.tabPage6.Controls.Add(this.button14);
this.tabPage6.Controls.Add(this.button13);
this.tabPage6.Location = new System.Drawing.Point(4, 22);
this.tabPage6.Name = "tabPage6";
this.tabPage6.Padding = new System.Windows.Forms.Padding(3);
this.tabPage6.Size = new System.Drawing.Size(682, 362);
this.tabPage6.Size = new System.Drawing.Size(682, 377);
this.tabPage6.TabIndex = 6;
this.tabPage6.Text = "Client Terminal";
this.tabPage6.UseVisualStyleBackColor = true;
//
// button15
//
this.button15.Location = new System.Drawing.Point(223, 184);
this.button15.Name = "button15";
this.button15.Size = new System.Drawing.Size(75, 23);
this.button15.TabIndex = 2;
this.button15.Text = "button15";
this.button15.UseVisualStyleBackColor = true;
this.button15.Click += new System.EventHandler(this.button15_Click);
//
// button14
//
this.button14.Location = new System.Drawing.Point(13, 45);
@@ -1151,25 +1173,15 @@
this.button13.UseVisualStyleBackColor = true;
this.button13.Click += new System.EventHandler(this.button13_Click);
//
// button18
// checkBox1
//
this.button18.Location = new System.Drawing.Point(6, 336);
this.button18.Name = "button18";
this.button18.Size = new System.Drawing.Size(75, 23);
this.button18.TabIndex = 14;
this.button18.Text = "Buy";
this.button18.UseVisualStyleBackColor = true;
this.button18.Click += new System.EventHandler(this.button18_Click);
//
// button19
//
this.button19.Location = new System.Drawing.Point(87, 336);
this.button19.Name = "button19";
this.button19.Size = new System.Drawing.Size(75, 23);
this.button19.TabIndex = 15;
this.button19.Text = "Sell";
this.button19.UseVisualStyleBackColor = true;
this.button19.Click += new System.EventHandler(this.button19_Click);
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(297, 191);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(205, 17);
this.checkBox1.TabIndex = 14;
this.checkBox1.Text = "Close order by current price on market";
this.checkBox1.UseVisualStyleBackColor = true;
//
// Form1
//
@@ -1298,7 +1310,6 @@
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button buttonRefreshRates;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBox2;
@@ -1306,6 +1317,8 @@
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.Button button19;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Button button20;
private System.Windows.Forms.CheckBox checkBox1;
}
}
+192 -249
View File
@@ -17,20 +17,17 @@ namespace TestApiClientUI
{
public partial class Form1 : Form
{
delegate void PerformCommandHandler();
private List<PerformCommandHandler> GroupOrderCommands = new List<PerformCommandHandler>();
private MtApiClient apiClient = new MtApiClient();
private readonly List<Action> _groupOrderCommands = new List<Action>();
private readonly MtApiClient _apiClient = new MtApiClient();
public Form1()
{
InitializeComponent();
apiClient.QuoteUpdated += apiClient_QuoteUpdated;
apiClient.QuoteAdded += apiClient_QuoteAdded;
apiClient.QuoteRemoved += apiClient_QuoteRemoved;
apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
_apiClient.QuoteUpdated += apiClient_QuoteUpdated;
_apiClient.QuoteAdded += apiClient_QuoteAdded;
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
initOrderCommandsGroup();
@@ -40,30 +37,30 @@ namespace TestApiClientUI
private void initOrderCommandsGroup()
{
GroupOrderCommands.Add(new PerformCommandHandler(closeOrders));
GroupOrderCommands.Add(new PerformCommandHandler(closeOrdersBy));
GroupOrderCommands.Add(new PerformCommandHandler(orderClosePrice));
GroupOrderCommands.Add(new PerformCommandHandler(orderCloseTime));
GroupOrderCommands.Add(new PerformCommandHandler(orderComment));
GroupOrderCommands.Add(new PerformCommandHandler(orderCommission));
GroupOrderCommands.Add(new PerformCommandHandler(orderDelete));
GroupOrderCommands.Add(new PerformCommandHandler(orderExpiration));
GroupOrderCommands.Add(new PerformCommandHandler(orderLots));
GroupOrderCommands.Add(new PerformCommandHandler(orderMagicNumber));
GroupOrderCommands.Add(new PerformCommandHandler(orderModify));
GroupOrderCommands.Add(new PerformCommandHandler(orderOpenPrice));
GroupOrderCommands.Add(new PerformCommandHandler(orderOpenTime));
GroupOrderCommands.Add(new PerformCommandHandler(orderPrint));
GroupOrderCommands.Add(new PerformCommandHandler(orderProfit));
GroupOrderCommands.Add(new PerformCommandHandler(orderSelect));
GroupOrderCommands.Add(new PerformCommandHandler(ordersHistoryTotal));
GroupOrderCommands.Add(new PerformCommandHandler(orderStopLoss));
GroupOrderCommands.Add(new PerformCommandHandler(ordersTotal));
GroupOrderCommands.Add(new PerformCommandHandler(orderSwap));
GroupOrderCommands.Add(new PerformCommandHandler(orderSymbol));
GroupOrderCommands.Add(new PerformCommandHandler(orderTakeProfit));
GroupOrderCommands.Add(new PerformCommandHandler(orderTicket));
GroupOrderCommands.Add(new PerformCommandHandler(orderType));
_groupOrderCommands.Add(closeOrders);
_groupOrderCommands.Add(closeOrdersBy);
_groupOrderCommands.Add(orderClosePrice);
_groupOrderCommands.Add(orderCloseTime);
_groupOrderCommands.Add(orderComment);
_groupOrderCommands.Add(orderCommission);
_groupOrderCommands.Add(orderDelete);
_groupOrderCommands.Add(orderExpiration);
_groupOrderCommands.Add(orderLots);
_groupOrderCommands.Add(orderMagicNumber);
_groupOrderCommands.Add(orderModify);
_groupOrderCommands.Add(orderOpenPrice);
_groupOrderCommands.Add(orderOpenTime);
_groupOrderCommands.Add(orderPrint);
_groupOrderCommands.Add(orderProfit);
_groupOrderCommands.Add(orderSelect);
_groupOrderCommands.Add(ordersHistoryTotal);
_groupOrderCommands.Add(orderStopLoss);
_groupOrderCommands.Add(ordersTotal);
_groupOrderCommands.Add(orderSwap);
_groupOrderCommands.Add(orderSymbol);
_groupOrderCommands.Add(orderTakeProfit);
_groupOrderCommands.Add(orderTicket);
_groupOrderCommands.Add(orderType);
}
private void RunOnUiThread(Action action)
@@ -175,7 +172,7 @@ namespace TestApiClientUI
private void onConnected()
{
var quotes = apiClient.GetQuotes();
var quotes = _apiClient.GetQuotes();
if (quotes != null)
{
@@ -199,21 +196,21 @@ namespace TestApiClientUI
int.TryParse(textBoxPort.Text, out port);
if (string.IsNullOrEmpty(serverName))
apiClient.BeginConnect(port);
_apiClient.BeginConnect(port);
else
apiClient.BeginConnect(serverName, port);
_apiClient.BeginConnect(serverName, port);
onConnected();
}
private void buttonDisconnect_Click(object sender, EventArgs e)
{
apiClient.BeginDisconnect();
_apiClient.BeginDisconnect();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
apiClient.BeginDisconnect();
_apiClient.BeginDisconnect();
}
private void sendOrder(string symbol, TradeOperation command, double volume, double price, int slippage, double stoploss, double takeprofit
@@ -223,7 +220,7 @@ namespace TestApiClientUI
int ticket = 0;
try
{
ticket = apiClient.OrderSend(symbol, command, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);
ticket = _apiClient.OrderSend(symbol, command, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);
}
catch (MtConnectionException ex)
{
@@ -315,7 +312,7 @@ namespace TestApiClientUI
foreach (var item in listBoxSendedOrders.SelectedItems)
{
int orderId = (int)item;
var result = apiClient.OrderClose(orderId, volume, price, slippage);
var result = _apiClient.OrderClose(orderId, volume, price, slippage);
if (result == true)
{
@@ -354,7 +351,7 @@ namespace TestApiClientUI
break;
}
var result = apiClient.OrderCloseBy(ticket, opposite, color);
var result = _apiClient.OrderCloseBy(ticket, opposite, color);
addToLog(string.Format("ClosedBy order result: {0}, ticketId = {1}, opposite {2}", result, ticket, opposite));
}
@@ -362,27 +359,27 @@ namespace TestApiClientUI
private void orderClosePrice()
{
var result = apiClient.OrderClosePrice();
var result = _apiClient.OrderClosePrice();
textBoxOrderPrice.Text = result.ToString();
addToLog(string.Format("OrderClosePrice result: {0}", result));
}
private void orderCloseTime()
{
var result = apiClient.OrderCloseTime();
var result = _apiClient.OrderCloseTime();
addToLog(string.Format("OrderCloseTime result: {0}", result));
}
private void orderComment()
{
var result = apiClient.OrderComment();
var result = _apiClient.OrderComment();
textBoxOrderComment.Text = result.ToString();
addToLog(string.Format("OrderComment result: {0}", result));
}
private void orderCommission()
{
var result = apiClient.OrderCommission();
var result = _apiClient.OrderCommission();
addToLog(string.Format("OrderCommission result: {0}", result));
}
@@ -392,7 +389,7 @@ namespace TestApiClientUI
{
int ticket = (int)listBoxSendedOrders.SelectedItems[0];
var result = apiClient.OrderDelete(ticket);
var result = _apiClient.OrderDelete(ticket);
addToLog(string.Format("Delete order result: {0}, ticketId = {1}", result, ticket));
}
@@ -400,19 +397,19 @@ namespace TestApiClientUI
private void orderExpiration()
{
var result = apiClient.OrderExpiration();
var result = _apiClient.OrderExpiration();
addToLog(string.Format("Expiration order result: {0}", result));
}
private void orderLots()
{
var result = apiClient.OrderLots();
var result = _apiClient.OrderLots();
addToLog(string.Format("Lots order result: {0}", result));
}
private void orderMagicNumber()
{
var result = apiClient.OrderMagicNumber();
var result = _apiClient.OrderMagicNumber();
addToLog(string.Format("MagicNumber order result: {0}", result));
}
@@ -447,7 +444,7 @@ namespace TestApiClientUI
break;
}
var result = apiClient.OrderModify(ticket, price, stoploss, takeprofit, expiration, arrow_color);
var result = _apiClient.OrderModify(ticket, price, stoploss, takeprofit, expiration, arrow_color);
addToLog(string.Format("OrderModify result: {0}", result));
}
@@ -455,24 +452,24 @@ namespace TestApiClientUI
private void orderOpenPrice()
{
var result = apiClient.OrderOpenPrice();
var result = _apiClient.OrderOpenPrice();
addToLog(string.Format("OrderOpenPrice result: {0}", result));
}
private void orderOpenTime()
{
var result = apiClient.OrderOpenTime();
var result = _apiClient.OrderOpenTime();
addToLog(string.Format("OpenTime order result: {0}", result));
}
private void orderPrint()
{
apiClient.OrderPrint();
_apiClient.OrderPrint();
}
private void orderProfit()
{
var result = apiClient.OrderProfit();
var result = _apiClient.OrderProfit();
addToLog(string.Format("Profit order result: {0}", result));
}
@@ -489,7 +486,7 @@ namespace TestApiClientUI
if (ticket >= 0)
{
var result = apiClient.OrderSelect(ticket, OrderSelectMode.SELECT_BY_POS);
var result = _apiClient.OrderSelect(ticket, OrderSelectMode.SELECT_BY_POS);
addToLog(string.Format("OrderSelect result: {0}", result));
}
@@ -497,59 +494,59 @@ namespace TestApiClientUI
private void ordersHistoryTotal()
{
var result = apiClient.OrdersHistoryTotal();
var result = _apiClient.OrdersHistoryTotal();
addToLog(string.Format("OrdersHistoryTotal result: {0}", result));
}
private void orderStopLoss()
{
var result = apiClient.OrderStopLoss();
var result = _apiClient.OrderStopLoss();
textBoxOrderStoploss.Text = result.ToString();
addToLog(string.Format("OrderStopLoss result: {0}", result));
}
private void ordersTotal()
{
var result = apiClient.OrdersTotal();
var result = _apiClient.OrdersTotal();
addToLog(string.Format("OrdersTotal result: {0}", result));
}
private void orderSwap()
{
var result = apiClient.OrderSwap();
var result = _apiClient.OrderSwap();
addToLog(string.Format("OrderSwap result: {0}", result));
}
private void orderSymbol()
{
var result = apiClient.OrderSymbol();
var result = _apiClient.OrderSymbol();
textBoxOrderSymbol.Text = result;
addToLog(string.Format("OrderSymbol result: {0}", result));
}
private void orderTakeProfit()
{
var result = apiClient.OrderTakeProfit();
var result = _apiClient.OrderTakeProfit();
textBoxOrderProffit.Text = result.ToString();
addToLog(string.Format("OrderTakeProfit result: {0}", result));
}
private void orderTicket()
{
var result = apiClient.OrderTicket();
var result = _apiClient.OrderTicket();
addToLog(string.Format("OrderTicket result: {0}", result));
}
private void orderType()
{
var result = apiClient.OrderType();
var result = _apiClient.OrderType();
comboBoxOrderCommand.SelectedIndex = (int)result;
addToLog(string.Format("OrderType result: {0}", result));
}
private void button2_Click(object sender, EventArgs e)
{
GroupOrderCommands[comboBoxSelectedCommand.SelectedIndex]();
_groupOrderCommands[comboBoxSelectedCommand.SelectedIndex]();
}
private void addToLog(string msg)
@@ -568,79 +565,79 @@ namespace TestApiClientUI
{
case 0:
{
var result = apiClient.GetLastError();
var result = _apiClient.GetLastError();
addToLog(string.Format("GetLastError result: {0}", result));
}
break;
case 1:
{
var result = apiClient.IsConnected();
var result = _apiClient.IsConnected();
addToLog(string.Format("IsConnected result: {0}", result));
}
break;
case 2:
{
var result = apiClient.IsDemo();
var result = _apiClient.IsDemo();
addToLog(string.Format("IsDemo result: {0}", result));
}
break;
case 3:
{
var result = apiClient.IsDllsAllowed();
var result = _apiClient.IsDllsAllowed();
addToLog(string.Format("IsDllsAllowed result: {0}", result));
}
break;
case 4:
{
var result = apiClient.IsExpertEnabled();
var result = _apiClient.IsExpertEnabled();
addToLog(string.Format("IsExpertEnabled result: {0}", result));
}
break;
case 5:
{
var result = apiClient.IsLibrariesAllowed();
var result = _apiClient.IsLibrariesAllowed();
addToLog(string.Format("IsLibrariesAllowed result: {0}", result));
}
break;
case 6:
{
var result = apiClient.IsOptimization();
var result = _apiClient.IsOptimization();
addToLog(string.Format("IsOptimization result: {0}", result));
}
break;
case 7:
{
var result = apiClient.IsStopped();
var result = _apiClient.IsStopped();
addToLog(string.Format("IsStopped result: {0}", result));
}
break;
case 8:
{
var result = apiClient.IsTesting();
var result = _apiClient.IsTesting();
addToLog(string.Format("IsTesting result: {0}", result));
}
break;
case 9:
{
var result = apiClient.IsTradeAllowed();
var result = _apiClient.IsTradeAllowed();
addToLog(string.Format("IsTradeAllowed result: {0}", result));
}
break;
case 10:
{
var result = apiClient.IsTradeContextBusy();
var result = _apiClient.IsTradeContextBusy();
addToLog(string.Format("IsTradeContextBusy result: {0}", result));
}
break;
case 11:
{
var result = apiClient.IsVisualMode();
var result = _apiClient.IsVisualMode();
addToLog(string.Format("IsVisualMode result: {0}", result));
}
break;
case 12:
{
var result = apiClient.UninitializeReason();
var result = _apiClient.UninitializeReason();
addToLog(string.Format("UninitializeReason result: {0}", result));
}
break;
@@ -648,7 +645,7 @@ namespace TestApiClientUI
{
int errorCode = -1;
int.TryParse(textBoxErrorCode.Text, out errorCode);
var result = apiClient.ErrorDescription(errorCode);
var result = _apiClient.ErrorDescription(errorCode);
addToLog(string.Format("ErrorDescription result: {0}", result));
}
break;
@@ -661,97 +658,97 @@ namespace TestApiClientUI
{
case 0:
{
var result = apiClient.AccountBalance();
var result = _apiClient.AccountBalance();
addToLog(string.Format("AccountBalance result: {0}", result));
}
break;
case 1:
{
var result = apiClient.AccountCredit();
var result = _apiClient.AccountCredit();
addToLog(string.Format("AccountCredit result: {0}", result));
}
break;
case 2:
{
var result = apiClient.AccountCompany();
var result = _apiClient.AccountCompany();
addToLog(string.Format("AccountCompany result: {0}", result));
}
break;
case 3:
{
var result = apiClient.AccountCurrency();
var result = _apiClient.AccountCurrency();
addToLog(string.Format("AccountCurrency result: {0}", result));
}
break;
case 4:
{
var result = apiClient.AccountEquity();
var result = _apiClient.AccountEquity();
addToLog(string.Format("AccountEquity result: {0}", result));
}
break;
case 5:
{
var result = apiClient.AccountFreeMargin();
var result = _apiClient.AccountFreeMargin();
addToLog(string.Format("AccountFreeMargin result: {0}", result));
}
break;
case 6:
{
var result = apiClient.AccountFreeMarginCheck(textBoxAccountInfoSymbol.Text, (TradeOperation)comboBoxAccountInfoCmd.SelectedIndex, int.Parse(textBoxAccountInfoVolume.Text));
var result = _apiClient.AccountFreeMarginCheck(textBoxAccountInfoSymbol.Text, (TradeOperation)comboBoxAccountInfoCmd.SelectedIndex, int.Parse(textBoxAccountInfoVolume.Text));
addToLog(string.Format("AccountFreeMarginCheck result: {0}", result));
}
break;
case 7:
{
var result = apiClient.AccountFreeMarginMode();
var result = _apiClient.AccountFreeMarginMode();
addToLog(string.Format("AccountFreeMarginMode result: {0}", result));
}
break;
case 8:
{
var result = apiClient.AccountLeverage();
var result = _apiClient.AccountLeverage();
addToLog(string.Format("AccountLeverage result: {0}", result));
}
break;
case 9:
{
var result = apiClient.AccountMargin();
var result = _apiClient.AccountMargin();
addToLog(string.Format("AccountMargin result: {0}", result));
}
break;
case 10:
{
var result = apiClient.AccountName();
var result = _apiClient.AccountName();
addToLog(string.Format("AccountName result: {0}", result));
}
break;
case 11:
{
var result = apiClient.AccountNumber();
var result = _apiClient.AccountNumber();
addToLog(string.Format("AccountNumber result: {0}", result));
}
break;
case 12:
{
var result = apiClient.AccountProfit();
var result = _apiClient.AccountProfit();
addToLog(string.Format("AccountProfit result: {0}", result));
}
break;
case 13:
{
var result = apiClient.AccountServer();
var result = _apiClient.AccountServer();
addToLog(string.Format("AccountServer result: {0}", result));
}
break;
case 14:
{
var result = apiClient.AccountStopoutLevel();
var result = _apiClient.AccountStopoutLevel();
addToLog(string.Format("AccountStopoutLevel result: {0}", result));
}
break;
case 15:
{
var result = apiClient.AccountStopoutMode();
var result = _apiClient.AccountStopoutMode();
addToLog(string.Format("AccountStopoutMode result: {0}", result));
}
break;
@@ -763,7 +760,7 @@ namespace TestApiClientUI
if (listBoxMarketInfo.SelectedIndex < 0)
return;
var result = apiClient.MarketInfo(txtMarketInfoSymbol.Text, (MarketInfoModeType)listBoxMarketInfo.SelectedIndex);
var result = _apiClient.MarketInfo(txtMarketInfoSymbol.Text, (MarketInfoModeType)listBoxMarketInfo.SelectedIndex);
addToLog(string.Format("MarketInfo result: {0}", result));
}
@@ -779,11 +776,11 @@ namespace TestApiClientUI
//for (int i = 0; i < COUNT; i++)
//{
// var price = apiClient.iOpen(symbol, ChartPeriod.PERIOD_M1, i);
// var price = _apiClient.iOpen(symbol, ChartPeriod.PERIOD_M1, i);
// openPriceList.Add(price);
//}
var prices = apiClient.iCloseArray(symbol, ChartPeriod.PERIOD_M1);
var prices = _apiClient.iCloseArray(symbol, ChartPeriod.PERIOD_M1);
openPriceList = new List<double>(prices);
@@ -803,14 +800,14 @@ namespace TestApiClientUI
private void button7_Click(object sender, EventArgs e)
{
string symbol = textBoxSelectedSymbol.Text;
var barCount = apiClient.iBars(symbol, ChartPeriod.PERIOD_M1);
var barCount = _apiClient.iBars(symbol, ChartPeriod.PERIOD_M1);
textBoxTimeframesCount.Text = barCount.ToString();
}
private void button8_Click(object sender, EventArgs e)
{
string symbol = textBoxSelectedSymbol.Text;
var prices = apiClient.iHighArray(symbol, ChartPeriod.PERIOD_M1);
var prices = _apiClient.iHighArray(symbol, ChartPeriod.PERIOD_M1);
var items = new List<double>(prices);
listBoxProceHistory.DataSource = items;
}
@@ -818,7 +815,7 @@ namespace TestApiClientUI
private void button9_Click(object sender, EventArgs e)
{
string symbol = textBoxSelectedSymbol.Text;
var prices = apiClient.iLowArray(symbol, ChartPeriod.PERIOD_M1);
var prices = _apiClient.iLowArray(symbol, ChartPeriod.PERIOD_M1);
var items = new List<double>(prices);
listBoxProceHistory.DataSource = items;
}
@@ -826,7 +823,7 @@ namespace TestApiClientUI
private void button10_Click(object sender, EventArgs e)
{
string symbol = textBoxSelectedSymbol.Text;
var prices = apiClient.iOpenArray(symbol, ChartPeriod.PERIOD_M1);
var prices = _apiClient.iOpenArray(symbol, ChartPeriod.PERIOD_M1);
var items = new List<double>(prices);
listBoxProceHistory.DataSource = items;
}
@@ -834,7 +831,7 @@ namespace TestApiClientUI
private void button11_Click(object sender, EventArgs e)
{
string symbol = textBoxSelectedSymbol.Text;
var prices = apiClient.iVolumeArray(symbol, ChartPeriod.PERIOD_M1);
var prices = _apiClient.iVolumeArray(symbol, ChartPeriod.PERIOD_M1);
var items = new List<double>(prices);
listBoxProceHistory.DataSource = items;
}
@@ -842,7 +839,7 @@ namespace TestApiClientUI
private void button12_Click(object sender, EventArgs e)
{
string symbol = textBoxSelectedSymbol.Text;
var times = apiClient.iTimeArray(symbol, ChartPeriod.PERIOD_M1);
var times = _apiClient.iTimeArray(symbol, ChartPeriod.PERIOD_M1);
var items = new List<DateTime>(times);
listBoxProceHistory.DataSource = items;
}
@@ -851,145 +848,93 @@ namespace TestApiClientUI
{
string symbol = textBoxSelectedSymbol.Text;
int[] param = {11, 12, 13};
var retVal = apiClient.iCustom(symbol, (int)ChartPeriod.PERIOD_H1, "Zigzag", param, 1, 0);
var retVal = _apiClient.iCustom(symbol, (int)ChartPeriod.PERIOD_H1, "Zigzag", param, 1, 0);
addToLog(string.Format("ICustom result: {0}", retVal));
}
private void button13_Click(object sender, EventArgs e)
{
var retVal = apiClient.TimeCurrent();
var retVal = _apiClient.TimeCurrent();
addToLog(string.Format("TimeCurrent result: {0}", retVal));
}
private void button14_Click(object sender, EventArgs e)
{
var retVal = apiClient.TimeLocal();
var retVal = _apiClient.TimeLocal();
addToLog(string.Format("TimeLocal result: {0}", retVal));
}
private void buttonRefreshRates_Click(object sender, EventArgs e)
{
var retVal = apiClient.RefreshRates();
var retVal = _apiClient.RefreshRates();
addToLog(string.Format("RefreshRates result: {0}", retVal));
}
private void button15_Click(object sender, EventArgs e)
{
for (var i = 0; i < 4; i++)
{
var ticket = i;
Task.Factory.StartNew(() =>
{
MtOrder order = null;
try
{
order = apiClient.GetOrder(ticket, OrderSelectMode.SELECT_BY_POS, OrderSelectSource.MODE_TRADES);
}
catch (MtConnectionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
}
catch (MtExecutionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
}
string result;
if (order != null)
{
result =
string.Format(
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}",
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime);
}
else
{
result = "Order is null";
}
addToLog(result);
});
}
}
private void button16_Click(object sender, EventArgs e)
{
var ticket = int.Parse(textBoxIndexTicket.Text);
var selectMode = (OrderSelectMode) comboBox1.SelectedIndex;
var selectSource = (OrderSelectSource) comboBox2.SelectedIndex;
MtOrder order = null;
try
{
order = apiClient.GetOrder(ticket, selectMode, selectSource);
}
catch (MtConnectionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
return;
}
catch (MtExecutionException ex)
{
addToLog("MtExecutionException: " + ex.Message + "; ErrorCode = " + ex.ErrorCode);
return;
}
if (order == null)
{
addToLog("Order is null");
return;
}
var result =
string.Format(
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}",
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime);
addToLog(result);
}
private void button17_Click(object sender, EventArgs e)
{
var selectSource = (OrderSelectSource)comboBox2.SelectedIndex;
IEnumerable<MtOrder> orders = null;
try
{
orders = apiClient.GetOrders(selectSource);
}
catch (MtConnectionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
return;
}
catch (MtExecutionException ex)
{
addToLog("MtExecutionException: " + ex.Message + "; ErrorCode = " + ex.ErrorCode);
return;
}
if (orders == null)
{
addToLog("Orders is null");
return;
}
foreach (var order in orders)
{
var result =
string.Format(
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}",
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime);
addToLog(result);
}
}
private void listBoxEventLog_MouseDoubleClick(object sender, MouseEventArgs e)
{
listBoxEventLog.Items.Clear();
}
private TResult Execute<TResult>(Func<TResult> func)
{
var result = default(TResult);
try
{
result = func();
}
catch (MtConnectionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
}
catch (MtExecutionException ex)
{
addToLog("MtExecutionException: " + ex.Message + "; ErrorCode = " + ex.ErrorCode);
}
return result;
}
//GetOrder
private void button16_Click(object sender, EventArgs e)
{
var ticket = int.Parse(textBoxIndexTicket.Text);
var selectMode = (OrderSelectMode) comboBox1.SelectedIndex;
var selectSource = (OrderSelectSource) comboBox2.SelectedIndex;
var order = Execute(() => _apiClient.GetOrder(ticket, selectMode, selectSource));
if (order != null)
{
var result =
string.Format(
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}",
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime);
addToLog(result);
}
}
//GetOrders
private void button17_Click(object sender, EventArgs e)
{
var selectSource = (OrderSelectSource)comboBox2.SelectedIndex;
var orders = Execute(() => _apiClient.GetOrders(selectSource)); ;
if (orders != null)
{
foreach (var order in orders)
{
var result =
string.Format(
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}",
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime);
addToLog(result);
}
}
}
//OrderSendBuy
private void button18_Click(object sender, EventArgs e)
{
var symbol = textBoxOrderSymbol.Text;
@@ -999,26 +944,13 @@ namespace TestApiClientUI
var slippage = (int)numericOrderSlippage.Value;
int ticket = 0;
try
{
ticket = apiClient.OrderSendBuy(symbol, volume, slippage);
}
catch (MtConnectionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
return;
}
catch (MtExecutionException ex)
{
addToLog("MtExecutionException: " + ex.Message + "; ErrorCode = " + ex.ErrorCode);
return;
}
var ticket = Execute(() => _apiClient.OrderSendBuy(symbol, volume, slippage));
addToLog(string.Format("Sended order result: ticketId = {0}, symbol = {1}, volume = {2}, slippage = {3}",
ticket, symbol, volume, slippage));
}
//OrderSendSell
private void button19_Click(object sender, EventArgs e)
{
var symbol = textBoxOrderSymbol.Text;
@@ -1028,24 +960,35 @@ namespace TestApiClientUI
var slippage = (int)numericOrderSlippage.Value;
int ticket = 0;
try
{
ticket = apiClient.OrderSendSell(symbol, volume, slippage);
}
catch (MtConnectionException ex)
{
addToLog("MtExecutionException: " + ex.Message);
return;
}
catch (MtExecutionException ex)
{
addToLog("MtExecutionException: " + ex.Message + "; ErrorCode = " + ex.ErrorCode);
return;
}
var ticket = Execute(() => _apiClient.OrderSendSell(symbol, volume, slippage));
addToLog(string.Format("Sended order result: ticketId = {0}, symbol = {1}, volume = {2}, slippage = {3}",
ticket, symbol, volume, slippage));
}
//OrderClose
private void button20_Click(object sender, EventArgs e)
{
var ticket = int.Parse(textBoxIndexTicket.Text);
var slippage = (int)numericOrderSlippage.Value;
var closed = false;
if (checkBox1.Checked)
{
closed = Execute(() => _apiClient.OrderClose(ticket, slippage));
}
else
{
double volume;
double.TryParse(textBoxOrderVolume.Text, out volume);
double price;
double.TryParse(textBoxOrderPrice.Text, out price);
closed = Execute(() => _apiClient.OrderClose(ticket, volume, price, slippage));
}
addToLog(string.Format("Close order result: {0}, ticket = {1}", closed, ticket));
}
}
}
BIN
View File
Binary file not shown.
+65 -232
View File
@@ -248,254 +248,31 @@ int executeCommand()
//NoCommand
break;
case 155: //SignalServiceCommand
case 155: //Request
{
if (!getStringValue(ExpertHandle, 0, requestValue))
{
PrintParamError("Signal");
PrintParamError("Request");
}
string response = "";
if (requestValue != "")
{
Print("executeCommand: incoming signal = ", requestValue);
Print("executeCommand: incoming request = ", requestValue);
response = OnRequest(requestValue);
}
sendStringResponse(ExpertHandle, response);
}
break;
case 1: // OrderSend
if (!getStringValue(ExpertHandle, 0, symbolValue))
{
PrintParamError("symbol");
}
if (!getIntValue(ExpertHandle, 1, cmdValue))
{
PrintParamError("cmd");
}
if (!getDoubleValue(ExpertHandle, 2, volumeValue))
{
PrintParamError("volume");
}
if (!getDoubleValue(ExpertHandle, 3, priceValue))
{
PrintParamError("price");
}
if (!getIntValue(ExpertHandle, 4, slippageValue))
{
PrintParamError("slippage");
}
if (!getDoubleValue(ExpertHandle, 5, stoplossValue))
{
PrintParamError("stoploss");
}
if (!getDoubleValue(ExpertHandle, 6, takeprofitValue))
{
PrintParamError("takeprofit");
}
if (!getStringValue(ExpertHandle, 7, commentValue))
{
PrintParamError("comment");
}
if (!getIntValue(ExpertHandle, 8, magicValue))
{
PrintParamError("magic");
}
if (!getIntValue(ExpertHandle, 9, expirationValue))
{
PrintParamError("expiration");
}
if (!getIntValue(ExpertHandle, 10, arrow_colorValue))
{
PrintParamError("arrow_color");
}
if (!sendIntResponse(ExpertHandle, OrderSend(symbolValue, cmdValue, volumeValue, priceValue
, slippageValue, stoplossValue, takeprofitValue
, commentValue, magicValue, expirationValue, arrow_colorValue)))
{
PrintResponseError("OrderSend");
}
break;
case 1001: // OrderSendBuy
if (!getStringValue(ExpertHandle, 0, symbolValue))
{
PrintParamError("symbol");
}
if (!getDoubleValue(ExpertHandle, 1, volumeValue))
{
PrintParamError("volume");
}
if (!getIntValue(ExpertHandle, 2, slippageValue))
{
PrintParamError("slippage");
}
if (!getDoubleValue(ExpertHandle, 3, stoplossValue))
{
PrintParamError("stoploss");
}
if (!getDoubleValue(ExpertHandle, 4, takeprofitValue))
{
PrintParamError("takeprofit");
}
if (!getStringValue(ExpertHandle, 5, commentValue))
{
PrintParamError("comment");
}
if (!getIntValue(ExpertHandle, 6, magicValue))
{
PrintParamError("magic");
}
priceValue = MarketInfo(symbolValue, MODE_ASK);
if (!sendIntResponse(ExpertHandle, OrderSend(symbolValue, OP_BUY, volumeValue, priceValue
, slippageValue, stoplossValue, takeprofitValue
, commentValue, magicValue)))
{
PrintResponseError("OrderSend");
}
break;
case 1002: // OrderSendSell
if (!getStringValue(ExpertHandle, 0, symbolValue))
{
PrintParamError("symbol");
}
if (!getDoubleValue(ExpertHandle, 1, volumeValue))
{
PrintParamError("volume");
}
if (!getIntValue(ExpertHandle, 2, slippageValue))
{
PrintParamError("slippage");
}
if (!getDoubleValue(ExpertHandle, 3, stoplossValue))
{
PrintParamError("stoploss");
}
if (!getDoubleValue(ExpertHandle, 4, takeprofitValue))
{
PrintParamError("takeprofit");
}
if (!getStringValue(ExpertHandle, 5, commentValue))
{
PrintParamError("comment");
}
if (!getIntValue(ExpertHandle, 6, magicValue))
{
PrintParamError("magic");
}
priceValue = MarketInfo(symbolValue, MODE_BID);
if (!sendIntResponse(ExpertHandle, OrderSend(symbolValue, OP_SELL, volumeValue, priceValue
, slippageValue, stoplossValue, takeprofitValue
, commentValue, magicValue)))
{
PrintResponseError("OrderSend");
}
break;
case 2: // OrderClose
if (!getIntValue(ExpertHandle, 0, ticketValue))
{
PrintParamError("ticket");
}
if (!getDoubleValue(ExpertHandle, 1, lotsValue))
{
PrintParamError("lots");
}
if (!getDoubleValue(ExpertHandle, 2, priceValue))
{
PrintParamError("price");
}
if (!getIntValue(ExpertHandle, 3, slippageValue))
{
PrintParamError("slippage");
}
if (!getIntValue(ExpertHandle, 4, colorValue))
{
PrintParamError("color");
}
if (!sendBooleanResponse(ExpertHandle, OrderClose(ticketValue, lotsValue, priceValue, slippageValue, colorValue)))
{
PrintResponseError("OrderClose");
}
break;
case 151: //OrderCloseAll
if (!sendBooleanResponse(ExpertHandle, OrderCloseAll()))
{
PrintResponseError("OrderCloseAll");
}
break;
case 152: //OrderCloseByCurrentPrice
if (!getIntValue(ExpertHandle, 0, ticketValue))
{
PrintParamError("ticket");
}
if (!getIntValue(ExpertHandle, 1, slippageValue))
{
PrintParamError("slippage");
}
lotsValue = 0;
if (OrderSelect(ticketValue, SELECT_BY_TICKET))
{
symbolValue = OrderSymbol();
lotsValue = OrderLots();
if (OrderType() == OP_SELL)
{
priceValue = MarketInfo(symbolValue, MODE_ASK);
}
else
{
priceValue = MarketInfo(symbolValue, MODE_BID);
}
}
if (!sendBooleanResponse(ExpertHandle, OrderClose(ticketValue, lotsValue, priceValue, slippageValue)))
{
PrintResponseError("OrderClose");
}
break;
break;
case 3: // OrderCloseBy
if (!getIntValue(ExpertHandle, 0, ticketValue))
@@ -3567,14 +3344,13 @@ bool OrderCloseAll()
{
if (OrderSelect(i, SELECT_BY_POS))
{
int type = OrderType();
int type = OrderType();
switch(type)
{
//Close opened long positions
case OP_BUY: OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
//Close opened short positions
case OP_SELL: OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
break;
}
@@ -3640,6 +3416,9 @@ string OnRequest(string json)
case 3: //OrderSend
response = ExecuteRequestOrderSend(jo);
break;
case 4: //OrderClose
response = ExecuteRequestOrderClose(jo);
break;
default:
Print("OnRequest [WARNING]: Unknown request type ", requestType);
response = CreateErrorResponse(-1, "Unknown request type");
@@ -3755,13 +3534,11 @@ string ExecuteRequestOrderSend(JSONObject *jo)
if (jvPrice != NULL)
{
price = jvPrice.getDouble();
Print("Take price from request ", price);
}
else
{
int mode = isLongOperation(cmd) ? MODE_ASK : MODE_BID;
price = MarketInfo(symbol, mode);
Print("Take price by mode ", mode, " and choosen price ", price);
}
JSONValue *jvSlippage = jo.getValue("Slippage");
@@ -3792,3 +3569,59 @@ string ExecuteRequestOrderSend(JSONObject *jo)
JSONValue* jvTicket = new JSONNumber(ticket);
return CreateSuccessResponse("Ticket", jvTicket);
}
string ExecuteRequestOrderClose(JSONObject *jo)
{
if (jo.getValue("Ticket") == NULL)
return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket");
int ticket = jo.getInt("Ticket");
double price;
JSONValue *jvPrice = jo.getValue("Price");
if (jvPrice != NULL)
{
price = jvPrice.getDouble();
}
else
{
if (OrderSelect(ticket, SELECT_BY_TICKET))
{
string symbol = OrderSymbol();
int mode = isLongOperation(OrderType()) ? MODE_BID : MODE_ASK;
price = MarketInfo(symbol, mode);
}
else
{
return CreateErrorResponse(-1, "Failed select order to get current price");
}
}
double lots;
JSONValue *jvLots = jo.getValue("Lots");
if (jvLots != NULL)
{
lots = jvLots.getDouble();
}
else
{
if (OrderSelect(ticket, SELECT_BY_TICKET))
{
lots = OrderLots();
}
else
{
return CreateErrorResponse(-1, "Failed select order to get lots of order");
}
}
JSONValue *jvSlippage = jo.getValue("Slippage");
double slippage = (jvSlippage != NULL) ? jvSlippage.getDouble() : 1;
JSONValue *jvArrowColor = jo.getValue("ArrowColor");
int arrowcolor = (jvArrowColor != NULL) ? jvArrowColor.getInt() : clrNONE;
if (!OrderClose(ticket, lots, price, slippage, arrowcolor))
return CreateErrorResponse(GetLastError(), "OrderClose failed");
return CreateSuccessResponse("", NULL);
}