mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-18 05:08:11 +00:00
Issue #82: Refactored MQL5 expert to use json in function OrderSend
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -22,6 +23,8 @@ namespace MtApi5
|
||||
public ulong Position { get; set; } // Position ticket
|
||||
public ulong PositionBy { get; set; } // The ticket of an opposite position
|
||||
|
||||
public int MtExpiration => Mt5TimeConverter.ConvertToMtTime(Expiration);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Symbol}|{Volume}|{Price}|{Volume}|{Action}";
|
||||
|
||||
+25
-10
@@ -1,4 +1,6 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeResult
|
||||
{
|
||||
@@ -15,15 +17,28 @@
|
||||
Request_id = request_id;
|
||||
}
|
||||
|
||||
public uint Retcode { get; private set; } // Operation return code
|
||||
public ulong Deal { get; private set; } // Deal ticket, if it is performed
|
||||
public ulong Order { get; private set; } // Order ticket, if it is placed
|
||||
public double Volume { get; private set; } // Deal volume, confirmed by broker
|
||||
public double Price { get; private set; } // Deal price, confirmed by broker
|
||||
public double Bid { get; private set; } // Current Bid price
|
||||
public double Ask { get; private set; } // Current Ask price
|
||||
public string Comment { get; private set; } // Broker comment to operation (by default it is filled by the operation description)
|
||||
public uint Request_id { get; private set; } // Request ID set by the terminal during the dispatch
|
||||
internal MqlTradeResult(MqlTradeResult o)
|
||||
{
|
||||
Retcode = o.Retcode;
|
||||
Deal = o.Deal;
|
||||
Order = o.Order;
|
||||
Volume = o.Volume;
|
||||
Price = o.Price;
|
||||
Bid = o.Bid;
|
||||
Ask = o.Ask;
|
||||
Comment = o.Comment;
|
||||
Request_id = o.Request_id;
|
||||
}
|
||||
|
||||
public uint Retcode { get; } // Operation return code
|
||||
public ulong Deal { get; } // Deal ticket, if it is performed
|
||||
public ulong Order { get; } // Order ticket, if it is placed
|
||||
public double Volume { get; } // Deal volume, confirmed by broker
|
||||
public double Price { get; } // Deal price, confirmed by broker
|
||||
public double Bid { get; } // Current Bid price
|
||||
public double Ask { get; } // Current Ask price
|
||||
public string Comment { get; } // Broker comment to operation (by default it is filled by the operation description)
|
||||
public uint Request_id { get; } // Request ID set by the terminal during the dispatch
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
|
||||
// Chart Constants:
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Responses\CopyTicksResponse.cs" />
|
||||
<Compile Include="Responses\ICustomResponse.cs" />
|
||||
<Compile Include="Responses\OrderSendResponse.cs" />
|
||||
<Compile Include="Responses\ResponseBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
+16
-8
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MTApiService;
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.ServiceModel;
|
||||
using MtApi5.Requests;
|
||||
using MtApi5.Responses;
|
||||
@@ -12,7 +12,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class MtApi5Client
|
||||
{
|
||||
#region MT Constants
|
||||
@@ -117,13 +116,22 @@ namespace MtApi5
|
||||
return false;
|
||||
}
|
||||
|
||||
var commandParameters = request.ToArrayList();
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
TradeRequest = request
|
||||
});
|
||||
|
||||
var strResult = SendCommand<string>(Mt5CommandType.OrderSend, commandParameters);
|
||||
result = response?.Value?.TradeResult;
|
||||
return response?.Value != null && response.Value.RetVal;
|
||||
|
||||
Log.Debug($"OrderSend: strResult = {strResult}");
|
||||
|
||||
return strResult.ParseResult(ParamSeparator, out result);
|
||||
//var commandParameters = request.ToArrayList();
|
||||
|
||||
//var strResult = SendCommand<string>(Mt5CommandType.OrderSend, commandParameters);
|
||||
|
||||
//Log.Debug($"OrderSend: strResult = {strResult}");
|
||||
|
||||
//return strResult.ParseResult(ParamSeparator, out result);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -2398,7 +2406,7 @@ namespace MtApi5
|
||||
}
|
||||
|
||||
var responseValue = response.GetValue();
|
||||
return responseValue != null ? (T)responseValue : default(T);
|
||||
return (T) responseValue;
|
||||
}
|
||||
|
||||
private T SendRequest<T>(RequestBase request) where T : ResponseBase, new()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace MtApi5.Responses
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace MtApi5.Responses
|
||||
{
|
||||
internal class ICustomResponse: ResponseBase
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace MtApi5.Responses
|
||||
{
|
||||
internal class OrderSendResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeResult TradeResult { get; set; }
|
||||
}
|
||||
|
||||
internal class OrderSendResponse: ResponseBase
|
||||
{
|
||||
public OrderSendResult Value { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user