From 7abb4d3b5e146c9cd7d97f254596538bcf155317 Mon Sep 17 00:00:00 2001 From: DW Date: Wed, 27 Sep 2017 15:38:54 +0300 Subject: [PATCH] Issue #41: Partialy implemented object functions on client side --- MtApi5/Mt5CommandType.cs | 28 ++++++-- MtApi5/Mt5Enums.cs | 15 ++++- MtApi5/MtApi5Client.cs | 136 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 169 insertions(+), 10 deletions(-) diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs index 8a8aab49..957720e7 100755 --- a/MtApi5/Mt5CommandType.cs +++ b/MtApi5/Mt5CommandType.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi5 +namespace MtApi5 { internal enum Mt5CommandType { @@ -115,6 +110,25 @@ namespace MtApi5 //Requests MtRequest = 155, - PositionSelectByTicket = 69 + PositionSelectByTicket = 69, + + ObjectCreate = 70, + ObjectName = 71, + ObjectDelete = 72, + ObjectsDeleteAll = 73, + ObjectFind = 74, + ObjectGetTimeByValue = 75, + ObjectGetValueByTime = 76, + ObjectMove = 77, + ObjectsTotal = 78, + ObjectGetDouble = 79, + ObjectGetInteger = 80, + ObjectGetString = 81, + ObjectSetDouble = 82, + ObjectSetInteger = 83, + ObjectSetString = 84, + TextSetFont = 85, + TextOut = 86, + TextGetSize = 87 } } diff --git a/MtApi5/Mt5Enums.cs b/MtApi5/Mt5Enums.cs index d69105b2..9ff57384 100755 --- a/MtApi5/Mt5Enums.cs +++ b/MtApi5/Mt5Enums.cs @@ -657,4 +657,17 @@ } #endregion // Object Types -} + + #region Object Properties + + public enum ENUM_OBJECT_PROPERTY_DOUBLE + { + OBJPROP_PRICE = 9, // Price coordinate + OBJPROP_LEVELVALUE = 204, // Level value + OBJPROP_SCALE = 1006, // Scale (properties of Gann objects and Fibonacci Arcs) + OBJPROP_ANGLE = 1007, // Angle. For the objects with no angle specified, created from a program, the value is equal to EMPTY_VALUE + OBJPROP_DEVIATION = 1010 // Deviation for the Standard Deviation Channel + } + + #endregion + } diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 449047a1..29525ae6 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -1419,9 +1419,141 @@ namespace MtApi5 return SendCommand(Mt5CommandType.Print, commandParameters); } - #endregion + #endregion // Common Functions - #endregion + #region Object Functions + + /// + ///The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow. + /// + ///Chart identifier. 0 means the current chart. + ///Name of the object. The name must be unique within a chart, including its subwindows. + ///Object type. The value can be one of the values of the ENUM_OBJECT enumeration. + ///Number of the chart subwindow. 0 means the main chart window. The specified subwindow must exist, otherwise the function returns false. + ///The time coordinate of the first anchor. + ///The price coordinate of the first anchor point. + public bool ObjectCreate(long chartId, string name, ENUM_OBJECT type, int nwin, DateTime time, double price) + { + var commandParameters = new ArrayList { chartId, name, (int)type, nwin, Mt5TimeConverter.ConvertToMtTime(time), price }; + return SendCommand(Mt5CommandType.ObjectCreate, commandParameters); + } + + /// + ///The function returns the name of the corresponding object in the specified chart, in the specified subwindow, of the specified type. + /// + ///Chart identifier. 0 means the current chart. + ///Ordinal number of the object according to the specified filter by the number and type of the subwindow. + ///umber of the chart subwindow. 0 means the main chart window, -1 means all the subwindows of the chart, including the main window. + ///Type of the object. The value can be one of the values of the ENUM_OBJECT enumeration. -1 means all types. + public string ObjectName(long chartId, int pos, int subWindow = -1, int type = -1) + { + var commandParameters = new ArrayList { chartId, pos, subWindow, type }; + return SendCommand(Mt5CommandType.ObjectName, commandParameters); + } + + /// + ///The function removes the object with the specified name from the specified chart. + /// + ///Chart identifier. 0 means the current chart. + ///Name of object to be deleted. + public bool ObjectDelete(long chartId, string name) + { + var commandParameters = new ArrayList { chartId, name }; + return SendCommand(Mt5CommandType.ObjectDelete, commandParameters); + } + + /// + ///The function removes the object with the specified name from the specified chart. + /// + ///Chart identifier. 0 means the current chart. + ///Number of the chart subwindow. 0 means the main chart window, -1 means all the subwindows of the chart, including the main window. + ///Type of the object. The value can be one of the values of the ENUM_OBJECT enumeration. -1 means all types. + public int ObjectsDeleteAll(long chartId, int subWindow = -1, int type = -1) + { + var commandParameters = new ArrayList { chartId, subWindow, type }; + return SendCommand(Mt5CommandType.ObjectsDeleteAll, commandParameters); + } + + /// + ///The function searches for an object with the specified name in the chart with the specified ID. + /// + ///Chart identifier. 0 means the current chart. + ///The name of the searched object. + public int ObjectFind(long chartId, string name) + { + var commandParameters = new ArrayList { chartId, name }; + return SendCommand(Mt5CommandType.ObjectFind, commandParameters); + } + + /// + ///The function returns the time value for the specified price value of the specified object. + /// + ///Chart identifier. 0 means the current chart. + ///Name of the object. + ///Price value. + ///Line identifier. + public DateTime ObjectGetTimeByValue(long chartId, string name, double value, int lineId) + { + var commandParameters = new ArrayList { chartId, name, value, lineId }; + var res = SendCommand(Mt5CommandType.ObjectGetTimeByValue, commandParameters); + return Mt5TimeConverter.ConvertFromMtTime(res); + } + + /// + ///The function returns the price value for the specified time value of the specified object. + /// + ///Chart identifier. 0 means the current chart. + ///Name of the object. + ///Time value. + ///Line identifier. + public double ObjectGetValueByTime(long chartId, string name, DateTime time, int lineId) + { + var commandParameters = new ArrayList { chartId, name, Mt5TimeConverter.ConvertToMtTime(time), lineId }; + return SendCommand(Mt5CommandType.ObjectGetValueByTime, commandParameters); + } + + /// + ///The function changes coordinates of the specified anchor point of the object. + /// + ///Chart identifier. 0 means the current chart. + ///Name of the object. + ///Index of the anchor point. The number of anchor points depends on the type of object. + ///Time coordinate of the selected anchor point. + ///Price coordinate of the selected anchor point. + public bool ObjectMove(long chartId, string name, int pointIndex, DateTime time, double price) + { + var commandParameters = new ArrayList { chartId, name, pointIndex, Mt5TimeConverter.ConvertToMtTime(time), price }; + return SendCommand(Mt5CommandType.ObjectMove, commandParameters); + } + + /// + ///The function returns the number of objects in the specified chart, specified subwindow, of the specified type. + /// + ///Chart identifier. 0 means the current chart. + ///Number of the chart subwindow. 0 means the main chart window, -1 means all the subwindows of the chart, including the main window. + ///Type of the object. The value can be one of the values of the ENUM_OBJECT enumeration. -1 means all types. + public int ObjectsTotal(long chartId, int subWindow = -1, int type = -1) + + { + var commandParameters = new ArrayList { chartId, subWindow, type }; + return SendCommand(Mt5CommandType.ObjectsTotal, commandParameters); + } + + /// + ///The function returns the number of objects in the specified chart, specified subwindow, of the specified type. + /// + ///Chart identifier. 0 means the current chart. + ///Name of the object. + ///ID of the object property. The value can be one of the values of the ENUM_OBJECT_PROPERTY_DOUBLE enumeration. + ///The value of the property. + public bool ObjectSetDouble(long chartId, string name, ENUM_OBJECT_PROPERTY_DOUBLE propId, double propValue) + + { + var commandParameters = new ArrayList { chartId, name, (int)propId, propValue }; + return SendCommand(Mt5CommandType.ObjectsTotal, commandParameters); + } + + #endregion //Object Functions #region Properties ///