mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-08 00:17:49 +00:00
Issue #202: [MT5] added Buy/Sell functions
This commit is contained in:
@@ -78,6 +78,7 @@
|
||||
<Compile Include="Events\Mt5EventTypes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Mt5Quote.cs" />
|
||||
<Compile Include="Requests\BuyRequest.cs" />
|
||||
<Compile Include="Requests\ChartTimePriceToXyRequest.cs" />
|
||||
<Compile Include="Requests\ChartTimePriceToXyResult.cs" />
|
||||
<Compile Include="Requests\ChartXyToTimePriceRequest.cs" />
|
||||
@@ -96,6 +97,7 @@
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Requests\OrderSendResult.cs" />
|
||||
<Compile Include="Requests\Response.cs" />
|
||||
<Compile Include="Requests\SellRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringResult.cs" />
|
||||
<Compile Include="Requests\SymbolInfoTickRequest.cs" />
|
||||
|
||||
@@ -683,6 +683,64 @@ namespace MtApi5
|
||||
|
||||
return SendCommand<bool>(Mt5CommandType.PositionClosePartial_byTicket, commandParameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a long position with specified parameters with current market Ask price
|
||||
/// </summary>
|
||||
/// <param name="result">output result</param>
|
||||
/// <param name="volume">Requested position volume.</param>
|
||||
/// <param name="symbol">Position symbol. If it is not specified, the current symbol will be used.</param>
|
||||
/// <param name="price">Execution price.</param>
|
||||
/// <param name="sl">Stop Loss price.</param>
|
||||
/// <param name="tp">Take Profit price.</param>
|
||||
/// <param name="comment">Comment.</param>
|
||||
/// <returns>true - successful check of the structures, otherwise - false.</returns>
|
||||
public bool Buy(out MqlTradeResult result, double volume, string symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string comment = null)
|
||||
{
|
||||
Log.Debug($"Buy: volume = {volume}, symbol = {symbol}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||
|
||||
var response = SendRequest<OrderSendResult>(new BuyRequest
|
||||
{
|
||||
Volume = volume,
|
||||
Symbol = symbol,
|
||||
Price = price,
|
||||
Sl = sl,
|
||||
Tp = tp,
|
||||
Comment = comment
|
||||
});
|
||||
|
||||
result = response?.TradeResult;
|
||||
return response != null && response.RetVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a short position with specified parameters with current market Bid price
|
||||
/// </summary>
|
||||
/// <param name="result">output result</param>
|
||||
/// <param name="volume">Requested position volume.</param>
|
||||
/// <param name="symbol">Position symbol. If it is not specified, the current symbol will be used.</param>
|
||||
/// <param name="price">Execution price.</param>
|
||||
/// <param name="sl">Stop Loss price.</param>
|
||||
/// <param name="tp">Take Profit price.</param>
|
||||
/// <param name="comment">Comment.</param>
|
||||
/// <returns>true - successful check of the structures, otherwise - false.</returns>
|
||||
public bool Sell(out MqlTradeResult result, double volume, string symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string comment = null)
|
||||
{
|
||||
Log.Debug($"Sell: volume = {volume}, symbol = {symbol}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||
|
||||
var response = SendRequest<OrderSendResult>(new SellRequest
|
||||
{
|
||||
Volume = volume,
|
||||
Symbol = symbol,
|
||||
Price = price,
|
||||
Sl = sl,
|
||||
Tp = tp,
|
||||
Comment = comment
|
||||
});
|
||||
|
||||
result = response?.TradeResult;
|
||||
return response != null && response.RetVal;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Account Information functions
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class BuyRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.Buy;
|
||||
|
||||
public double Volume { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ namespace MtApi5.Requests
|
||||
ChartTimePriceToXY = 9,
|
||||
ChartXYToTimePrice = 10,
|
||||
PositionClose = 11,
|
||||
SymbolInfoTick = 12
|
||||
SymbolInfoTick = 12,
|
||||
Buy = 13,
|
||||
Sell = 14
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class SellRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.Sell;
|
||||
|
||||
public double Volume { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user