mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 02:57:56 +00:00
Issue #100: implemented functions GetLastError, ResetLastError() in MtApi (MT5)
This commit is contained in:
@@ -164,7 +164,7 @@ _DLLAPI int _stdcall sendStringResponse(int expertHandle, wchar_t* response, wch
|
||||
_DLLAPI int _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, nullptr);
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseObject(nullptr));
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
@@ -107,8 +107,6 @@ namespace MtApi5
|
||||
BacktestingReady = 66,
|
||||
IsTesting = 67,
|
||||
|
||||
Print = 68,
|
||||
|
||||
//Requests
|
||||
MtRequest = 155,
|
||||
|
||||
@@ -179,6 +177,25 @@ namespace MtApi5
|
||||
TimeLocal = 129,
|
||||
TimeGMT = 130,
|
||||
|
||||
IndicatorRelease = 131
|
||||
IndicatorRelease = 131,
|
||||
|
||||
//Checkup
|
||||
GetLastError = 132,
|
||||
TerminalInfoInteger = 133, //TODO
|
||||
TerminalInfoDouble = 134, //TODO
|
||||
TerminalInfoString = 135, //TODO
|
||||
|
||||
//Common Functions
|
||||
Alert = 136, //TODO
|
||||
Comment = 137, //TODO
|
||||
GetTickCount = 138, //TODO
|
||||
GetMicrosecondCount = 139, //TODO
|
||||
MessageBox = 140, //TODO
|
||||
PeriodSeconds = 141, //TODO
|
||||
PlaySound = 142, //TODO
|
||||
Print = 68,
|
||||
ResetLastError = 143,
|
||||
SendNotification = 144, //TODO
|
||||
SendMail = 145 //TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2352,6 +2352,26 @@ namespace MtApi5
|
||||
|
||||
#endregion //Date and Time
|
||||
|
||||
#region Checkup
|
||||
|
||||
///<summary>
|
||||
///Returns the value of the last error that occurred during the execution of an mql5 program.
|
||||
///</summary>
|
||||
public int GetLastError()
|
||||
{
|
||||
return SendCommand<int>(Mt5CommandType.GetLastError, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Sets the value of the predefined variable _LastError into zero.
|
||||
///</summary>
|
||||
public void ResetLastError()
|
||||
{
|
||||
SendCommand<object>(Mt5CommandType.ResetLastError, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion // Public Methods
|
||||
|
||||
#region Properties
|
||||
|
||||
@@ -294,15 +294,6 @@
|
||||
Command="{Binding AccountInfoStringCommand}"
|
||||
Content="AccountInfoString" HorizontalAlignment="Left" />
|
||||
</Grid>
|
||||
<Grid Margin="10" Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBox Grid.Column="0" Text="{Binding MessageText}" Margin="5"/>
|
||||
<Button Grid.Column="1" Content="Print" Command="{Binding PrintCommand}" Margin="5"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@@ -433,6 +424,29 @@
|
||||
<Button Command="{Binding TimeGMTCommand}" Content="TimeGMT" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="Checkup and Common Functions">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||
<Button Command="{Binding GetLastErrorCommand}" Content="GetLastError" Margin="2"/>
|
||||
<Button Command="{Binding ResetLastErrorCommand}" Content="ResetLastError" Margin="2"/>
|
||||
</WrapPanel>
|
||||
|
||||
<Grid Margin="10" Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column="0" Text="{Binding MessageText}" Margin="5"/>
|
||||
<Button Grid.Column="1" Command="{Binding PrintCommand}" Content="Print" Margin="5"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<Expander Grid.Row="2" Header="Console" IsExpanded="True">
|
||||
|
||||
@@ -60,6 +60,8 @@ namespace MtApi5TestClient
|
||||
|
||||
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||
|
||||
public DelegateCommand GetLastErrorCommand { get; private set; }
|
||||
public DelegateCommand ResetLastErrorCommand { get; private set; }
|
||||
public DelegateCommand PrintCommand { get; private set; }
|
||||
|
||||
public DelegateCommand iCustomCommand { get; private set; }
|
||||
@@ -257,6 +259,8 @@ namespace MtApi5TestClient
|
||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||
|
||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||
GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError);
|
||||
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
|
||||
|
||||
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||
|
||||
@@ -926,6 +930,18 @@ namespace MtApi5TestClient
|
||||
AddLog($"Print: message print in MetaTrader - {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteGetLastError(object obj)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.GetLastError());
|
||||
AddLog($"GetLastError: last error = {retVal}");
|
||||
}
|
||||
|
||||
private void ExecuteResetLastError(object obj)
|
||||
{
|
||||
_mtApiClient.ResetLastError();
|
||||
AddLog("GetLastError: executed.");
|
||||
}
|
||||
|
||||
private async void ExecuteICustom(object o)
|
||||
{
|
||||
const string symbol = "EURUSD";
|
||||
|
||||
Binary file not shown.
@@ -705,6 +705,14 @@ int executeCommand()
|
||||
case 131: //IndicatorRelease
|
||||
Execute_IndicatorRelease();
|
||||
break;
|
||||
|
||||
case 132: //GetLastError
|
||||
Execute_GetLastError();
|
||||
break;
|
||||
case 143: //ResetLastError
|
||||
Execute_ResetLastError();
|
||||
break;
|
||||
|
||||
default:
|
||||
Print("Unknown command type = ", commandType);
|
||||
sendVoidResponse(ExpertHandle, _response_error);
|
||||
@@ -5508,6 +5516,31 @@ void Execute_IndicatorRelease()
|
||||
PrintResponseError("IndicatorRelease", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_GetLastError()
|
||||
{
|
||||
int last_error = GetLastError();
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: last_error = %d", __FUNCTION__, last_error);
|
||||
#endif
|
||||
|
||||
SEND_INT_RESPONSE(last_error, "GetLastError");
|
||||
}
|
||||
|
||||
void Execute_ResetLastError()
|
||||
{
|
||||
ResetLastError();
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: called", __FUNCTION__);
|
||||
#endif
|
||||
|
||||
if (!sendVoidResponse(ExpertHandle, _error))
|
||||
{
|
||||
PrintResponseError("ResetLastError", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintParamError(string paramName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user