mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-01 13:07:52 +00:00
Issue #90: Added time functions: TimeCurrent, TimeTradeServer, TimeLocal, TimeGMT
This commit is contained in:
@@ -171,6 +171,12 @@ namespace MtApi5
|
||||
iTriX = 123,
|
||||
iWPR = 124,
|
||||
iVIDyA = 125,
|
||||
iVolumes = 126
|
||||
iVolumes = 126,
|
||||
|
||||
//Date and Time
|
||||
TimeCurrent = 127,
|
||||
TimeTradeServer = 128,
|
||||
TimeLocal = 129,
|
||||
TimeGMT = 130
|
||||
}
|
||||
}
|
||||
|
||||
+58
-2
@@ -1667,8 +1667,6 @@ namespace MtApi5
|
||||
|
||||
#region Technical Indicators
|
||||
|
||||
#endregion //Technical Indicators
|
||||
|
||||
///<summary>
|
||||
///The function creates Accelerator Oscillator in a global cache of the client terminal and returns its handle.
|
||||
///</summary>
|
||||
@@ -2196,6 +2194,7 @@ namespace MtApi5
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, double[] parameters)
|
||||
{
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -2204,6 +2203,7 @@ namespace MtApi5
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Double
|
||||
});
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -2216,6 +2216,7 @@ namespace MtApi5
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, int[] parameters)
|
||||
{
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -2224,6 +2225,7 @@ namespace MtApi5
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -2236,6 +2238,7 @@ namespace MtApi5
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, string[] parameters)
|
||||
{
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -2244,6 +2247,7 @@ namespace MtApi5
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -2256,6 +2260,7 @@ namespace MtApi5
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, bool[] parameters)
|
||||
{
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -2264,9 +2269,60 @@ namespace MtApi5
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
#endregion //Technical Indicators
|
||||
|
||||
#region Date and Time
|
||||
|
||||
///<summary>
|
||||
///Returns the last known server time, time of the last quote receipt for one of the symbols selected in the "Market Watch" window.
|
||||
///</summary>
|
||||
public DateTime TimeCurrent()
|
||||
{
|
||||
Log.Debug("TimeCurrent: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeCurrent, null);
|
||||
Log.Debug($"TimeCurrent: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the calculated current time of the trade server. Unlike TimeCurrent(), the calculation of the time value is performed in the client terminal and depends on the time settings on your computer.
|
||||
///</summary>
|
||||
public DateTime TimeTradeServer()
|
||||
{
|
||||
Log.Debug("TimeTradeServer: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeTradeServer, null);
|
||||
Log.Debug($"TimeTradeServer: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the local time of a computer, where the client terminal is running.
|
||||
///</summary>
|
||||
public DateTime TimeLocal()
|
||||
{
|
||||
Log.Debug("TimeLocal: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeLocal, null);
|
||||
Log.Debug($"TimeLocal: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the GMT, which is calculated taking into account the DST switch by the local time on the computer where the client terminal is running.
|
||||
///</summary>
|
||||
public DateTime TimeGMT()
|
||||
{
|
||||
Log.Debug("TimeGMT: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeGMT, null);
|
||||
Log.Debug($"TimeGMT: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
#endregion //Date and Time
|
||||
|
||||
#endregion // Public Methods
|
||||
|
||||
#region Properties
|
||||
|
||||
@@ -389,6 +389,15 @@
|
||||
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="Time and Date">
|
||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||
<Button Command="{Binding TimeCurrentCommand}" Content="TimeCurrent" Margin="2"/>
|
||||
<Button Command="{Binding TimeTradeServerCommand}" Content="TimeTradeServer" Margin="2"/>
|
||||
<Button Command="{Binding TimeLocalCommand}" Content="TimeLocal" Margin="2"/>
|
||||
<Button Command="{Binding TimeGMTCommand}" Content="TimeGMT" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<Expander Grid.Row="2" Header="Console" IsExpanded="True">
|
||||
|
||||
@@ -60,6 +60,11 @@ namespace MtApi5TestClient
|
||||
public DelegateCommand PrintCommand { get; private set; }
|
||||
|
||||
public DelegateCommand iCustomCommand { get; private set; }
|
||||
|
||||
public DelegateCommand TimeCurrentCommand { get; private set; }
|
||||
public DelegateCommand TimeTradeServerCommand { get; private set; }
|
||||
public DelegateCommand TimeLocalCommand { get; private set; }
|
||||
public DelegateCommand TimeGMTCommand { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
@@ -246,6 +251,11 @@ namespace MtApi5TestClient
|
||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||
|
||||
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||
|
||||
TimeCurrentCommand = new DelegateCommand(ExecuteTimeCurrent);
|
||||
TimeTradeServerCommand = new DelegateCommand(ExecuteTimeTradeServer);
|
||||
TimeLocalCommand = new DelegateCommand(ExecuteTimeLocal);
|
||||
TimeGMTCommand = new DelegateCommand(ExecuteTimeGMT);
|
||||
}
|
||||
|
||||
private bool CanExecuteConnect(object o)
|
||||
@@ -866,6 +876,30 @@ namespace MtApi5TestClient
|
||||
AddLog($"Custom Moving Average: result - {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeCurrent(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
|
||||
AddLog($"TimeCurrent: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeTradeServer(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeTradeServer());
|
||||
AddLog($"TimeTradeServer: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeLocal(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeLocal());
|
||||
AddLog($"TimeLocal: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeGMT(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeGMT());
|
||||
AddLog($"TimeGMT: {retVal}");
|
||||
}
|
||||
|
||||
private static void RunOnUiThread(Action action)
|
||||
{
|
||||
Application.Current?.Dispatcher.Invoke(action);
|
||||
|
||||
Binary file not shown.
+47
-3
@@ -489,9 +489,9 @@ int executeCommand()
|
||||
case 65: //PositionOpen
|
||||
Execute_PositionOpen(false);
|
||||
break;
|
||||
case 1065: //PositionOpenWithResult
|
||||
Execute_PositionOpen(true);
|
||||
break;
|
||||
// case 1065: //PositionOpenWithResult
|
||||
// Execute_PositionOpen(true);
|
||||
// break;
|
||||
case 66: //BacktestingReady
|
||||
Execute_BacktestingReady();
|
||||
break;
|
||||
@@ -665,6 +665,18 @@ int executeCommand()
|
||||
case 126: //iVolumes
|
||||
Execute_iVolumes();
|
||||
break;
|
||||
case 127: //TimeCurrent
|
||||
Execute_TimeCurrent();
|
||||
break;
|
||||
case 128: //TimeTradeServer
|
||||
Execute_TimeTradeServer();
|
||||
break;
|
||||
case 129: //TimeLocal
|
||||
Execute_TimeLocal();
|
||||
break;
|
||||
case 130: //TimeGMT
|
||||
Execute_TimeGMT();
|
||||
break;
|
||||
default:
|
||||
Print("Unknown command type = ", commandType);
|
||||
sendVoidResponse(ExpertHandle, _response_error);
|
||||
@@ -5427,6 +5439,38 @@ void Execute_iVolumes()
|
||||
PrintResponseError("iVolumes", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeCurrent()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeCurrent(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeCurrent", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeTradeServer()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeTradeServer(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeTradeServer", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeLocal()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeLocal(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeLocal", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeGMT()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeGMT(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeGMT", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintParamError(string paramName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user