Implemented functions ChartTimePriceToXY, ChartXYToTimePrice (MT5)

This commit is contained in:
vdemydiuk
2018-03-13 17:28:21 +02:00
parent f3a3a582fd
commit 16f454ca61
12 changed files with 238 additions and 47 deletions
+2 -2
View File
@@ -187,8 +187,8 @@ namespace MtApi5
ChartApplyTemplate = 236,
ChartSaveTemplate = 237,
ChartWindowFind = 238,
ChartTimePriceToXY = 239,
ChartXYToTimePrice = 240,
//ChartTimePriceToXY = 239,
//ChartXYToTimePrice = 240,
ChartOpen = 241,
ChartFirst = 242,
ChartNext = 243,
+4
View File
@@ -73,6 +73,10 @@
<Compile Include="Events\Mt5EventTypes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Mt5Quote.cs" />
<Compile Include="Requests\ChartTimePriceToXyRequest.cs" />
<Compile Include="Requests\ChartTimePriceToXyResult.cs" />
<Compile Include="Requests\ChartXyToTimePriceRequest.cs" />
<Compile Include="Requests\ChartXyToTimePriceResult.cs" />
<Compile Include="Requests\CopyTicksRequest.cs" />
<Compile Include="Requests\ICustomRequest.cs" />
<Compile Include="Requests\IndicatorCreateRequest.cs" />
+20 -34
View File
@@ -1578,22 +1578,17 @@ namespace MtApi5
///</returns>
public bool ChartTimePriceToXY(long chartId, int subWindow, DateTime? time, double price, out int x, out int y)
{
var commandParameters = new ArrayList { chartId, subWindow, Mt5TimeConverter.ConvertToMtTime(time), price };
var str = SendCommand<string>(Mt5CommandType.ChartTimePriceToXY, commandParameters);
var res = false;
x = 0;
y = 0;
if (!string.IsNullOrEmpty(str) && str.Contains(";"))
{
var values = str.Split(';');
if (values.Length > 1)
var result = SendRequest<ChartTimePriceToXyResult>(new ChartTimePriceToXyRequest
{
int.TryParse(values[0], out x);
int.TryParse(values[1], out y);
res = true;
}
}
return res;
ChartId = chartId,
SubWindow = subWindow,
Time = time,
Price = price
});
x = result?.X ?? 0;
y = result?.Y ?? 0;
return result?.RetVal ?? false;
}
///<summary>
@@ -1610,26 +1605,17 @@ namespace MtApi5
///</returns>
public bool ChartXYToTimePrice(long chartId, int x, int y, out int subWindow, out DateTime? time, out double price)
{
var commandParameters = new ArrayList { chartId, x, y };
var str = SendCommand<string>(Mt5CommandType.ChartXYToTimePrice, commandParameters);
var res = false;
subWindow = 0;
time = null;
price = double.NaN;
if (!string.IsNullOrEmpty(str) && str.Contains(";"))
var result = SendRequest<ChartXyToTimePriceResult>(new ChartXyToTimePriceRequest
{
var values = str.Split(';');
if (values.Length > 2)
{
int.TryParse(values[0], out subWindow);
int mt4Time;
int.TryParse(values[1], out mt4Time);
time = Mt5TimeConverter.ConvertFromMtTime(mt4Time);
double.TryParse(values[2], out price);
res = true;
}
}
return res;
ChartId = chartId,
X = x,
Y = y
});
subWindow = result?.SubWindow ?? 0;
time = result?.Time;
price = result?.Price ?? double.NaN;
return result?.RetVal ?? false;
}
///<summary>
@@ -0,0 +1,16 @@
using System;
namespace MtApi5.Requests
{
internal class ChartTimePriceToXyRequest : RequestBase
{
public override RequestType RequestType => RequestType.ChartTimePriceToXY;
public long ChartId { get; set; }
public int SubWindow { get; set; }
public DateTime? Time { get; set; }
public double Price { get; set; }
public int MtTime => Mt5TimeConverter.ConvertToMtTime(Time);
}
}
@@ -0,0 +1,9 @@
namespace MtApi5.Requests
{
internal class ChartTimePriceToXyResult
{
public bool RetVal { get; set; }
public int X { get; set; }
public int Y { get; set; }
}
}
@@ -0,0 +1,13 @@
using System;
namespace MtApi5.Requests
{
internal class ChartXyToTimePriceRequest : RequestBase
{
public override RequestType RequestType => RequestType.ChartXYToTimePrice;
public long ChartId { get; set; }
public int X { get; set; }
public int Y { get; set; }
}
}
@@ -0,0 +1,14 @@
using System;
namespace MtApi5.Requests
{
internal class ChartXyToTimePriceResult
{
public bool RetVal { get; set; }
public int SubWindow { get; set; }
public DateTime? Time => Mt5TimeConverter.ConvertFromMtTime(MtTime);
public double Price { get; set; }
public int MtTime { get; set; }
}
}
+3 -1
View File
@@ -12,6 +12,8 @@ namespace MtApi5.Requests
OrderCheck = 5,
MarketBookGet = 6,
IndicatorCreate = 7,
SymbolInfoString = 8
SymbolInfoString = 8,
ChartTimePriceToXY = 9,
ChartXYToTimePrice = 10
}
}