Issue #96: Implemented function PositionGetTicket in MtApi (MT5)

This commit is contained in:
vdemydiuk
2018-03-08 17:45:22 +02:00
parent 0a39b69b15
commit ec6c71607b
6 changed files with 68 additions and 24 deletions
+1 -1
View File
@@ -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,
+11
View File
@@ -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>
@@ -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>
+15
View File
@@ -18,6 +18,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; }
@@ -213,6 +214,7 @@ namespace MtApi5TestClient
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
PositionGetTicketCommand = new DelegateCommand(ExecutePositionGetTicket);
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
@@ -320,6 +322,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;
BIN
View File
Binary file not shown.
+40 -23
View File
@@ -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();
@@ -714,6 +714,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;
@@ -880,19 +903,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()
@@ -5468,15 +5494,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;