mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-05 06:57:46 +00:00
MtApiService version 1.0.29. Added log wrapper class MtLog
This commit is contained in:
@@ -8,6 +8,50 @@ using log4net.Repository.Hierarchy;
|
|||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
public class MtLog
|
||||||
|
{
|
||||||
|
#region ctor
|
||||||
|
internal MtLog(Type type)
|
||||||
|
{
|
||||||
|
_log = LogManager.GetLogger(type);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public
|
||||||
|
|
||||||
|
public void Debug(object message)
|
||||||
|
{
|
||||||
|
_log.Debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(object message)
|
||||||
|
{
|
||||||
|
_log.Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fatal(object message)
|
||||||
|
{
|
||||||
|
_log.Fatal(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Info(object message)
|
||||||
|
{
|
||||||
|
_log.Info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warn(object message)
|
||||||
|
{
|
||||||
|
_log.Warn(message);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private
|
||||||
|
|
||||||
|
private readonly ILog _log;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
public class LogConfigurator
|
public class LogConfigurator
|
||||||
{
|
{
|
||||||
private const string LogFileNameExtension = "txt";
|
private const string LogFileNameExtension = "txt";
|
||||||
@@ -48,5 +92,13 @@ namespace MTApiService
|
|||||||
#endif
|
#endif
|
||||||
hierarchy.Configured = true;
|
hierarchy.Configured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MtLog GetLogger(Type type)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException(nameof(type));
|
||||||
|
|
||||||
|
return new MtLog(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.28.0")]
|
[assembly: AssemblyVersion("1.0.29.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.28.0")]
|
[assembly: AssemblyFileVersion("1.0.29.0")]
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MTApiService;
|
using MTApiService;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using MtApi5.Requests;
|
using MtApi5.Requests;
|
||||||
using MtApi5.Responses;
|
using MtApi5.Responses;
|
||||||
@@ -11,6 +12,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
public class MtApi5Client
|
public class MtApi5Client
|
||||||
{
|
{
|
||||||
#region MT Constants
|
#region MT Constants
|
||||||
@@ -32,9 +34,11 @@ namespace MtApi5
|
|||||||
|
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApi5Client));
|
||||||
|
|
||||||
private MtClient _client;
|
private MtClient _client;
|
||||||
private readonly object _locker = new object();
|
private readonly object _locker = new object();
|
||||||
private volatile bool _isBacktestingMode = false;
|
private volatile bool _isBacktestingMode;
|
||||||
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
|
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
|
||||||
private int _executorHandle;
|
private int _executorHandle;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -78,7 +82,7 @@ namespace MtApi5
|
|||||||
public IEnumerable<Mt5Quote> GetQuotes()
|
public IEnumerable<Mt5Quote> GetQuotes()
|
||||||
{
|
{
|
||||||
var client = Client;
|
var client = Client;
|
||||||
var quotes = client != null ? client.GetQuotes() : null;
|
var quotes = client?.GetQuotes();
|
||||||
return quotes?.Select(q => q.Parse());
|
return quotes?.Select(q => q.Parse());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,6 +537,7 @@ namespace MtApi5
|
|||||||
/// <param name="sl">Stop Loss price</param>
|
/// <param name="sl">Stop Loss price</param>
|
||||||
/// <param name="tp">Take Profit price</param>
|
/// <param name="tp">Take Profit price</param>
|
||||||
/// <param name="comment">comment</param>
|
/// <param name="comment">comment</param>
|
||||||
|
/// <param name="result">output result</param>
|
||||||
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
||||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result)
|
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result)
|
||||||
{
|
{
|
||||||
|
|||||||
+36
-5
@@ -6,14 +6,18 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
internal static class MtConverters
|
internal static class MtConverters
|
||||||
{
|
{
|
||||||
|
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtConverters));
|
||||||
|
|
||||||
#region Values Converters
|
#region Values Converters
|
||||||
public static Mt5Quote Parse(this MtQuote quote)
|
public static Mt5Quote Parse(this MtQuote quote)
|
||||||
{
|
{
|
||||||
return (quote != null) ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
return quote != null ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
result = null;
|
result = null;
|
||||||
|
|
||||||
@@ -38,17 +42,25 @@ namespace MtApi5
|
|||||||
|
|
||||||
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
|
retVal = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
result = null;
|
result = null;
|
||||||
|
|
||||||
@@ -72,18 +84,25 @@ namespace MtApi5
|
|||||||
|
|
||||||
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out double result)
|
public static bool ParseResult(this string inputString, char separator, out double result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
@@ -98,18 +117,25 @@ namespace MtApi5
|
|||||||
|
|
||||||
result = double.Parse(values[1]);
|
result = double.Parse(values[1]);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
|
|
||||||
from = new DateTime();
|
from = new DateTime();
|
||||||
@@ -130,12 +156,17 @@ namespace MtApi5
|
|||||||
var iTo= int.Parse(values[2]);
|
var iTo= int.Parse(values[2]);
|
||||||
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user