mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-27 18:47:55 +00:00
Implemented functions ChartTimePriceToXY, ChartXYToTimePrice (MT5)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace MtApi5.Requests
|
||||
OrderCheck = 5,
|
||||
MarketBookGet = 6,
|
||||
IndicatorCreate = 7,
|
||||
SymbolInfoString = 8
|
||||
SymbolInfoString = 8,
|
||||
ChartTimePriceToXY = 9,
|
||||
ChartXYToTimePrice = 10
|
||||
}
|
||||
}
|
||||
@@ -480,12 +480,29 @@
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Chart Functions">
|
||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}" Margin="1"/>
|
||||
<Button Command="{Binding ChartOpenCommand}" Content="ChartOpen"/>
|
||||
<Button Command="{Binding ChartApplyTemplateCommand}" Content="ChartApplyTemplate"/>
|
||||
<Button Command="{Binding ChartSaveTemplateCommand}" Content="ChartSaveTemplate"/>
|
||||
</WrapPanel>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5">
|
||||
<TextBlock Text="Symbol" VerticalAlignment="Center" Margin="2"/>
|
||||
<TextBox Width="100" Text="{Binding ChartFunctionsSymbolValue}" Margin="2"/>
|
||||
</StackPanel>
|
||||
|
||||
<WrapPanel Grid.Row="1" Orientation="Horizontal" Margin="5">
|
||||
<Button Command="{Binding ChartOpenCommand}" Content="ChartOpen" Margin="2"/>
|
||||
<Button Command="{Binding ChartTimePriceToXYCommand}" Content="ChartTimePriceToXY" Margin="2"/>
|
||||
<Button Command="{Binding ChartXYToTimePriceCommand}" Content="ChartXYToTimePrice" Margin="2"/>
|
||||
</WrapPanel>
|
||||
|
||||
<WrapPanel Grid.Row="2" VerticalAlignment="Top" Margin="5">
|
||||
<Button Command="{Binding ChartApplyTemplateCommand}" Content="ChartApplyTemplate" Margin="2"/>
|
||||
<Button Command="{Binding ChartSaveTemplateCommand}" Content="ChartSaveTemplate" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Time and Date">
|
||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||
|
||||
@@ -76,6 +76,8 @@ namespace MtApi5TestClient
|
||||
public DelegateCommand TimeCurrentCommand { get; private set; }
|
||||
|
||||
public DelegateCommand ChartOpenCommand { get; private set; }
|
||||
public DelegateCommand ChartTimePriceToXYCommand { get; private set; }
|
||||
public DelegateCommand ChartXYToTimePriceCommand { get; private set; }
|
||||
public DelegateCommand ChartApplyTemplateCommand { get; private set; }
|
||||
public DelegateCommand ChartSaveTemplateCommand { get; private set; }
|
||||
|
||||
@@ -88,15 +90,19 @@ namespace MtApi5TestClient
|
||||
private async void ExecuteChartOpen(object o)
|
||||
{
|
||||
AddLog("Executed #1");
|
||||
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
||||
if (string.IsNullOrEmpty(ChartFunctionsSymbolValue))
|
||||
{
|
||||
AddLog("ChartOpen [ERROR]: Symbol is not defined!");
|
||||
return;
|
||||
}
|
||||
|
||||
AddLog($"Executed #2 s:{TimeSeriesValues?.SymbolValue}");
|
||||
AddLog($"Executed #2 s:{ChartFunctionsSymbolValue}");
|
||||
|
||||
|
||||
var result = await Execute(() =>
|
||||
{
|
||||
var SymbolAddReturn = _mtApiClient.SymbolSelect(TimeSeriesValues?.SymbolValue, true);
|
||||
var ChartId = _mtApiClient.ChartOpen(TimeSeriesValues?.SymbolValue, TimeSeriesValues.TimeFrame);
|
||||
var SymbolAddReturn = _mtApiClient.SymbolSelect(ChartFunctionsSymbolValue, true);
|
||||
var ChartId = _mtApiClient.ChartOpen(ChartFunctionsSymbolValue, TimeSeriesValues.TimeFrame);
|
||||
return ChartId;
|
||||
});
|
||||
|
||||
@@ -109,6 +115,45 @@ namespace MtApi5TestClient
|
||||
AddLog($"ChartOpen: success chartid=>{result}");
|
||||
}
|
||||
|
||||
private async void ExecuteChartTimePriceToXY(object o)
|
||||
{
|
||||
const long chartId = 0;
|
||||
const int subWindow = 0;
|
||||
var time = DateTime.Now;
|
||||
const double price = 1.131;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
|
||||
var result = await Execute(() => _mtApiClient.ChartTimePriceToXY(chartId, subWindow, time, price, out x, out y));
|
||||
if (result == false)
|
||||
{
|
||||
AddLog("ChartTimePriceToXY: result is false");
|
||||
return;
|
||||
}
|
||||
|
||||
AddLog($"ChartTimePriceToXY: success. x = {x}; Y = {y}");
|
||||
}
|
||||
|
||||
private async void ExecuteChartXYToTimePrice(object o)
|
||||
{
|
||||
const long chartId = 0;
|
||||
const int x = 0;
|
||||
const int y = 0;
|
||||
|
||||
var subWindow = 0;
|
||||
DateTime? time = null;
|
||||
double price = double.NaN;
|
||||
|
||||
var result = await Execute(() => _mtApiClient.ChartXYToTimePrice(chartId, x, y, out subWindow, out time, out price));
|
||||
if (result == false)
|
||||
{
|
||||
AddLog("ChartXYToTimePrice: result is false");
|
||||
return;
|
||||
}
|
||||
|
||||
AddLog($"ChartXYToTimePrice: success. subWindow = {subWindow}; time = {time}; price = {price}");
|
||||
}
|
||||
|
||||
private async void ExecuteChartApplyTemplate(object o)
|
||||
{
|
||||
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
||||
@@ -271,6 +316,16 @@ namespace MtApi5TestClient
|
||||
}
|
||||
}
|
||||
|
||||
private string _chartFunctionsSymbolValue = "EURUSD";
|
||||
public string ChartFunctionsSymbolValue
|
||||
{
|
||||
get { return _chartFunctionsSymbolValue; }
|
||||
set
|
||||
{
|
||||
_chartFunctionsSymbolValue = value;
|
||||
OnPropertyChanged("ChartFunctionsSymbolValue");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
@@ -376,6 +431,8 @@ namespace MtApi5TestClient
|
||||
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||
|
||||
ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
|
||||
ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
|
||||
ChartXYToTimePriceCommand = new DelegateCommand(ExecuteChartXYToTimePrice);
|
||||
ChartApplyTemplateCommand = new DelegateCommand(ExecuteChartApplyTemplate);
|
||||
ChartSaveTemplateCommand = new DelegateCommand(ExecuteChartSaveTemplate);
|
||||
|
||||
|
||||
Binary file not shown.
@@ -5944,6 +5944,12 @@ string OnRequest(string json)
|
||||
case 8: //SymbolInfoString
|
||||
response = ExecuteRequest_SymbolInfoString(jo);
|
||||
break;
|
||||
case 9: //ChartTimePriceToXY
|
||||
response = ExecuteRequest_ChartTimePriceToXY(jo);
|
||||
break;
|
||||
case 10: //ChartXYToTimePrice
|
||||
response = ExecuteRequest_ChartXYToTimePrice(jo);
|
||||
break;
|
||||
default:
|
||||
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
|
||||
response = CreateErrorResponse(-1, "Unknown request type");
|
||||
@@ -6357,6 +6363,73 @@ string ExecuteRequest_SymbolInfoString(JSONObject *jo)
|
||||
return CreateSuccessResponse("Value", result_value_jo);
|
||||
}
|
||||
|
||||
|
||||
string ExecuteRequest_ChartTimePriceToXY(JSONObject *jo)
|
||||
{
|
||||
CHECK_JSON_VALUE(jo, "ChartId", CreateErrorResponse(-1, "Undefinded mandatory parameter ChartId"));
|
||||
long chart_id = jo.getLong("ChartId");
|
||||
|
||||
CHECK_JSON_VALUE(jo, "SubWindow", CreateErrorResponse(-1, "Undefinded mandatory parameter SubWindow"));
|
||||
int sub_window = jo.getInt("SubWindow");
|
||||
|
||||
CHECK_JSON_VALUE(jo, "MtTime", CreateErrorResponse(-1, "Undefinded mandatory parameter MtTime"));
|
||||
datetime time = (datetime)jo.getInt("MtTime");
|
||||
|
||||
CHECK_JSON_VALUE(jo, "Price", CreateErrorResponse(-1, "Undefinded mandatory parameter Price"));
|
||||
double price = jo.getDouble("Price");
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: chart_id = %d, sub_window = %d, time = %s", __FUNCTION__, chart_id, sub_window, TimeToString(time));
|
||||
#endif
|
||||
|
||||
int x,y;
|
||||
bool ok = ChartTimePriceToXY(chart_id, sub_window, time, price, x, y);
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: ok = %s, x = %d, y = %d", __FUNCTION__, BoolToString(ok), x, y);
|
||||
#endif
|
||||
|
||||
JSONObject* result_value_jo = new JSONObject();
|
||||
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||
result_value_jo.put("X", new JSONNumber(x));
|
||||
result_value_jo.put("Y", new JSONNumber(y));
|
||||
|
||||
return CreateSuccessResponse("Value", result_value_jo);
|
||||
}
|
||||
|
||||
string ExecuteRequest_ChartXYToTimePrice(JSONObject *jo)
|
||||
{
|
||||
CHECK_JSON_VALUE(jo, "ChartId", CreateErrorResponse(-1, "Undefinded mandatory parameter ChartId"));
|
||||
long chart_id = jo.getLong("ChartId");
|
||||
|
||||
CHECK_JSON_VALUE(jo, "X", CreateErrorResponse(-1, "Undefinded mandatory parameter X"));
|
||||
int x = jo.getInt("X");
|
||||
|
||||
CHECK_JSON_VALUE(jo, "Y", CreateErrorResponse(-1, "Undefinded mandatory parameter Y"));
|
||||
int y = jo.getInt("Y");
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: chart_id = %d, x = %d, y = %d", __FUNCTION__, chart_id, x, y);
|
||||
#endif
|
||||
|
||||
int sub_window;
|
||||
datetime time;
|
||||
double price;
|
||||
bool ok = ChartXYToTimePrice(chart_id, x, y, sub_window, time, price);
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: ok = %s, sub_window = %d, time = %s, price = %f", __FUNCTION__, BoolToString(ok), sub_window, TimeToString(time), price);
|
||||
#endif
|
||||
|
||||
JSONObject* result_value_jo = new JSONObject();
|
||||
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||
result_value_jo.put("SubWindow", new JSONNumber(sub_window));
|
||||
result_value_jo.put("MtTime", new JSONNumber((int)time));
|
||||
result_value_jo.put("Price", new JSONNumber(price));
|
||||
|
||||
return CreateSuccessResponse("Value", result_value_jo);
|
||||
}
|
||||
|
||||
//------------ Events -------------------------------------------------------
|
||||
|
||||
enum MtEventTypes
|
||||
|
||||
Reference in New Issue
Block a user