mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-17 04:38:10 +00:00
Issue #96: Implemented function PositionGetTicket in MtApi (MT5)
This commit is contained in:
@@ -9,7 +9,6 @@ namespace MtApi5
|
|||||||
//OrderSend = 1,
|
//OrderSend = 1,
|
||||||
OrderCalcMargin = 2,
|
OrderCalcMargin = 2,
|
||||||
OrderCalcProfit = 3,
|
OrderCalcProfit = 3,
|
||||||
//OrderCheck = 4,
|
|
||||||
//OrderSendAsync = 5,
|
//OrderSendAsync = 5,
|
||||||
PositionsTotal = 6,
|
PositionsTotal = 6,
|
||||||
PositionGetSymbol = 7,
|
PositionGetSymbol = 7,
|
||||||
@@ -17,6 +16,7 @@ namespace MtApi5
|
|||||||
PositionGetDouble = 9,
|
PositionGetDouble = 9,
|
||||||
PositionGetInteger = 10,
|
PositionGetInteger = 10,
|
||||||
PositionGetString = 11,
|
PositionGetString = 11,
|
||||||
|
PositionGetTicket = 4,
|
||||||
OrdersTotal = 12,
|
OrdersTotal = 12,
|
||||||
OrderGetTicket = 13,
|
OrderGetTicket = 13,
|
||||||
OrderSelect = 14,
|
OrderSelect = 14,
|
||||||
|
|||||||
@@ -280,6 +280,17 @@ namespace MtApi5
|
|||||||
return SendCommand<string>(Mt5CommandType.PositionGetString, commandParameters);
|
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>
|
///<summary>
|
||||||
///Returns the number of current orders.
|
///Returns the number of current orders.
|
||||||
///</summary>
|
///</summary>
|
||||||
|
|||||||
@@ -240,6 +240,7 @@
|
|||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
<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="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>
|
</StackPanel>
|
||||||
|
|
||||||
<WrapPanel>
|
<WrapPanel>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
public DelegateCommand OrderSendCommand { get; private set; }
|
public DelegateCommand OrderSendCommand { get; private set; }
|
||||||
public DelegateCommand OrderCheckCommand { get; private set; }
|
public DelegateCommand OrderCheckCommand { get; private set; }
|
||||||
|
public DelegateCommand PositionGetTicketCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand HistoryOrderGetIntegerCommand { get; private set; }
|
public DelegateCommand HistoryOrderGetIntegerCommand { get; private set; }
|
||||||
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
||||||
@@ -213,6 +214,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
||||||
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
|
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
|
||||||
|
PositionGetTicketCommand = new DelegateCommand(ExecutePositionGetTicket);
|
||||||
|
|
||||||
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
|
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
|
||||||
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
||||||
@@ -320,6 +322,19 @@ namespace MtApi5TestClient
|
|||||||
AddLog(message);
|
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)
|
private async void ExecuteHistoryOrderGetInteger(object o)
|
||||||
{
|
{
|
||||||
const ulong ticket = 12345;
|
const ulong ticket = 12345;
|
||||||
|
|||||||
Binary file not shown.
+40
-23
@@ -41,7 +41,7 @@
|
|||||||
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
|
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
|
||||||
#import
|
#import
|
||||||
|
|
||||||
//#define __DEBUG_LOG__
|
#define __DEBUG_LOG__
|
||||||
|
|
||||||
input int Port = 8228;
|
input int Port = 8228;
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ int executeCommand()
|
|||||||
Execute_OrderCalcProfit();
|
Execute_OrderCalcProfit();
|
||||||
break;
|
break;
|
||||||
case 4: //OrderCheck
|
case 4: //OrderCheck
|
||||||
Execute_OrderCheck();
|
Execute_PositionGetTicket();
|
||||||
break;
|
break;
|
||||||
case 6: //PositionsTotal
|
case 6: //PositionsTotal
|
||||||
Execute_PositionsTotal();
|
Execute_PositionsTotal();
|
||||||
@@ -714,6 +714,29 @@ int executeCommand()
|
|||||||
return (commandType);
|
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()
|
void Execute_Request()
|
||||||
{
|
{
|
||||||
string request;
|
string request;
|
||||||
@@ -880,19 +903,22 @@ void Execute_OrderCalcProfit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Execute_OrderCheck()
|
void Execute_PositionGetTicket()
|
||||||
{
|
{
|
||||||
MqlTradeRequest request={0};
|
int index;
|
||||||
ReadMqlTradeRequestFromCommand(request);
|
GET_INTEGER_VALUE(0, index, "PositionGetTicket", "index");
|
||||||
|
|
||||||
MqlTradeCheckResult result={0};
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: index = %d", __FUNCTION__, index);
|
||||||
bool retVal = OrderCheck(request, result);
|
#endif
|
||||||
|
|
||||||
if (!sendStringResponse(ExpertHandle, ResultToString(retVal, result), _response_error))
|
ulong result = PositionGetTicket(index);
|
||||||
{
|
|
||||||
PrintResponseError("OrderCheck", _response_error);
|
#ifdef __DEBUG_LOG__
|
||||||
}
|
PrintFormat("%s: result = %u", __FUNCTION__, result);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SEND_ULONG_RESPONSE(result, "PositionGetTicket");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Execute_PositionsTotal()
|
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()
|
void Execute_IndicatorRelease()
|
||||||
{
|
{
|
||||||
int indicator_handle;
|
int indicator_handle;
|
||||||
|
|||||||
Reference in New Issue
Block a user