Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions MtApi5/MtApi5Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,32 @@ public bool SymbolInfoSessionTrade(string name, ENUM_DAY_OF_WEEK dayOfWeek, uint
return false;
}

///<summary>
///Returns the margin rates depending on the order type and direction.
///</summary>
///<param name="symbolName">Symbol name.</param>
///<param name="orderType">Order type.</param>
///<param name="initialMarginRate">A variable, to which the initial margin rate value will be written.</param>
///<param name="maintenanceMarginRate">A variable, to which the maintenance margin rate value will be written.</param>
public bool SymbolInfoMarginRate(string symbolName, ENUM_ORDER_TYPE orderType, out double initialMarginRate, out double maintenanceMarginRate)
{
Dictionary<string, object> cmdParams = new() { { "Symbol", symbolName ?? string.Empty }, { "OrderType", orderType } };

var response = SendCommand<FuncResult<Dictionary<string, double>>>(ExecutorHandle,
Mt5CommandType.SymbolInfoMarginRate, cmdParams);
if (response != null && response.Result != null
&& response.Result.TryGetValue("Initial", out double initial)
&& response.Result.TryGetValue("Maintenance", out double maintenance))
{
initialMarginRate = initial;
maintenanceMarginRate = maintenance;
return response.RetVal;
}
initialMarginRate = 0;
maintenanceMarginRate = 0;
return false;
}

///<summary>
///Provides opening of Depth of Market for a selected symbol, and subscribes for receiving notifications of the DOM changes.
///</summary>
Expand Down
4 changes: 3 additions & 1 deletion MtApi5/MtProtocol/Mt5CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ internal enum Mt5CommandType
OrderCheck = 303,
Buy = 304,
Sell = 305,
GetSymbols = 306
GetSymbols = 306,

SymbolInfoMarginRate = 380
}
}
1 change: 1 addition & 0 deletions TestClients/MtApi5TestClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@
<Button Command="{Binding SymbolInfoTickCommand}" Content="SymbolInfoTick" Margin="2"/>
<Button Command="{Binding SymbolInfoSessionQuoteCommand}" Content="SymbolInfoSessionQuote" Margin="2"/>
<Button Command="{Binding SymbolInfoSessionTradeCommand}" Content="SymbolInfoSessionTrade" Margin="2"/>
<Button Command="{Binding SymbolInfoMarginRateCommand}" Content="SymbolInfoMarginRate" Margin="2"/>
<Button Command="{Binding MarketBookAddCommand}" Content="MarketBookAdd" Margin="2"/>
<Button Command="{Binding MarketBookReleaseCommand}" Content="MarketBookRelease" Margin="2"/>
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
Expand Down
20 changes: 20 additions & 0 deletions TestClients/MtApi5TestClient/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand SymbolInfoTickCommand { get; private set; }
public DelegateCommand SymbolInfoSessionQuoteCommand { get; private set; }
public DelegateCommand SymbolInfoSessionTradeCommand { get; private set; }
public DelegateCommand SymbolInfoMarginRateCommand { get; private set; }
public DelegateCommand MarketBookAddCommand { get; private set; }
public DelegateCommand MarketBookReleaseCommand { get; private set; }
public DelegateCommand MarketBookGetCommand { get; private set; }
Expand Down Expand Up @@ -441,6 +442,7 @@ private void InitCommands()
SymbolInfoTickCommand = new DelegateCommand(ExecuteSymbolInfoTick);
SymbolInfoSessionQuoteCommand = new DelegateCommand(ExecuteSymbolInfoSessionQuote);
SymbolInfoSessionTradeCommand = new DelegateCommand(ExecuteSymbolInfoSessionTrade);
SymbolInfoMarginRateCommand = new DelegateCommand(ExecuteSymbolInfoMarginRate);
MarketBookAddCommand = new DelegateCommand(ExecuteMarketBookAdd);
MarketBookReleaseCommand = new DelegateCommand(ExecuteMarketBookRelease);
MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet);
Expand Down Expand Up @@ -1217,6 +1219,24 @@ private async void ExecuteSymbolInfoSessionTrade(object o)
AddLog("SymbolInfoSessionTrade(EURUSD): result = " + retVal);
}

private async void ExecuteSymbolInfoMarginRate(object o)
{
var retVal = await Execute(() =>
{
double initialMarginRate;
double maintenanceMarginRate;
var ok = _mtApiClient.SymbolInfoMarginRate("EURUSD", ENUM_ORDER_TYPE.ORDER_TYPE_BUY, out initialMarginRate, out maintenanceMarginRate);
if (ok)
{
AddLog($"SymbolInfoMarginRate(EURUSD) initial = {initialMarginRate}");
AddLog($"SymbolInfoMarginRate(EURUSD) maintenance = {maintenanceMarginRate}");
}
return ok;
});

AddLog($"SymbolInfoMarginRate(EURUSD): result = {retVal}");
}

private async void ExecuteMarketBookAdd(object o)
{
var retVal = await Execute(() => _mtApiClient.MarketBookAdd("EURUSD"));
Expand Down
Binary file modified mq5/MtApi5.ex5
Binary file not shown.
21 changes: 21 additions & 0 deletions mq5/MtApi5.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ int preinit()
ADD_EXECUTOR(304, Buy);
ADD_EXECUTOR(305, Sell);
ADD_EXECUTOR(306, GetSymbols);
ADD_EXECUTOR(380, SymbolInfoMarginRate);

return (0);
}
Expand Down Expand Up @@ -1647,6 +1648,26 @@ string Execute_SymbolInfoSessionTrade()
return CreateSuccessResponse(result_value_jo);
}

string Execute_SymbolInfoMarginRate()
{
GET_JSON_PAYLOAD(jo);
GET_STRING_JSON_VALUE(jo, "Symbol", symbol);
GET_INT_JSON_VALUE(jo, "OrderType", order_type);

double initial_margin_rate = 0.0;
double maintenance_margin_rate = 0.0;
bool ok = SymbolInfoMarginRate(symbol, (ENUM_ORDER_TYPE)order_type, initial_margin_rate, maintenance_margin_rate);

JSONObject* result_value_jo = new JSONObject();
result_value_jo.put("RetVal", new JSONBool(ok));
JSONObject* info_jo = new JSONObject();
info_jo.put("Initial", new JSONNumber(initial_margin_rate));
info_jo.put("Maintenance", new JSONNumber(maintenance_margin_rate));
result_value_jo.put("Result", info_jo);

return CreateSuccessResponse(result_value_jo);
}

string Execute_MarketBookAdd()
{
GET_JSON_PAYLOAD(jo);
Expand Down