mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 19:58:10 +00:00
Issue #107: Added function PositionCloseAll
This commit is contained in:
@@ -250,6 +250,7 @@ namespace MtApi5
|
|||||||
GlobalVariablesDeleteAll = 157,
|
GlobalVariablesDeleteAll = 157,
|
||||||
GlobalVariablesTotal = 158,
|
GlobalVariablesTotal = 158,
|
||||||
|
|
||||||
UnlockTicks = 159
|
UnlockTicks = 159,
|
||||||
|
PositionCloseAll = 160
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -521,11 +521,20 @@ namespace MtApi5
|
|||||||
///<summary>
|
///<summary>
|
||||||
///Close all open positions.
|
///Close all open positions.
|
||||||
///</summary>
|
///</summary>
|
||||||
|
[Obsolete("OrderCloseAll is deprecated, please use PositionCloseAll instead.")]
|
||||||
public bool OrderCloseAll()
|
public bool OrderCloseAll()
|
||||||
{
|
{
|
||||||
return SendCommand<bool>(Mt5CommandType.OrderCloseAll, null);
|
return SendCommand<bool>(Mt5CommandType.OrderCloseAll, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Close all open positions. Returns count of closed positions.
|
||||||
|
///</summary>
|
||||||
|
public int PositionCloseAll()
|
||||||
|
{
|
||||||
|
return SendCommand<int>(Mt5CommandType.PositionCloseAll, null);
|
||||||
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Closes a position with the specified ticket.
|
///Closes a position with the specified ticket.
|
||||||
///</summary>
|
///</summary>
|
||||||
|
|||||||
@@ -486,6 +486,7 @@
|
|||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Button Grid.Row="0" Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2" HorizontalAlignment="Left"/>
|
<Button Grid.Row="0" Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2" HorizontalAlignment="Left"/>
|
||||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="4">
|
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="4">
|
||||||
@@ -493,6 +494,7 @@
|
|||||||
<TextBox Text="{Binding PositionTicketValue}" Width="150" Margin="2"/>
|
<TextBox Text="{Binding PositionTicketValue}" Width="150" Margin="2"/>
|
||||||
<Button Command="{Binding PositionCloseCommand}" Content="PositionClose" Margin="2"/>
|
<Button Command="{Binding PositionCloseCommand}" Content="PositionClose" Margin="2"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<Button Grid.Row="2" Command="{Binding PositionCloseAllCommand}" Content="PositionCloseAll" Margin="2" HorizontalAlignment="Left"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
public DelegateCommand PositionOpenCommand { get; private set; }
|
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||||
public DelegateCommand PositionCloseCommand { get; private set; }
|
public DelegateCommand PositionCloseCommand { get; private set; }
|
||||||
|
public DelegateCommand PositionCloseAllCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand GetLastErrorCommand { get; private set; }
|
public DelegateCommand GetLastErrorCommand { get; private set; }
|
||||||
public DelegateCommand ResetLastErrorCommand { get; private set; }
|
public DelegateCommand ResetLastErrorCommand { get; private set; }
|
||||||
@@ -375,6 +376,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||||
PositionCloseCommand = new DelegateCommand(ExecutePositionClose);
|
PositionCloseCommand = new DelegateCommand(ExecutePositionClose);
|
||||||
|
PositionCloseAllCommand = new DelegateCommand(ExecutePositionCloseAll);
|
||||||
|
|
||||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||||
AlertCommand = new DelegateCommand(ExecuteAlert);
|
AlertCommand = new DelegateCommand(ExecuteAlert);
|
||||||
@@ -1126,6 +1128,12 @@ namespace MtApi5TestClient
|
|||||||
AddLog($"PositionClose: ticket {ticket} retVal = {retVal}, result = {tradeResult}");
|
AddLog($"PositionClose: ticket {ticket} retVal = {retVal}, result = {tradeResult}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecutePositionCloseAll(object obj)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.PositionCloseAll());
|
||||||
|
AddLog($"PositionCloseAll: count = {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecutePrint(object obj)
|
private async void ExecutePrint(object obj)
|
||||||
{
|
{
|
||||||
var message = MessageText;
|
var message = MessageText;
|
||||||
|
|||||||
Binary file not shown.
+26
-4
@@ -791,6 +791,9 @@ int executeCommand()
|
|||||||
case 159: //UnlockTiks
|
case 159: //UnlockTiks
|
||||||
Execute_UnlockTicks();
|
Execute_UnlockTicks();
|
||||||
break;
|
break;
|
||||||
|
case 160: //PositionCloseAll
|
||||||
|
Execute_PositionCloseAll();
|
||||||
|
break;
|
||||||
case 204: //TerminalInfoInteger
|
case 204: //TerminalInfoInteger
|
||||||
Execute_TerminalInfoInteger();
|
Execute_TerminalInfoInteger();
|
||||||
break;
|
break;
|
||||||
@@ -6527,6 +6530,17 @@ void Execute_UnlockTicks()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Execute_PositionCloseAll()
|
||||||
|
{
|
||||||
|
int res = PositionCloseAll();
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: result = %d", __FUNCTION__, res);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SEND_INT_RESPONSE(res)
|
||||||
|
}
|
||||||
|
|
||||||
void Execute_TerminalInfoInteger()
|
void Execute_TerminalInfoInteger()
|
||||||
{
|
{
|
||||||
int propertyId;
|
int propertyId;
|
||||||
@@ -6714,6 +6728,18 @@ bool OrderCloseAll()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PositionCloseAll()
|
||||||
|
{
|
||||||
|
CTrade trade;
|
||||||
|
int total = PositionsTotal();
|
||||||
|
int i = total -1;
|
||||||
|
while (i >= 0)
|
||||||
|
{
|
||||||
|
if (trade.PositionClose(PositionGetSymbol(i))) i--;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
//------------ Requests -------------------------------------------------------
|
//------------ Requests -------------------------------------------------------
|
||||||
|
|
||||||
string OnRequest(string json)
|
string OnRequest(string json)
|
||||||
@@ -7408,10 +7434,6 @@ private:
|
|||||||
|
|
||||||
void SendMtEvent(MtEventTypes eventType, MtEvent* mtEvent)
|
void SendMtEvent(MtEventTypes eventType, MtEvent* mtEvent)
|
||||||
{
|
{
|
||||||
#ifdef __DEBUG_LOG__
|
|
||||||
PrintFormat("%s: eventType = %d", __FUNCTION__, eventType);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
JSONObject* json = mtEvent.CreateJson();
|
JSONObject* json = mtEvent.CreateJson();
|
||||||
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
|
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user