mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-27 18:47:55 +00:00
Fixed Issue #4: Changed function iCustom to use request/respons pattern.
This commit is contained in:
@@ -78,6 +78,7 @@
|
||||
<Compile Include="OrderSelectSource.cs" />
|
||||
<Compile Include="Requests\GetOrderRequest.cs" />
|
||||
<Compile Include="Requests\GetOrdersRequest.cs" />
|
||||
<Compile Include="Requests\ICustomRequest.cs" />
|
||||
<Compile Include="Requests\OrderCloseByRequest.cs" />
|
||||
<Compile Include="Requests\OrderCloseRequest.cs" />
|
||||
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
||||
@@ -87,6 +88,7 @@
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Responses\GetOrderResponse.cs" />
|
||||
<Compile Include="Responses\GetOrdersResponse.cs" />
|
||||
<Compile Include="Responses\ICustomResponse.cs" />
|
||||
<Compile Include="Responses\OrderSendResponse.cs" />
|
||||
<Compile Include="Responses\ResponseBase.cs" />
|
||||
<Compile Include="SeriesIdentifier.cs" />
|
||||
|
||||
+42
-17
@@ -995,29 +995,54 @@ namespace MtApi
|
||||
|
||||
public double iCustom(string symbol, int timeframe, string name, int[] parameters, int mode, int shift)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbol, timeframe, name };
|
||||
int arraySize = parameters != null ? parameters.Length : 0;
|
||||
commandParameters.Add(arraySize);
|
||||
if (arraySize > 0)
|
||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
||||
{
|
||||
commandParameters.AddRange(parameters);
|
||||
}
|
||||
commandParameters.Add(mode);
|
||||
commandParameters.Add(shift);
|
||||
|
||||
return SendCommand<double>(MtCommandType.iCustom, commandParameters);
|
||||
Symbol = symbol,
|
||||
Timeframe = timeframe,
|
||||
Name = name,
|
||||
Mode = mode,
|
||||
Shift = shift,
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
return response != null ? response.Value : double.NaN;
|
||||
}
|
||||
|
||||
public double iCustom(string symbol, int timeframe, string name, double[] parameters, int mode, int shift)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbol, timeframe, name };
|
||||
int arraySize = parameters != null ? parameters.Length : 0;
|
||||
commandParameters.Add(arraySize);
|
||||
commandParameters.AddRange(parameters);
|
||||
commandParameters.Add(mode);
|
||||
commandParameters.Add(shift);
|
||||
//var commandParameters = new ArrayList { symbol, timeframe, name };
|
||||
//int arraySize = parameters != null ? parameters.Length : 0;
|
||||
//commandParameters.Add(arraySize);
|
||||
//commandParameters.AddRange(parameters);
|
||||
//commandParameters.Add(mode);
|
||||
//commandParameters.Add(shift);
|
||||
|
||||
return SendCommand<double>(MtCommandType.iCustom_d, commandParameters);
|
||||
//return SendCommand<double>(MtCommandType.iCustom_d, commandParameters);
|
||||
|
||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Timeframe = timeframe,
|
||||
Name = name,
|
||||
Mode = mode,
|
||||
Shift = shift,
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Double
|
||||
});
|
||||
return response != null ? response.Value : double.NaN;
|
||||
}
|
||||
|
||||
public double iCustom(string symbol, int timeframe, string name, int mode, int shift)
|
||||
{
|
||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Timeframe = timeframe,
|
||||
Name = name,
|
||||
Mode = mode,
|
||||
Shift = shift
|
||||
});
|
||||
return response != null ? response.Value : double.NaN;
|
||||
}
|
||||
|
||||
public double iDeMarker(string symbol, int timeframe, int period, int shift)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace MtApi.Requests
|
||||
{
|
||||
public class ICustomRequest : RequestBase
|
||||
{
|
||||
public enum ParametersType
|
||||
{
|
||||
Int = 0,
|
||||
Double = 1,
|
||||
String = 2,
|
||||
Boolean = 3
|
||||
}
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public int Timeframe { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Mode { get; set; }
|
||||
public int Shift { get; set; }
|
||||
public ArrayList Params { get; set; }
|
||||
public ParametersType ParamsType { get; set; }
|
||||
|
||||
public override RequestType RequestType
|
||||
{
|
||||
get { return RequestType.iCustom; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
OrderClose = 4,
|
||||
OrderCloseBy = 5,
|
||||
OrderDelete = 6,
|
||||
OrderModify = 7
|
||||
OrderModify = 7,
|
||||
iCustom = 8
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi.Responses
|
||||
{
|
||||
public class ICustomResponse: ResponseBase
|
||||
{
|
||||
public double Value { get; set; }
|
||||
}
|
||||
}
|
||||
+87
-59
@@ -48,6 +48,11 @@
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.tabControl1 = new System.Windows.Forms.TabControl();
|
||||
this.tabPage2 = new System.Windows.Forms.TabPage();
|
||||
this.button22 = new System.Windows.Forms.Button();
|
||||
this.button21 = new System.Windows.Forms.Button();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.textBoxOppositeTicket = new System.Windows.Forms.TextBox();
|
||||
this.button15 = new System.Windows.Forms.Button();
|
||||
this.checkBox1 = new System.Windows.Forms.CheckBox();
|
||||
this.button20 = new System.Windows.Forms.Button();
|
||||
this.button17 = new System.Windows.Forms.Button();
|
||||
@@ -109,7 +114,6 @@
|
||||
this.button5 = new System.Windows.Forms.Button();
|
||||
this.listBoxMarketInfo = new System.Windows.Forms.ListBox();
|
||||
this.tabPage5 = new System.Windows.Forms.TabPage();
|
||||
this.iCustomBtn = new System.Windows.Forms.Button();
|
||||
this.button12 = new System.Windows.Forms.Button();
|
||||
this.button11 = new System.Windows.Forms.Button();
|
||||
this.button10 = new System.Windows.Forms.Button();
|
||||
@@ -124,11 +128,9 @@
|
||||
this.tabPage6 = new System.Windows.Forms.TabPage();
|
||||
this.button14 = new System.Windows.Forms.Button();
|
||||
this.button13 = new System.Windows.Forms.Button();
|
||||
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.button22 = new System.Windows.Forms.Button();
|
||||
this.tabPage7 = new System.Windows.Forms.TabPage();
|
||||
this.iCustomBtn = new System.Windows.Forms.Button();
|
||||
this.button23 = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
@@ -141,6 +143,7 @@
|
||||
this.tabPage4.SuspendLayout();
|
||||
this.tabPage5.SuspendLayout();
|
||||
this.tabPage6.SuspendLayout();
|
||||
this.tabPage7.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBoxServerName
|
||||
@@ -301,6 +304,7 @@
|
||||
this.tabControl1.Controls.Add(this.tabPage4);
|
||||
this.tabControl1.Controls.Add(this.tabPage5);
|
||||
this.tabControl1.Controls.Add(this.tabPage6);
|
||||
this.tabControl1.Controls.Add(this.tabPage7);
|
||||
this.tabControl1.Location = new System.Drawing.Point(12, 147);
|
||||
this.tabControl1.Name = "tabControl1";
|
||||
this.tabControl1.SelectedIndex = 0;
|
||||
@@ -337,6 +341,53 @@
|
||||
this.tabPage2.Text = "Trade Operations";
|
||||
this.tabPage2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button22
|
||||
//
|
||||
this.button22.Location = new System.Drawing.Point(216, 293);
|
||||
this.button22.Name = "button22";
|
||||
this.button22.Size = new System.Drawing.Size(75, 23);
|
||||
this.button22.TabIndex = 19;
|
||||
this.button22.Text = "OrderModify";
|
||||
this.button22.UseVisualStyleBackColor = true;
|
||||
this.button22.Click += new System.EventHandler(this.button22_Click);
|
||||
//
|
||||
// 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);
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(219, 242);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(78, 13);
|
||||
this.label3.TabIndex = 17;
|
||||
this.label3.Text = "Opposite ticket";
|
||||
//
|
||||
// textBoxOppositeTicket
|
||||
//
|
||||
this.textBoxOppositeTicket.Location = new System.Drawing.Point(303, 239);
|
||||
this.textBoxOppositeTicket.Name = "textBoxOppositeTicket";
|
||||
this.textBoxOppositeTicket.Size = new System.Drawing.Size(100, 20);
|
||||
this.textBoxOppositeTicket.TabIndex = 16;
|
||||
this.textBoxOppositeTicket.Text = "0";
|
||||
//
|
||||
// button15
|
||||
//
|
||||
this.button15.Location = new System.Drawing.Point(410, 237);
|
||||
this.button15.Name = "button15";
|
||||
this.button15.Size = new System.Drawing.Size(92, 23);
|
||||
this.button15.TabIndex = 15;
|
||||
this.button15.Text = "OrderCloseBy";
|
||||
this.button15.UseVisualStyleBackColor = true;
|
||||
this.button15.Click += new System.EventHandler(this.button15_Click);
|
||||
//
|
||||
// checkBox1
|
||||
//
|
||||
this.checkBox1.AutoSize = true;
|
||||
@@ -1030,7 +1081,6 @@
|
||||
//
|
||||
// tabPage5
|
||||
//
|
||||
this.tabPage5.Controls.Add(this.iCustomBtn);
|
||||
this.tabPage5.Controls.Add(this.button12);
|
||||
this.tabPage5.Controls.Add(this.button11);
|
||||
this.tabPage5.Controls.Add(this.button10);
|
||||
@@ -1050,16 +1100,6 @@
|
||||
this.tabPage5.Text = "Timeframes";
|
||||
this.tabPage5.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// iCustomBtn
|
||||
//
|
||||
this.iCustomBtn.Location = new System.Drawing.Point(341, 215);
|
||||
this.iCustomBtn.Name = "iCustomBtn";
|
||||
this.iCustomBtn.Size = new System.Drawing.Size(75, 23);
|
||||
this.iCustomBtn.TabIndex = 14;
|
||||
this.iCustomBtn.Text = "ICustom";
|
||||
this.iCustomBtn.UseVisualStyleBackColor = true;
|
||||
this.iCustomBtn.Click += new System.EventHandler(this.iCustomBtn_Click);
|
||||
//
|
||||
// button12
|
||||
//
|
||||
this.button12.Location = new System.Drawing.Point(141, 201);
|
||||
@@ -1193,52 +1233,37 @@
|
||||
this.button13.UseVisualStyleBackColor = true;
|
||||
this.button13.Click += new System.EventHandler(this.button13_Click);
|
||||
//
|
||||
// button15
|
||||
// tabPage7
|
||||
//
|
||||
this.button15.Location = new System.Drawing.Point(410, 237);
|
||||
this.button15.Name = "button15";
|
||||
this.button15.Size = new System.Drawing.Size(92, 23);
|
||||
this.button15.TabIndex = 15;
|
||||
this.button15.Text = "OrderCloseBy";
|
||||
this.button15.UseVisualStyleBackColor = true;
|
||||
this.button15.Click += new System.EventHandler(this.button15_Click);
|
||||
this.tabPage7.Controls.Add(this.button23);
|
||||
this.tabPage7.Controls.Add(this.iCustomBtn);
|
||||
this.tabPage7.Location = new System.Drawing.Point(4, 22);
|
||||
this.tabPage7.Name = "tabPage7";
|
||||
this.tabPage7.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.tabPage7.Size = new System.Drawing.Size(682, 377);
|
||||
this.tabPage7.TabIndex = 7;
|
||||
this.tabPage7.Text = "Technical Indicators";
|
||||
this.tabPage7.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// textBoxOppositeTicket
|
||||
// iCustomBtn
|
||||
//
|
||||
this.textBoxOppositeTicket.Location = new System.Drawing.Point(303, 239);
|
||||
this.textBoxOppositeTicket.Name = "textBoxOppositeTicket";
|
||||
this.textBoxOppositeTicket.Size = new System.Drawing.Size(100, 20);
|
||||
this.textBoxOppositeTicket.TabIndex = 16;
|
||||
this.textBoxOppositeTicket.Text = "0";
|
||||
this.iCustomBtn.Location = new System.Drawing.Point(6, 6);
|
||||
this.iCustomBtn.Name = "iCustomBtn";
|
||||
this.iCustomBtn.Size = new System.Drawing.Size(107, 23);
|
||||
this.iCustomBtn.TabIndex = 15;
|
||||
this.iCustomBtn.Text = "iCustom (ZigZag)";
|
||||
this.iCustomBtn.UseVisualStyleBackColor = true;
|
||||
this.iCustomBtn.Click += new System.EventHandler(this.iCustomBtn_Click);
|
||||
//
|
||||
// label3
|
||||
// button23
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(219, 242);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(78, 13);
|
||||
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);
|
||||
//
|
||||
// button22
|
||||
//
|
||||
this.button22.Location = new System.Drawing.Point(216, 293);
|
||||
this.button22.Name = "button22";
|
||||
this.button22.Size = new System.Drawing.Size(75, 23);
|
||||
this.button22.TabIndex = 19;
|
||||
this.button22.Text = "OrderModify";
|
||||
this.button22.UseVisualStyleBackColor = true;
|
||||
this.button22.Click += new System.EventHandler(this.button22_Click);
|
||||
this.button23.Location = new System.Drawing.Point(6, 35);
|
||||
this.button23.Name = "button23";
|
||||
this.button23.Size = new System.Drawing.Size(107, 23);
|
||||
this.button23.TabIndex = 16;
|
||||
this.button23.Text = "iCustom (Parabolic)";
|
||||
this.button23.UseVisualStyleBackColor = true;
|
||||
this.button23.Click += new System.EventHandler(this.button23_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
@@ -1274,6 +1299,7 @@
|
||||
this.tabPage5.ResumeLayout(false);
|
||||
this.tabPage5.PerformLayout();
|
||||
this.tabPage6.ResumeLayout(false);
|
||||
this.tabPage7.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@@ -1362,7 +1388,6 @@
|
||||
private System.Windows.Forms.Button button11;
|
||||
private System.Windows.Forms.Button button12;
|
||||
private System.Windows.Forms.ColumnHeader colFeedCount;
|
||||
private System.Windows.Forms.Button iCustomBtn;
|
||||
private System.Windows.Forms.TabPage tabPage6;
|
||||
private System.Windows.Forms.Button button13;
|
||||
private System.Windows.Forms.Button button14;
|
||||
@@ -1381,6 +1406,9 @@
|
||||
private System.Windows.Forms.Button button15;
|
||||
private System.Windows.Forms.Button button21;
|
||||
private System.Windows.Forms.Button button22;
|
||||
private System.Windows.Forms.TabPage tabPage7;
|
||||
private System.Windows.Forms.Button iCustomBtn;
|
||||
private System.Windows.Forms.Button button23;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using MtApi;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
|
||||
namespace TestApiClientUI
|
||||
{
|
||||
@@ -765,14 +766,6 @@ namespace TestApiClientUI
|
||||
listBoxProceHistory.DataSource = items;
|
||||
}
|
||||
|
||||
private void iCustomBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
string symbol = textBoxSelectedSymbol.Text;
|
||||
int[] param = {11, 12, 13};
|
||||
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();
|
||||
@@ -1002,5 +995,30 @@ namespace TestApiClientUI
|
||||
|
||||
AddToLog(string.Format("Modify order result: {0}, ticket = {1}", modified, ticket));
|
||||
}
|
||||
|
||||
//iCustom
|
||||
private async void iCustomBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
string symbol = "EURUSD";
|
||||
var timeframe = ChartPeriod.PERIOD_H1;
|
||||
string name = "ZigZag";
|
||||
int[] parameters = { 12, 5, 4 };
|
||||
int mode = 0;
|
||||
int shift = 0;
|
||||
var retVal = await Execute(() => _apiClient.iCustom(symbol, (int)timeframe, name, parameters, mode, shift));
|
||||
AddToLog(string.Format("ICustom result: {0}", retVal));
|
||||
}
|
||||
|
||||
private async void button23_Click(object sender, EventArgs e)
|
||||
{
|
||||
string symbol = "EURUSD";
|
||||
var timeframe = ChartPeriod.PERIOD_H1;
|
||||
string name = "Parabolic";
|
||||
double[] parameters = { 0.02, 0.2 };
|
||||
int mode = 0;
|
||||
int shift = 1;
|
||||
var retVal = await Execute(() => _apiClient.iCustom(symbol, (int)timeframe, name, parameters, mode, shift));
|
||||
AddToLog(string.Format("ICustom result: {0}", retVal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
+130
-16
@@ -3408,25 +3408,28 @@ string OnRequest(string json)
|
||||
switch(requestType)
|
||||
{
|
||||
case 1: //GetOrder
|
||||
response = ExecuteRequestGetOrder(jo);
|
||||
response = ExecuteRequest_GetOrder(jo);
|
||||
break;
|
||||
case 2: //GetOrders
|
||||
response = ExecuteRequestGetOrders(jo);
|
||||
response = ExecuteRequest_GetOrders(jo);
|
||||
break;
|
||||
case 3: //OrderSend
|
||||
response = ExecuteRequestOrderSend(jo);
|
||||
response = ExecuteRequest_OrderSend(jo);
|
||||
break;
|
||||
case 4: //OrderClose
|
||||
response = ExecuteRequestOrderClose(jo);
|
||||
response = ExecuteRequest_OrderClose(jo);
|
||||
break;
|
||||
case 5: //OrderCloseBy
|
||||
response = ExecuteRequestOrderCloseBy(jo);
|
||||
response = ExecuteRequest_OrderCloseBy(jo);
|
||||
break;
|
||||
case 6: //OrderDelete
|
||||
response = ExecuteRequestOrderDelete(jo);
|
||||
response = ExecuteRequest_OrderDelete(jo);
|
||||
break;
|
||||
case 7: //OrderModify
|
||||
response = ExecuteRequestOrderModify(jo);
|
||||
response = ExecuteRequest_OrderModify(jo);
|
||||
break;
|
||||
case 8: //iCustom
|
||||
response = ExecuteRequest_iCustom(jo);
|
||||
break;
|
||||
default:
|
||||
Print("OnRequest [WARNING]: Unknown request type ", requestType);
|
||||
@@ -3488,7 +3491,7 @@ JSONObject* GetOrderJson(int index, int select, int pool)
|
||||
return joOrder;
|
||||
}
|
||||
|
||||
string ExecuteRequestGetOrder(JSONObject *jo)
|
||||
string ExecuteRequest_GetOrder(JSONObject *jo)
|
||||
{
|
||||
int index = jo.getInt("Index");
|
||||
int select = jo.getInt("Select");
|
||||
@@ -3502,7 +3505,7 @@ string ExecuteRequestGetOrder(JSONObject *jo)
|
||||
return CreateSuccessResponse("Order", joOrder);
|
||||
}
|
||||
|
||||
string ExecuteRequestGetOrders(JSONObject *jo)
|
||||
string ExecuteRequest_GetOrders(JSONObject *jo)
|
||||
{
|
||||
int pool = jo.getInt("Pool");
|
||||
|
||||
@@ -3511,9 +3514,9 @@ string ExecuteRequestGetOrders(JSONObject *jo)
|
||||
int total = (pool == MODE_HISTORY) ? OrdersHistoryTotal() : OrdersTotal();
|
||||
|
||||
JSONArray* joOrders = new JSONArray();
|
||||
for(int pos = 0; pos < total; pos++)
|
||||
for(int pos = 0; pos < 10000; pos++)
|
||||
{
|
||||
JSONObject* joOrder = GetOrderJson(pos, SELECT_BY_POS, pool);
|
||||
JSONObject* joOrder = GetOrderJson(0, SELECT_BY_POS, pool);
|
||||
if (joOrder == NULL)
|
||||
return CreateErrorResponse(GetLastError(), "GetOrders failed");
|
||||
joOrders.put(pos, joOrder);
|
||||
@@ -3529,7 +3532,7 @@ bool isLongOperation(int operation)
|
||||
return false;
|
||||
}
|
||||
|
||||
string ExecuteRequestOrderSend(JSONObject *jo)
|
||||
string ExecuteRequest_OrderSend(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("Symbol") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Symbol");
|
||||
@@ -3584,7 +3587,7 @@ string ExecuteRequestOrderSend(JSONObject *jo)
|
||||
return CreateSuccessResponse("Ticket", jvTicket);
|
||||
}
|
||||
|
||||
string ExecuteRequestOrderClose(JSONObject *jo)
|
||||
string ExecuteRequest_OrderClose(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("Ticket") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket");
|
||||
@@ -3640,7 +3643,7 @@ string ExecuteRequestOrderClose(JSONObject *jo)
|
||||
return CreateSuccessResponse("", NULL);
|
||||
}
|
||||
|
||||
string ExecuteRequestOrderCloseBy(JSONObject *jo)
|
||||
string ExecuteRequest_OrderCloseBy(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("Ticket") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket");
|
||||
@@ -3658,7 +3661,7 @@ string ExecuteRequestOrderCloseBy(JSONObject *jo)
|
||||
return CreateSuccessResponse("", NULL);
|
||||
}
|
||||
|
||||
string ExecuteRequestOrderDelete(JSONObject *jo)
|
||||
string ExecuteRequest_OrderDelete(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("Ticket") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket");
|
||||
@@ -3673,7 +3676,7 @@ string ExecuteRequestOrderDelete(JSONObject *jo)
|
||||
return CreateSuccessResponse("", NULL);
|
||||
}
|
||||
|
||||
string ExecuteRequestOrderModify(JSONObject *jo)
|
||||
string ExecuteRequest_OrderModify(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("Ticket") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket");
|
||||
@@ -3698,4 +3701,115 @@ string ExecuteRequestOrderModify(JSONObject *jo)
|
||||
if (!OrderModify(ticket, price, stoploss, takeprofit, expiration, arrowcolor))
|
||||
return CreateErrorResponse(GetLastError(), "OrderModify failed");
|
||||
return CreateSuccessResponse("", NULL);
|
||||
}
|
||||
|
||||
string ExecuteRequest_iCustom(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("Symbol") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Symbol");
|
||||
if (jo.getValue("Timeframe") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Timeframe");
|
||||
if (jo.getValue("Name") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Name");
|
||||
if (jo.getValue("Mode") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Mode");
|
||||
if (jo.getValue("Shift") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter Shift");
|
||||
|
||||
string symbol = jo.getString("Symbol");
|
||||
int timeframe = jo.getInt("Timeframe");
|
||||
string name = jo.getString("Name");
|
||||
int mode = jo.getInt("Mode");
|
||||
int shift = jo.getInt("Shift");
|
||||
|
||||
if (jo.getValue("Params") == NULL)
|
||||
{
|
||||
result = iCustom(symbol, timeframe, name, mode, shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
JSONArray *jaParams = jo.getArray("Params");
|
||||
int size = jaParams.size();
|
||||
|
||||
if (size < 0 || size > 10)
|
||||
return CreateErrorResponse(-1, "Parameter's count is out of range.");
|
||||
|
||||
if (jo.getValue("ParamsType") == NULL)
|
||||
return CreateErrorResponse(-1, "Undefinded mandatory parameter ParamsType");
|
||||
|
||||
int paramsType = jo.getInt("ParamsType");
|
||||
switch (paramsType)
|
||||
{
|
||||
case 0: //Int
|
||||
{
|
||||
int intParams[];
|
||||
ArrayResize(intParams, size);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
intParams[i] = jaParams.getInt(i);
|
||||
}
|
||||
result = iCustomT(symbol, timeframe, name, intParams, size, mode, shift);
|
||||
}
|
||||
break;
|
||||
case 1: //Double
|
||||
{
|
||||
int doubleParams[];
|
||||
ArrayResize(doubleParams, size);
|
||||
result = iCustomT(symbol, timeframe, name, doubleParams, size, mode, shift);
|
||||
}
|
||||
break;
|
||||
case 2: //String
|
||||
{
|
||||
string stringParams[];
|
||||
ArrayResize(stringParams, size);
|
||||
result = iCustomT(symbol, timeframe, name, stringParams, size, mode, shift);
|
||||
}
|
||||
break;
|
||||
case 3: //Boolean
|
||||
{
|
||||
string boolParams[];
|
||||
ArrayResize(boolParams, size);
|
||||
result = iCustomT(symbol, timeframe, name, boolParams, size, mode, shift);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return CreateErrorResponse(-1, "Unsupported type of iCustom parameters.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return CreateSuccessResponse("Value", new JSONNumber(result));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double iCustomT(string symbol, int timeframe, string name, T &p[], int count, int mode, int shift)
|
||||
{
|
||||
switch(count)
|
||||
{
|
||||
case 0:
|
||||
return iCustom(symbol, timeframe, name, mode, shift);
|
||||
break;
|
||||
case 1:
|
||||
return iCustom(symbol, timeframe, name, p[0], mode, shift);
|
||||
case 2:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], mode, shift);
|
||||
case 3:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], mode, shift);
|
||||
case 4:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], mode, shift);
|
||||
case 5:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], p[4], mode, shift);
|
||||
case 6:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], p[4], p[5], mode, shift);
|
||||
case 7:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], p[4], p[5], p[6], mode, shift);
|
||||
case 8:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], mode, shift);
|
||||
case 9:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], mode, shift);
|
||||
case 10:
|
||||
return iCustom(symbol, timeframe, name, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], mode, shift);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user