mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-27 18:47:55 +00:00
Merge branch 'mt5_1_0_18' into master
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);
|
||||
}
|
||||
|
||||
@@ -10,13 +10,16 @@ namespace MtApi5
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public ENUM_BOOK_TYPE type { get; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||
public double price { get; } // Price
|
||||
public long volume { get; } // Volume
|
||||
public MqlBookInfo()
|
||||
{ }
|
||||
|
||||
public ENUM_BOOK_TYPE type { get; set; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||
public double price { get; set; } // Price
|
||||
public long volume { get; set; } // Volume
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{type}|{price}|{volume}";
|
||||
return $"type = {type}; price = {price}; volume = {volume}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ namespace MtApi5
|
||||
{
|
||||
public class MqlTradeCheckResult
|
||||
{
|
||||
public uint Retcode { get; } // Reply code
|
||||
public double Balance { get; } // Balance after the execution of the deal
|
||||
public double Equity { get; } // Equity after the execution of the deal
|
||||
public double Profit { get; } // Floating profit
|
||||
public double Margin { get; } // Margin requirements
|
||||
public double Margin_free { get; } // Free margin
|
||||
public double Margin_level { get; } // Margin level
|
||||
public string Comment { get; } // Comment to the reply code (description of the error)
|
||||
public uint Retcode { get; set; } // Reply code
|
||||
public double Balance { get; set; } // Balance after the execution of the deal
|
||||
public double Equity { get; set; } // Equity after the execution of the deal
|
||||
public double Profit { get; set; } // Floating profit
|
||||
public double Margin { get; set; } // Margin requirements
|
||||
public double Margin_free { get; set; } // Free margin
|
||||
public double Margin_level { get; set; } // Margin level
|
||||
public string Comment { get; set; } // Comment to the reply code (description of the error)
|
||||
|
||||
public MqlTradeCheckResult(uint retcode
|
||||
, double balance
|
||||
@@ -32,6 +32,9 @@ namespace MtApi5
|
||||
Comment = comment;
|
||||
}
|
||||
|
||||
public MqlTradeCheckResult()
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Retcode={Retcode}; Comment={Comment}; Balance={Balance}; Equity={Equity}; Profit={Profit}; Margin={Margin}; Margin_free={Margin_free}; Margin_level={Margin_level}";
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace MtApi5
|
||||
//OrderSend = 1,
|
||||
OrderCalcMargin = 2,
|
||||
OrderCalcProfit = 3,
|
||||
//OrderCheck = 4,
|
||||
//OrderSendAsync = 5,
|
||||
PositionsTotal = 6,
|
||||
PositionGetSymbol = 7,
|
||||
@@ -17,6 +16,7 @@ namespace MtApi5
|
||||
PositionGetDouble = 9,
|
||||
PositionGetInteger = 10,
|
||||
PositionGetString = 11,
|
||||
PositionGetTicket = 4,
|
||||
OrdersTotal = 12,
|
||||
OrderGetTicket = 13,
|
||||
OrderSelect = 14,
|
||||
@@ -107,8 +107,6 @@ namespace MtApi5
|
||||
BacktestingReady = 66,
|
||||
IsTesting = 67,
|
||||
|
||||
Print = 68,
|
||||
|
||||
//Requests
|
||||
MtRequest = 155,
|
||||
|
||||
@@ -237,9 +235,24 @@ namespace MtApi5
|
||||
TerminalCompany = 68,
|
||||
TerminalName = 69,
|
||||
TerminalPath = 70,
|
||||
TerminalInfoString = 153,
|
||||
TerminalInfoInteger = 204,
|
||||
TerminalInfoDouble = 205,
|
||||
|
||||
//Checkup
|
||||
GetLastError = 132,
|
||||
TerminalInfoString = 153, //TODO
|
||||
TerminalInfoInteger = 204, //TODO
|
||||
TerminalInfoDouble = 205, //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
|
||||
}
|
||||
}
|
||||
|
||||
+33
-2
@@ -280,6 +280,17 @@ namespace MtApi5
|
||||
return SendCommand<string>(Mt5CommandType.PositionGetString, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the ticket of a position with the specified index in the list of open positions and automatically selects the position to work with using functions PositionGetDouble, PositionGetInteger, PositionGetString.
|
||||
///</summary>
|
||||
///<param name="index">Identifier of a position property.</param>
|
||||
public ulong PositionGetTicket(int index)
|
||||
{
|
||||
var commandParameters = new ArrayList { index };
|
||||
|
||||
return SendCommand<ulong>(Mt5CommandType.PositionGetTicket, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the number of current orders.
|
||||
///</summary>
|
||||
@@ -611,11 +622,11 @@ namespace MtApi5
|
||||
///<param name="symbolName">Symbol name.</param>
|
||||
///<param name="timeframe"> Period.</param>
|
||||
///<param name="propId">Identifier of the requested property, value of the ENUM_SERIES_INFO_INTEGER enumeration.</param>
|
||||
public int SeriesInfoInteger(string symbolName, ENUM_TIMEFRAMES timeframe, ENUM_SERIES_INFO_INTEGER propId)
|
||||
public long SeriesInfoInteger(string symbolName, ENUM_TIMEFRAMES timeframe, ENUM_SERIES_INFO_INTEGER propId)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, (int)propId };
|
||||
|
||||
return SendCommand<int>(Mt5CommandType.SeriesInfoInteger, commandParameters);
|
||||
return SendCommand<long>(Mt5CommandType.SeriesInfoInteger, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -3006,6 +3017,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
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.17")]
|
||||
[assembly: AssemblyFileVersion("1.0.17")]
|
||||
[assembly: AssemblyVersion("1.0.18")]
|
||||
[assembly: AssemblyFileVersion("1.0.18")]
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="OrderCheck" Command="{Binding OrderCheckCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="PositionGetTicket" Command="{Binding PositionGetTicketCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
</StackPanel>
|
||||
|
||||
<WrapPanel>
|
||||
@@ -293,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>
|
||||
|
||||
@@ -438,6 +430,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">
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace MtApi5TestClient
|
||||
|
||||
public DelegateCommand OrderSendCommand { get; private set; }
|
||||
public DelegateCommand OrderCheckCommand { get; private set; }
|
||||
public DelegateCommand PositionGetTicketCommand { get; private set; }
|
||||
|
||||
public DelegateCommand HistoryOrderGetIntegerCommand { get; private set; }
|
||||
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
||||
@@ -61,6 +62,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; }
|
||||
@@ -282,6 +285,7 @@ namespace MtApi5TestClient
|
||||
|
||||
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
||||
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
|
||||
PositionGetTicketCommand = new DelegateCommand(ExecutePositionGetTicket);
|
||||
|
||||
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
|
||||
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
||||
@@ -324,6 +328,8 @@ namespace MtApi5TestClient
|
||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||
|
||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||
GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError);
|
||||
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
|
||||
|
||||
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||
|
||||
@@ -393,6 +399,19 @@ namespace MtApi5TestClient
|
||||
AddLog(message);
|
||||
}
|
||||
|
||||
private async void ExecutePositionGetTicket(object obj)
|
||||
{
|
||||
const int index = 0;
|
||||
var retVal = await Execute(() =>
|
||||
{
|
||||
var ok = _mtApiClient.PositionGetTicket(index);
|
||||
return ok;
|
||||
});
|
||||
|
||||
var message = $"PositionGetTicket: result = {retVal}";
|
||||
AddLog(message);
|
||||
}
|
||||
|
||||
private async void ExecuteHistoryOrderGetInteger(object o)
|
||||
{
|
||||
const ulong ticket = 12345;
|
||||
@@ -984,6 +1003,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.
+73
-23
@@ -41,7 +41,7 @@
|
||||
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
|
||||
#import
|
||||
|
||||
//#define __DEBUG_LOG__
|
||||
#define __DEBUG_LOG__
|
||||
|
||||
input int Port = 8228;
|
||||
|
||||
@@ -282,7 +282,7 @@ int executeCommand()
|
||||
Execute_OrderCalcProfit();
|
||||
break;
|
||||
case 4: //OrderCheck
|
||||
Execute_OrderCheck();
|
||||
Execute_PositionGetTicket();
|
||||
break;
|
||||
case 6: //PositionsTotal
|
||||
Execute_PositionsTotal();
|
||||
@@ -734,6 +734,14 @@ int executeCommand()
|
||||
Execute_TerminalInfoString();
|
||||
break;
|
||||
|
||||
|
||||
case 132: //GetLastError
|
||||
Execute_GetLastError();
|
||||
break;
|
||||
case 143: //ResetLastError
|
||||
Execute_ResetLastError();
|
||||
break;
|
||||
|
||||
default:
|
||||
Print("Unknown command type = ", commandType);
|
||||
sendVoidResponse(ExpertHandle, _response_error);
|
||||
@@ -743,6 +751,29 @@ int executeCommand()
|
||||
return (commandType);
|
||||
}
|
||||
|
||||
//------ helper macros to get and send values ------------------
|
||||
|
||||
#define GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(get_func, argument_id, argument, cmd_name, param_name) if (!get_func(ExpertHandle, argument_id, argument, _error)) \
|
||||
{ \
|
||||
PrintParamError(cmd_name, param_name, _error); \
|
||||
sendErrorResponse(ExpertHandle, -1, _error, _response_error); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
#define GET_INTEGER_VALUE(argument_id, argument, cmd_name, param_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getIntValue, argument_id, argument, cmd_name, param_name)
|
||||
|
||||
|
||||
#define SEND_RESPONSE_OR_PRINT_ERROR(send_func, response, cmd_name) if (!send_func(ExpertHandle, response, _response_error)) \
|
||||
{ \
|
||||
PrintResponseError(cmd_name, _response_error); \
|
||||
}
|
||||
|
||||
#define SEND_INT_RESPONSE(response, cmd_name) SEND_RESPONSE_OR_PRINT_ERROR(sendIntResponse, response, cmd_name)
|
||||
#define SEND_LONG_RESPONSE(response, cmd_name) SEND_RESPONSE_OR_PRINT_ERROR(sendLongResponse, response, cmd_name)
|
||||
#define SEND_ULONG_RESPONSE(response, cmd_name) SEND_RESPONSE_OR_PRINT_ERROR(sendULongResponse, response, cmd_name)
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
||||
void Execute_Request()
|
||||
{
|
||||
string request;
|
||||
@@ -909,19 +940,22 @@ void Execute_OrderCalcProfit()
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_OrderCheck()
|
||||
void Execute_PositionGetTicket()
|
||||
{
|
||||
MqlTradeRequest request={0};
|
||||
ReadMqlTradeRequestFromCommand(request);
|
||||
|
||||
MqlTradeCheckResult result={0};
|
||||
|
||||
bool retVal = OrderCheck(request, result);
|
||||
|
||||
if (!sendStringResponse(ExpertHandle, ResultToString(retVal, result), _response_error))
|
||||
{
|
||||
PrintResponseError("OrderCheck", _response_error);
|
||||
}
|
||||
int index;
|
||||
GET_INTEGER_VALUE(0, index, "PositionGetTicket", "index");
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: index = %d", __FUNCTION__, index);
|
||||
#endif
|
||||
|
||||
ulong result = PositionGetTicket(index);
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: result = %u", __FUNCTION__, result);
|
||||
#endif
|
||||
|
||||
SEND_ULONG_RESPONSE(result, "PositionGetTicket");
|
||||
}
|
||||
|
||||
void Execute_PositionsTotal()
|
||||
@@ -5497,15 +5531,6 @@ void Execute_TimeGMT()
|
||||
}
|
||||
}
|
||||
|
||||
#define GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(get_func, argument_id, argument, cmd_name, param_name) if (!get_func(ExpertHandle, argument_id, argument, _error)) \
|
||||
{ \
|
||||
PrintParamError(cmd_name, param_name, _error); \
|
||||
sendErrorResponse(ExpertHandle, -1, _error, _response_error); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
#define GET_INTEGER_VALUE(argument_id, argument, cmd_name, param_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getIntValue, argument_id, argument, cmd_name, param_name)
|
||||
|
||||
void Execute_IndicatorRelease()
|
||||
{
|
||||
int indicator_handle;
|
||||
@@ -5520,6 +5545,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