From 9a9403a32447f451a3d3dd1227feca202a2744bb Mon Sep 17 00:00:00 2001 From: Viacheslav Demydiuk Date: Sun, 7 Jan 2024 23:19:19 +0200 Subject: [PATCH] Added project Mt5Api to VS_2022 solution and disable some code for compilable --- MetaTraderApi_2022.sln | 14 + MtApi5/Events/OnBookEvent.cs | 2 +- MtApi5/Events/OnLastTimeBarEvent.cs | 4 +- MtApi5/Events/OnLockTicksEvent.cs | 2 +- MtApi5/Events/OnTickEvent.cs | 4 +- MtApi5/Events/OnTradeTransactionEvent.cs | 6 +- MtApi5/ExecutionException.cs | 6 +- MtApi5/LogConfigurator.cs | 133 ++++++ MtApi5/MqlParam.cs | 2 +- MtApi5/MqlTradeCheckResult.cs | 6 +- MtApi5/MqlTradeRequest.cs | 8 +- MtApi5/MqlTradeTransaction.cs | 2 +- MtApi5/Mt5BookEventArgs.cs | 2 +- MtApi5/Mt5Quote.cs | 11 +- MtApi5/Mt5TradeTransactionEventArgs.cs | 6 +- MtApi5/MtApi5.csproj | 136 +----- MtApi5/MtApi5Client.cs | 470 +++++++++++---------- MtApi5/MtConverters.cs | 4 +- MtApi5/Properties/AssemblyInfo.cs | 36 -- MtApi5/Requests/BuyRequest.cs | 4 +- MtApi5/Requests/CopyTicksRequest.cs | 2 +- MtApi5/Requests/ICustomRequest.cs | 6 +- MtApi5/Requests/IndicatorCreateRequest.cs | 8 +- MtApi5/Requests/MarketBookGetRequest.cs | 2 +- MtApi5/Requests/OrderCheckRequest.cs | 2 +- MtApi5/Requests/OrderCheckResult.cs | 2 +- MtApi5/Requests/OrderSendAsyncRequest.cs | 2 +- MtApi5/Requests/OrderSendRequest.cs | 2 +- MtApi5/Requests/OrderSendResult.cs | 2 +- MtApi5/Requests/PositionCloseResult.cs | 2 +- MtApi5/Requests/PositionOpenRequest.cs | 4 +- MtApi5/Requests/Response.cs | 4 +- MtApi5/Requests/SellRequest.cs | 4 +- MtApi5/Requests/SymbolInfoStringRequest.cs | 2 +- MtApi5/Requests/SymbolInfoStringResult.cs | 2 +- MtApi5/Requests/SymbolInfoTickRequest.cs | 9 +- MtApi5/packages.config | 0 MtClient/MtClient.csproj | 1 + 38 files changed, 456 insertions(+), 458 deletions(-) create mode 100755 MtApi5/LogConfigurator.cs delete mode 100755 MtApi5/Properties/AssemblyInfo.cs mode change 100644 => 100755 MtApi5/packages.config diff --git a/MetaTraderApi_2022.sln b/MetaTraderApi_2022.sln index fcbe7646..e6c715ba 100755 --- a/MetaTraderApi_2022.sln +++ b/MetaTraderApi_2022.sln @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MtService", "MtService\MtSe EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MT5Connector", "MT5Connector\MT5Connector.vcxproj", "{CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MtApi5", "MtApi5\MtApi5.csproj", "{AC8B5010-DA75-477E-9CA5-547C649E12D8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,18 @@ Global {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x64.Build.0 = Release|x64 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x86.ActiveCfg = Release|Win32 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x86.Build.0 = Release|Win32 + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x64.ActiveCfg = Debug|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x64.Build.0 = Debug|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x86.ActiveCfg = Debug|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x86.Build.0 = Debug|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|Any CPU.Build.0 = Release|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x64.ActiveCfg = Release|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x64.Build.0 = Release|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x86.ActiveCfg = Release|Any CPU + {AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MtApi5/Events/OnBookEvent.cs b/MtApi5/Events/OnBookEvent.cs index d3f57811..8657dca3 100644 --- a/MtApi5/Events/OnBookEvent.cs +++ b/MtApi5/Events/OnBookEvent.cs @@ -2,6 +2,6 @@ { internal class OnBookEvent { - public string Symbol { get; set; } + public string? Symbol { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Events/OnLastTimeBarEvent.cs b/MtApi5/Events/OnLastTimeBarEvent.cs index f6995043..3a0178e1 100644 --- a/MtApi5/Events/OnLastTimeBarEvent.cs +++ b/MtApi5/Events/OnLastTimeBarEvent.cs @@ -2,8 +2,8 @@ { public class OnLastTimeBarEvent { - public MqlRates Rates { get; set; } - public string Instrument { get; set; } + public MqlRates? Rates { get; set; } + public string? Instrument { get; set; } public int ExpertHandle { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Events/OnLockTicksEvent.cs b/MtApi5/Events/OnLockTicksEvent.cs index 0e460d79..7b6297df 100644 --- a/MtApi5/Events/OnLockTicksEvent.cs +++ b/MtApi5/Events/OnLockTicksEvent.cs @@ -2,6 +2,6 @@ { internal class OnLockTicksEvent { - public string Instrument { get; set; } + public string? Instrument { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Events/OnTickEvent.cs b/MtApi5/Events/OnTickEvent.cs index 42994636..e7874644 100644 --- a/MtApi5/Events/OnTickEvent.cs +++ b/MtApi5/Events/OnTickEvent.cs @@ -2,8 +2,8 @@ { internal class OnTickEvent { - public MqlTick Tick { get; set; } - public string Instrument { get; set; } + public MqlTick? Tick { get; set; } + public string? Instrument { get; set; } public int ExpertHandle { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Events/OnTradeTransactionEvent.cs b/MtApi5/Events/OnTradeTransactionEvent.cs index 6138e511..c812ccf9 100644 --- a/MtApi5/Events/OnTradeTransactionEvent.cs +++ b/MtApi5/Events/OnTradeTransactionEvent.cs @@ -2,8 +2,8 @@ { internal class OnTradeTransactionEvent { - public MqlTradeTransaction Trans { get; set; } - public MqlTradeRequest Request { get; set; } - public MqlTradeResult Result { get; set; } + public MqlTradeTransaction? Trans { get; set; } + public MqlTradeRequest? Request { get; set; } + public MqlTradeResult? Result { get; set; } } } \ No newline at end of file diff --git a/MtApi5/ExecutionException.cs b/MtApi5/ExecutionException.cs index 68a7511b..24706d16 100755 --- a/MtApi5/ExecutionException.cs +++ b/MtApi5/ExecutionException.cs @@ -1,10 +1,8 @@ -using System; - -namespace MtApi5 +namespace MtApi5 { public class ExecutionException: Exception { - public ExecutionException(ErrorCode errorCode, string message) + public ExecutionException(ErrorCode errorCode, string? message) :base(message) { ErrorCode = errorCode; diff --git a/MtApi5/LogConfigurator.cs b/MtApi5/LogConfigurator.cs new file mode 100755 index 00000000..125c3375 --- /dev/null +++ b/MtApi5/LogConfigurator.cs @@ -0,0 +1,133 @@ +using System; +using System.Diagnostics; +//using log4net; +//using log4net.Appender; +//using log4net.Core; +//using log4net.Layout; +//using log4net.Repository.Hierarchy; + +namespace MtApi5 +{ + 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 enum LogLevel + { + Off, + Debug, + Info + } + + public class LogConfigurator + { + private const string LogFileNameExtension = "log"; + + public static void Setup(string profileName) + { +#if (DEBUG) + const LogLevel logLevel = LogLevel.Debug; +#else + const LogLevel logLevel = LogLevel.Info; +#endif + Setup(profileName, logLevel); + } + + public static void Setup(string profileName, LogLevel logLevel) + { + if (string.IsNullOrEmpty(profileName)) + throw new ArgumentNullException(); + + //var hierarchy = (Hierarchy) LogManager.GetRepository(); + + ////check if logger is already configurated to avoid creation many empty logs files + //if (hierarchy.Configured) + // return; + + //var patternLayout = new PatternLayout + //{ + // ConversionPattern = "%date [%thread] %-5level %logger - %message%newline" + //}; + //patternLayout.ActivateOptions(); + + ////var filename = $"{DateTime.Now:yyyy-dd-M--HH-mm-ss}-{Process.GetCurrentProcess().Id}.{LogFileNameExtension}"; // This filename format keeps generating tons of log files with same content but different per-second/thread filenames until the harddisk have 0KB space left + //var filename = $"{DateTime.Now:yyyy-MM-dd}.{LogFileNameExtension}"; + + //var roller = new RollingFileAppender + //{ + // AppendToFile = true, + // File = $@"{System.IO.Path.GetTempPath()}{profileName}\Logs\{filename}", + // Layout = patternLayout, + // PreserveLogFileNameExtension = true, + // MaxSizeRollBackups = 5, + // MaximumFileSize = "1GB", + // RollingStyle = RollingFileAppender.RollingMode.Size, + // StaticLogFileName = false + //}; + //roller.ActivateOptions(); + //hierarchy.Root.AddAppender(roller); + //hierarchy.Root.Level = ConvertLogLevel(logLevel); + //hierarchy.Configured = true; + } + + public static MtLog GetLogger(Type type) + { + if (type == null) + throw new ArgumentNullException(nameof(type)); + + return new MtLog(type); + } + + //private static Level ConvertLogLevel(LogLevel logLevel) + //{ + // switch (logLevel) + // { + // case LogLevel.Debug: return Level.Debug; + // case LogLevel.Info: return Level.Info; + // case LogLevel.Off: return Level.Off; + // default: + // throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null); + // } + //} + } +} diff --git a/MtApi5/MqlParam.cs b/MtApi5/MqlParam.cs index ac7d4aa4..5db389c0 100644 --- a/MtApi5/MqlParam.cs +++ b/MtApi5/MqlParam.cs @@ -5,6 +5,6 @@ public ENUM_DATATYPE DataType { get; set; } public long? IntegerValue { get; set; } public double? DoubleValue { get; set; } - public string StringValue { get; set; } + public string? StringValue { get; set; } } } diff --git a/MtApi5/MqlTradeCheckResult.cs b/MtApi5/MqlTradeCheckResult.cs index 11d18e42..ed19fbd5 100755 --- a/MtApi5/MqlTradeCheckResult.cs +++ b/MtApi5/MqlTradeCheckResult.cs @@ -1,6 +1,4 @@ -// ReSharper disable InconsistentNaming - -namespace MtApi5 +namespace MtApi5 { public class MqlTradeCheckResult { @@ -11,7 +9,7 @@ namespace MtApi5 public double Margin { get; set; } // Margin requirements public double Margin_free { get; set; } // Free margin public double Margin_level { get; set; } // Margin level - public string Comment { get; set; } // Comment to the reply code (description of the error) + public string? Comment { get; set; } // Comment to the reply code (description of the error) public MqlTradeCheckResult(uint retcode , double balance diff --git a/MtApi5/MqlTradeRequest.cs b/MtApi5/MqlTradeRequest.cs index a3f3d118..8e813d52 100755 --- a/MtApi5/MqlTradeRequest.cs +++ b/MtApi5/MqlTradeRequest.cs @@ -1,6 +1,4 @@ -// ReSharper disable InconsistentNaming -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace MtApi5 { @@ -9,7 +7,7 @@ namespace MtApi5 public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type public ulong Magic { get; set; } // Expert Advisor ID (magic number) public ulong Order { get; set; } // Order ticket - public string Symbol { get; set; } // Trade symbol + public string? Symbol { get; set; } // Trade symbol public double Volume { get; set; } // Requested volume for a deal in lots public double Price { get; set; } // Price public double Stoplimit { get; set; } // StopLimit level of the order @@ -27,7 +25,7 @@ namespace MtApi5 set { MtExpiration = Mt5TimeConverter.ConvertToMtTime(value); } } - public string Comment { get; set; } // Order comment + public string? Comment { get; set; } // Order comment public ulong Position { get; set; } // Position ticket public ulong PositionBy { get; set; } // The ticket of an opposite position diff --git a/MtApi5/MqlTradeTransaction.cs b/MtApi5/MqlTradeTransaction.cs index 656f12fa..4f7418bb 100644 --- a/MtApi5/MqlTradeTransaction.cs +++ b/MtApi5/MqlTradeTransaction.cs @@ -7,7 +7,7 @@ namespace MtApi5 { public ulong Deal { get; set; } // Deal ticket public ulong Order { get; set; } // Order ticket - public string Symbol { get; set; } // Trade symbol name + public string? Symbol { get; set; } // Trade symbol name public ENUM_TRADE_TRANSACTION_TYPE Type { get; set; } // Trade transaction type public ENUM_ORDER_TYPE OrderType { get; set; } // Order type public ENUM_ORDER_STATE OrderState { get; set; } // Order state diff --git a/MtApi5/Mt5BookEventArgs.cs b/MtApi5/Mt5BookEventArgs.cs index 6a280cb5..dd9220bb 100644 --- a/MtApi5/Mt5BookEventArgs.cs +++ b/MtApi5/Mt5BookEventArgs.cs @@ -5,6 +5,6 @@ namespace MtApi5 public class Mt5BookEventArgs : EventArgs { public int ExpertHandle { get; set; } - public string Symbol { get; set; } //Symbol of OnBookEvent event. + public string? Symbol { get; set; } //Symbol of OnBookEvent event. } } \ No newline at end of file diff --git a/MtApi5/Mt5Quote.cs b/MtApi5/Mt5Quote.cs index c3ec47c4..ded45fcb 100755 --- a/MtApi5/Mt5Quote.cs +++ b/MtApi5/Mt5Quote.cs @@ -1,5 +1,4 @@ using System; -using MTApiService; namespace MtApi5 { @@ -22,10 +21,10 @@ namespace MtApi5 Ask = ask; } - internal Mt5Quote(MtQuote quote) - :this(quote.Instrument, quote.Bid, quote.Ask) - { - ExpertHandle = quote.ExpertHandle; - } + //internal Mt5Quote(MtQuote quote) + // :this(quote.Instrument, quote.Bid, quote.Ask) + //{ + // ExpertHandle = quote.ExpertHandle; + //} } } diff --git a/MtApi5/Mt5TradeTransactionEventArgs.cs b/MtApi5/Mt5TradeTransactionEventArgs.cs index 18f1d424..9476fbce 100644 --- a/MtApi5/Mt5TradeTransactionEventArgs.cs +++ b/MtApi5/Mt5TradeTransactionEventArgs.cs @@ -5,8 +5,8 @@ namespace MtApi5 public class Mt5TradeTransactionEventArgs : EventArgs { public int ExpertHandle { get; set; } - public MqlTradeTransaction Trans { get; set; } // trade transaction structure - public MqlTradeRequest Request { get; set; } // request structure - public MqlTradeResult Result { get; set; } // result structure + public MqlTradeTransaction? Trans { get; set; } // trade transaction structure + public MqlTradeRequest? Request { get; set; } // request structure + public MqlTradeResult? Result { get; set; } // result structure } } \ No newline at end of file diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj index 8596a9c9..be4e5dc8 100755 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -1,123 +1,15 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {AC8B5010-DA75-477E-9CA5-547C649E12D8} - Library - Properties - MtApi5 - MtApi5 - v4.0 - 512 - - - true - full - false - ..\build\products\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - ..\build\products\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.12.0.2\lib\net40\Newtonsoft.Json.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {DE76D5C7-B99C-4467-8408-78173BDD84E0} - MTApiService - - - - - - - + + + net8.0 + enable + enable + 2.0.0 + $(SolutionDir)build\products + + + + + + + \ No newline at end of file diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index a28348c0..e7700891 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -1,13 +1,7 @@ // ReSharper disable InconsistentNaming -using System; -using System.Collections.Generic; -using System.Linq; -using MTApiService; using System.Collections; -using System.ServiceModel; using MtApi5.Requests; using Newtonsoft.Json; -using System.Threading.Tasks; using MtApi5.Events; namespace MtApi5 @@ -35,7 +29,7 @@ namespace MtApi5 #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 volatile bool _isBacktestingMode; private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected; @@ -95,11 +89,13 @@ namespace MtApi5 /// ///Load quotes connected into MetaTrader API. /// - public IEnumerable GetQuotes() + public IEnumerable? GetQuotes() { - var client = Client; - var quotes = client?.GetQuotes(); - return quotes?.Select(q => new Mt5Quote(q)); + //TODO: !!! + //var client = Client; + //var quotes = client?.GetQuotes(); + //return quotes?.Select(q => new Mt5Quote(q)); + return null; } /// @@ -122,7 +118,7 @@ namespace MtApi5 /// However, this is not a sign of successful execution of a trade operation. /// For a more detailed description of the function execution result, analyze the fields of result structure. /// - public bool OrderSend(MqlTradeRequest request, out MqlTradeResult result) + public bool OrderSend(MqlTradeRequest request, out MqlTradeResult? result) { Log.Debug($"OrderSend: request = {request}"); @@ -154,7 +150,7 @@ namespace MtApi5 /// When processing the received request, a trade server sends a reply to a client terminal notifying of change in the current state of positions, /// orders and deals, which leads to the generation of the Trade event. /// - public bool OrderSendAsync(MqlTradeRequest request, out MqlTradeResult result) + public bool OrderSendAsync(MqlTradeRequest request, out MqlTradeResult? result) { Log.Debug($"OrderSend: request = {request}"); @@ -235,7 +231,7 @@ namespace MtApi5 /// However, this is not an indication that the requested trade operation is sure to be successfully executed. /// For a more detailed description of the function execution result, analyze the fields of the result structure. /// - public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult result) + public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult? result) { Log.Debug($"OrderCheck: request = {request}"); @@ -607,7 +603,7 @@ namespace MtApi5 ///Ticket of the closed position. ///Maximal deviation from the current price (in points). /// output result - public bool PositionClose(ulong ticket, ulong deviation, out MqlTradeResult result) + public bool PositionClose(ulong ticket, ulong deviation, out MqlTradeResult? result) { Log.Debug($"PositionClose: ticket = {ticket}, deviation = {deviation}"); @@ -626,7 +622,7 @@ namespace MtApi5 /// ///Ticket of the closed position. /// output result - public bool PositionClose(ulong ticket, out MqlTradeResult result) + public bool PositionClose(ulong ticket, out MqlTradeResult? result) { return PositionClose(ticket, ulong.MaxValue, out result); } @@ -661,7 +657,7 @@ namespace MtApi5 /// comment /// output result /// true - successful check of the basic structures, otherwise - false. - 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) { Log.Debug($"PositionOpen: symbol = {symbol}, orderType = {orderType}, volume = {volume}, price = {price}, sl = {sl}, tp = {tp}, comment = {comment}"); @@ -691,7 +687,7 @@ namespace MtApi5 /// Take Profit price /// output result /// true - successful check of the basic structures, otherwise - false. - public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, out MqlTradeResult result) + public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, out MqlTradeResult? result) { return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result); } @@ -735,7 +731,7 @@ namespace MtApi5 /// Take Profit price. /// Comment. /// true - successful check of the structures, otherwise - false. - 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) + 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}"); @@ -764,7 +760,7 @@ namespace MtApi5 /// Take Profit price. /// Comment. /// true - successful check of the structures, otherwise - false. - 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) + 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}"); @@ -926,28 +922,30 @@ namespace MtApi5 ///The start position for the first element to copy. ///Data count to copy. ///Array of MqlRates type. - public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out MqlRates[] ratesArray) + public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out MqlRates[]? ratesArray) { var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; ratesArray = null; - var retVal = SendCommand(Mt5CommandType.CopyRates, commandParameters); - if (retVal != null) - { - ratesArray = new MqlRates[retVal.Length]; - for(var i = 0; i < retVal.Length; i++) - { - ratesArray[i] = new MqlRates(retVal[i].time - , retVal[i].open - , retVal[i].high - , retVal[i].low - , retVal[i].close - , retVal[i].tick_volume - , retVal[i].spread - , retVal[i].real_volume); - } - } + //TODO: !!! + + //var retVal = SendCommand(Mt5CommandType.CopyRates, commandParameters); + //if (retVal != null) + //{ + // ratesArray = new MqlRates[retVal.Length]; + // for(var i = 0; i < retVal.Length; i++) + // { + // ratesArray[i] = new MqlRates(retVal[i].time + // , retVal[i].open + // , retVal[i].high + // , retVal[i].low + // , retVal[i].close + // , retVal[i].tick_volume + // , retVal[i].spread + // , retVal[i].real_volume); + // } + //} return ratesArray?.Length ?? 0; } @@ -960,28 +958,28 @@ namespace MtApi5 ///The start time for the first element to copy. ///Data count to copy. ///Array of MqlRates type. - public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out MqlRates[] ratesArray) + public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out MqlRates[]? ratesArray) { var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; ratesArray = null; - var retVal = SendCommand(Mt5CommandType.CopyRates1, commandParameters); - if (retVal != null) - { - ratesArray = new MqlRates[retVal.Length]; - for (var i = 0; i < retVal.Length; i++) - { - ratesArray[i] = new MqlRates(retVal[i].time - , retVal[i].open - , retVal[i].high - , retVal[i].low - , retVal[i].close - , retVal[i].tick_volume - , retVal[i].spread - , retVal[i].real_volume); - } - } + //var retVal = SendCommand(Mt5CommandType.CopyRates1, commandParameters); + //if (retVal != null) + //{ + // ratesArray = new MqlRates[retVal.Length]; + // for (var i = 0; i < retVal.Length; i++) + // { + // ratesArray[i] = new MqlRates(retVal[i].time + // , retVal[i].open + // , retVal[i].high + // , retVal[i].low + // , retVal[i].close + // , retVal[i].tick_volume + // , retVal[i].spread + // , retVal[i].real_volume); + // } + //} return ratesArray?.Length ?? 0; } @@ -994,28 +992,28 @@ namespace MtApi5 ///The start time for the first element to copy. ///Bar time, corresponding to the last element to copy. ///Array of MqlRates type. - public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out MqlRates[] ratesArray) + public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out MqlRates[]? ratesArray) { var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; ratesArray = null; - var retVal = SendCommand(Mt5CommandType.CopyRates2, commandParameters); - if (retVal != null) - { - ratesArray = new MqlRates[retVal.Length]; - for (var i = 0; i < retVal.Length; i++) - { - ratesArray[i] = new MqlRates(retVal[i].time - , retVal[i].open - , retVal[i].high - , retVal[i].low - , retVal[i].close - , retVal[i].tick_volume - , retVal[i].spread - , retVal[i].real_volume); - } - } + //var retVal = SendCommand(Mt5CommandType.CopyRates2, commandParameters); + //if (retVal != null) + //{ + // ratesArray = new MqlRates[retVal.Length]; + // for (var i = 0; i < retVal.Length; i++) + // { + // ratesArray[i] = new MqlRates(retVal[i].time + // , retVal[i].open + // , retVal[i].high + // , retVal[i].low + // , retVal[i].close + // , retVal[i].tick_volume + // , retVal[i].spread + // , retVal[i].real_volume); + // } + //} return ratesArray?.Length ?? 0; } @@ -1028,7 +1026,7 @@ namespace MtApi5 ///The start position for the first element to copy. ///Data count to copy. ///Array of DatetTme type. - public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out DateTime[] timeArray) + public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out DateTime[]? timeArray) { var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; @@ -1055,7 +1053,7 @@ namespace MtApi5 ///The start time for the first element to copy. ///Data count to copy. ///Array of DatetTme type. - public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out DateTime[] timeArray) + public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out DateTime[]? timeArray) { var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; @@ -1082,7 +1080,7 @@ namespace MtApi5 ///The start time for the first element to copy. ///Bar time corresponding to the last element to copy. ///Array of DatetTme type. - public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out DateTime[] timeArray) + public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out DateTime[]? timeArray) { var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; @@ -1486,7 +1484,7 @@ namespace MtApi5 ///The value of the timeframe can be one of values of the ENUM_TIMEFRAMES enumeration, 0 means the current timeframe. ///Indicator type, can be one of values of the ENUM_INDICATOR enumeration. ///An array of MqlParam type, whose elements contain the type and value of each input parameter of a technical indicator. - public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List parameters = null) + public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List? parameters = null) { var response = SendRequest(new IndicatorCreateRequest { @@ -1596,7 +1594,7 @@ namespace MtApi5 ///Symbol name. ///Identifier of a symbol property. ///Variable of the string type receiving the value of the requested property. - public bool SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId, out string value) + public bool SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId, out string? value) { var response = SendRequest(new SymbolInfoStringRequest { @@ -1699,7 +1697,7 @@ namespace MtApi5 /// ///Symbol name. ///Reference to an array of Depth of Market records. - public bool MarketBookGet(string symbol, out MqlBookInfo[] book) + public bool MarketBookGet(string symbol, out MqlBookInfo[]? book) { var response = SendRequest>(new MarketBookGetRequest { @@ -2255,7 +2253,7 @@ namespace MtApi5 ///The time coordinate of the first anchor. ///The price coordinate of the first anchor point. ///List of further anchor points (tuple of time and price). - public bool ObjectCreate(long chartId, string name, ENUM_OBJECT type, int nwin, DateTime time, double price, List> listOfCoordinates = null) + public bool ObjectCreate(long chartId, string name, ENUM_OBJECT type, int nwin, DateTime time, double price, List>? listOfCoordinates = null) { //Count the additional coordinates int iAdditionalCoordinates = (listOfCoordinates != null) ? listOfCoordinates.Count() : 0; @@ -2267,7 +2265,7 @@ namespace MtApi5 int nParameter = 6 + iAdditionalCoordinates * 2; var commandParameters = new ArrayList { nParameter, chartId, name, (int)type, nwin, Mt5TimeConverter.ConvertToMtTime(time), price }; - if (iAdditionalCoordinates > 0) + if (iAdditionalCoordinates > 0 && listOfCoordinates != null) { foreach (Tuple coordinateTuple in listOfCoordinates) { @@ -3307,97 +3305,99 @@ namespace MtApi5 #endregion #region Events - public event QuoteHandler QuoteUpdated; - public event EventHandler QuoteUpdate; - public event EventHandler QuoteAdded; - public event EventHandler QuoteRemoved; - public event EventHandler ConnectionStateChanged; - public event EventHandler OnTradeTransaction; - public event EventHandler OnBookEvent; - public event EventHandler OnLastTimeBar; - public event EventHandler OnLockTicks; + public event QuoteHandler? QuoteUpdated; + public event EventHandler? QuoteUpdate; + public event EventHandler? QuoteAdded; + public event EventHandler? QuoteRemoved; + public event EventHandler? ConnectionStateChanged; + public event EventHandler? OnTradeTransaction; + public event EventHandler? OnBookEvent; + public event EventHandler? OnLastTimeBar; + public event EventHandler? OnLockTicks; #endregion #region Private Methods - private MtClient Client - { - get - { - lock (_locker) - { - return _client; - } - } - } + //private MtClient Client + //{ + // get + // { + // lock (_locker) + // { + // return _client; + // } + // } + //} - private void Connect(MtClient client) - { - lock (_locker) - { - if (_connectionState == Mt5ConnectionState.Connected - || _connectionState == Mt5ConnectionState.Connecting) - { - return; - } + //private void Connect(MtClient client) + //{ + // lock (_locker) + // { + // if (_connectionState == Mt5ConnectionState.Connected + // || _connectionState == Mt5ConnectionState.Connecting) + // { + // return; + // } - _connectionState = Mt5ConnectionState.Connecting; - } + // _connectionState = Mt5ConnectionState.Connecting; + // } - string message = string.IsNullOrEmpty(client.Host) ? $"Connecting to localhost:{client.Port}" : $"Connecting to {client.Host}:{client.Port}"; - ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Connecting, message)); + // string message = string.IsNullOrEmpty(client.Host) ? $"Connecting to localhost:{client.Port}" : $"Connecting to {client.Host}:{client.Port}"; + // ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Connecting, message)); - var state = Mt5ConnectionState.Failed; + // var state = Mt5ConnectionState.Failed; - lock (_locker) - { - try - { - client.Connect(); - state = Mt5ConnectionState.Connected; - } - catch (Exception e) - { - client.Dispose(); - message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}"; + // lock (_locker) + // { + // try + // { + // client.Connect(); + // state = Mt5ConnectionState.Connected; + // } + // catch (Exception e) + // { + // client.Dispose(); + // message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}"; - Log.Warn(message); - } + // Log.Warn(message); + // } - if (state == Mt5ConnectionState.Connected) - { - _client = client; - _client.QuoteAdded += _client_QuoteAdded; - _client.QuoteRemoved += _client_QuoteRemoved; - _client.QuoteUpdated += _client_QuoteUpdated; - _client.ServerDisconnected += _client_ServerDisconnected; - _client.ServerFailed += _client_ServerFailed; - _client.MtEventReceived += _client_MtEventReceived; - message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}"; + // if (state == Mt5ConnectionState.Connected) + // { + // _client = client; + // _client.QuoteAdded += _client_QuoteAdded; + // _client.QuoteRemoved += _client_QuoteRemoved; + // _client.QuoteUpdated += _client_QuoteUpdated; + // _client.ServerDisconnected += _client_ServerDisconnected; + // _client.ServerFailed += _client_ServerFailed; + // _client.MtEventReceived += _client_MtEventReceived; + // message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}"; - Log.Info(message); - } + // Log.Info(message); + // } - _connectionState = state; - } + // _connectionState = state; + // } - ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message)); + // ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message)); - if (state == Mt5ConnectionState.Connected) - { - OnConnected(); - } - } + // if (state == Mt5ConnectionState.Connected) + // { + // OnConnected(); + // } + //} - private void _client_MtEventReceived(MtEvent e) - { - var eventType = (Mt5EventTypes)e.EventType; - _mtEventHandlers[eventType](e.ExpertHandle, e.Payload); - } + //private void _client_MtEventReceived(MtEvent e) + //{ + // var eventType = (Mt5EventTypes)e.EventType; + // _mtEventHandlers[eventType](e.ExpertHandle, e.Payload); + //} private void ReceivedOnTradeTransactionEvent(int expertHandler, string payload) { var e = JsonConvert.DeserializeObject(payload); + if (e == null) + return; OnTradeTransaction?.Invoke(this, new Mt5TradeTransactionEventArgs { ExpertHandle = expertHandler, @@ -3410,6 +3410,8 @@ namespace MtApi5 private void ReceivedOnBookEvent(int expertHandler, string payload) { var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Symbol)) + return; OnBookEvent?.Invoke(this, new Mt5BookEventArgs { ExpertHandle = expertHandler, @@ -3420,6 +3422,8 @@ namespace MtApi5 private void ReceivedOnTickEvent(int expertHandler, string payload) { var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null) + return; var quote = new Mt5Quote(e.Instrument, e.Tick.bid, e.Tick.ask) { ExpertHandle = expertHandler, @@ -3435,100 +3439,106 @@ namespace MtApi5 private void ReceivedOnLastTimeBarEvent(int expertHandler, string payload) { var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Rates == null) + return; OnLastTimeBar?.Invoke(this, new Mt5TimeBarArgs(expertHandler, e.Instrument, e.Rates)); } private void ReceivedOnLockTicksEvent(int expertHandler, string payload) { var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Instrument)) + return; OnLockTicks?.Invoke(this, new Mt5LockTicksEventArgs(e.Instrument)); } private void Connect(string host, int port) { - var client = new MtClient(host, port); - Connect(client); + //var client = new MtClient(host, port); + //Connect(client); } private void Connect(int port) { - var client = new MtClient(port); - Connect(client); + //var client = new MtClient(port); + //Connect(client); } private void Disconnect(bool failed) { - var state = failed ? Mt5ConnectionState.Failed : Mt5ConnectionState.Disconnected; - var message = failed ? "Connection Failed" : "Disconnected"; + //var state = failed ? Mt5ConnectionState.Failed : Mt5ConnectionState.Disconnected; + //var message = failed ? "Connection Failed" : "Disconnected"; - lock (_locker) - { - if (_connectionState == Mt5ConnectionState.Disconnected - || _connectionState == Mt5ConnectionState.Failed) - return; + //lock (_locker) + //{ + // if (_connectionState == Mt5ConnectionState.Disconnected + // || _connectionState == Mt5ConnectionState.Failed) + // return; - if (_client != null) - { - _client.QuoteAdded -= _client_QuoteAdded; - _client.QuoteRemoved -= _client_QuoteRemoved; - _client.QuoteUpdated -= _client_QuoteUpdated; - _client.ServerDisconnected -= _client_ServerDisconnected; - _client.ServerFailed -= _client_ServerFailed; - _client.MtEventReceived -= _client_MtEventReceived; + // if (_client != null) + // { + // _client.QuoteAdded -= _client_QuoteAdded; + // _client.QuoteRemoved -= _client_QuoteRemoved; + // _client.QuoteUpdated -= _client_QuoteUpdated; + // _client.ServerDisconnected -= _client_ServerDisconnected; + // _client.ServerFailed -= _client_ServerFailed; + // _client.MtEventReceived -= _client_MtEventReceived; - if (!failed) - { - _client.Disconnect(); - } + // if (!failed) + // { + // _client.Disconnect(); + // } - _client.Dispose(); + // _client.Dispose(); - _client = null; - } + // _client = null; + // } - _connectionState = state; - } + // _connectionState = state; + //} - Log.Info(message); + //Log.Info(message); - ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message)); + //ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message)); } - private T SendCommand(Mt5CommandType commandType, ArrayList commandParameters, Dictionary namedParams = null, int? executor = null) + private T SendCommand(Mt5CommandType commandType, ArrayList? commandParameters, Dictionary? namedParams = null, int? executor = null) { - MtResponse response; + T r; + //MtResponse response; - var client = Client; - if (client == null) - { - Log.Warn("SendCommand: No connection"); - throw new Exception("No connection"); - } + //var client = Client; + //if (client == null) + //{ + // Log.Warn("SendCommand: No connection"); + // throw new Exception("No connection"); + //} - try - { - response = client.SendCommand((int)commandType, commandParameters, namedParams, executor ?? ExecutorHandle); - } - catch (CommunicationException ex) - { - Log.Warn($"SendCommand: {ex.Message}"); - throw new Exception(ex.Message, ex); - } + //try + //{ + // response = client.SendCommand((int)commandType, commandParameters, namedParams, executor ?? ExecutorHandle); + //} + //catch (CommunicationException ex) + //{ + // Log.Warn($"SendCommand: {ex.Message}"); + // throw new Exception(ex.Message, ex); + //} - if (response == null) - { - Log.Warn("SendCommand: Response from MetaTrader is null"); - throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null"); - } + //if (response == null) + //{ + // Log.Warn("SendCommand: Response from MetaTrader is null"); + // throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null"); + //} - if (response.ErrorCode != 0) - { - Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}"); - throw new ExecutionException((ErrorCode)response.ErrorCode, response.ToString()); - } + //if (response.ErrorCode != 0) + //{ + // Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}"); + // throw new ExecutionException((ErrorCode)response.ErrorCode, response.ToString()); + //} - var responseValue = response.GetValue(); - return (T) responseValue; + //var responseValue = response.GetValue(); + //return (T) responseValue; + return default(T); } private T SendRequest(RequestBase request) @@ -3551,7 +3561,7 @@ namespace MtApi5 throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null"); } - var response = JsonConvert.DeserializeObject>(res); + var response = JsonConvert.DeserializeObject>(res) ?? throw new Exception("Failed to deserialize response"); if (response.ErrorCode != 0) { Log.Warn($"SendRequest: ErrorCode = {response.ErrorCode}. {response}"); @@ -3562,12 +3572,12 @@ namespace MtApi5 } - private void _client_QuoteUpdated(MtQuote quote) - { - if (quote == null) return; - QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote))); - QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask); - } + //private void _client_QuoteUpdated(MtQuote quote) + //{ + // if (quote == null) return; + // QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote))); + // QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask); + //} private void _client_ServerDisconnected(object sender, EventArgs e) { @@ -3579,21 +3589,21 @@ namespace MtApi5 Disconnect(true); } - private void _client_QuoteRemoved(MtQuote quote) - { - if (quote != null) - { - QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote))); - } - } + //private void _client_QuoteRemoved(MtQuote quote) + //{ + // if (quote != null) + // { + // QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote))); + // } + //} - private void _client_QuoteAdded(MtQuote quote) - { - if (quote != null) - { - QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote))); - } - } + //private void _client_QuoteAdded(MtQuote quote) + //{ + // if (quote != null) + // { + // QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote))); + // } + //} private void OnConnected() { diff --git a/MtApi5/MtConverters.cs b/MtApi5/MtConverters.cs index 96cacfec..d6cbcdad 100755 --- a/MtApi5/MtConverters.cs +++ b/MtApi5/MtConverters.cs @@ -1,6 +1,4 @@ -using System; -using MTApiService; -using System.Collections; +using System.Collections; namespace MtApi5 { diff --git a/MtApi5/Properties/AssemblyInfo.cs b/MtApi5/Properties/AssemblyInfo.cs deleted file mode 100755 index 69c9076d..00000000 --- a/MtApi5/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MtApi5")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MtApi5")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f3256daf-a5c0-422d-9d79-f7156cccb910")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.24")] -[assembly: AssemblyFileVersion("1.0.24")] diff --git a/MtApi5/Requests/BuyRequest.cs b/MtApi5/Requests/BuyRequest.cs index 911a0fcf..ae7cc951 100644 --- a/MtApi5/Requests/BuyRequest.cs +++ b/MtApi5/Requests/BuyRequest.cs @@ -5,10 +5,10 @@ public override RequestType RequestType => RequestType.Buy; public double Volume { get; set; } - public string Symbol { 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; } + public string? Comment { get; set; } } } diff --git a/MtApi5/Requests/CopyTicksRequest.cs b/MtApi5/Requests/CopyTicksRequest.cs index e31b90c4..11cefaf4 100755 --- a/MtApi5/Requests/CopyTicksRequest.cs +++ b/MtApi5/Requests/CopyTicksRequest.cs @@ -4,7 +4,7 @@ { public override RequestType RequestType => RequestType.CopyTicks; - public string SymbolName { get; set; } + public string? SymbolName { get; set; } public int Flags { get; set; } public ulong From { get; set; } public uint Count { get; set; } diff --git a/MtApi5/Requests/ICustomRequest.cs b/MtApi5/Requests/ICustomRequest.cs index bbf7d702..0cbeb064 100644 --- a/MtApi5/Requests/ICustomRequest.cs +++ b/MtApi5/Requests/ICustomRequest.cs @@ -12,10 +12,10 @@ namespace MtApi5.Requests Boolean = 3 } - public string Symbol { get; set; } + public required string Symbol { get; set; } public int Timeframe { get; set; } - public string Name { get; set; } - public ArrayList Params { get; set; } + public string? Name { get; set; } + public ArrayList? Params { get; set; } public ParametersType ParamsType { get; set; } public override RequestType RequestType => RequestType.iCustom; diff --git a/MtApi5/Requests/IndicatorCreateRequest.cs b/MtApi5/Requests/IndicatorCreateRequest.cs index e7af6543..63f4f05c 100644 --- a/MtApi5/Requests/IndicatorCreateRequest.cs +++ b/MtApi5/Requests/IndicatorCreateRequest.cs @@ -1,14 +1,12 @@ -using System.Collections.Generic; - -namespace MtApi5.Requests +namespace MtApi5.Requests { internal class IndicatorCreateRequest: RequestBase { public override RequestType RequestType => RequestType.IndicatorCreate; - public string Symbol { get; set; } + public string? Symbol { get; set; } public ENUM_TIMEFRAMES Period { get; set; } public ENUM_INDICATOR IndicatorType { get; set; } - public List Parameters { get; set; } + public List? Parameters { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/MarketBookGetRequest.cs b/MtApi5/Requests/MarketBookGetRequest.cs index e5fe7114..0c01c3e2 100644 --- a/MtApi5/Requests/MarketBookGetRequest.cs +++ b/MtApi5/Requests/MarketBookGetRequest.cs @@ -4,6 +4,6 @@ { public override RequestType RequestType => RequestType.MarketBookGet; - public string Symbol { get; set; } + public string? Symbol { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/OrderCheckRequest.cs b/MtApi5/Requests/OrderCheckRequest.cs index 6934e1e0..ed9ad1ea 100644 --- a/MtApi5/Requests/OrderCheckRequest.cs +++ b/MtApi5/Requests/OrderCheckRequest.cs @@ -4,7 +4,7 @@ { public override RequestType RequestType => RequestType.OrderCheck; - public MqlTradeRequest TradeRequest { get; set; } + public MqlTradeRequest? TradeRequest { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/OrderCheckResult.cs b/MtApi5/Requests/OrderCheckResult.cs index 5ec63707..9c98ff1c 100644 --- a/MtApi5/Requests/OrderCheckResult.cs +++ b/MtApi5/Requests/OrderCheckResult.cs @@ -3,6 +3,6 @@ public class OrderCheckResult { public bool RetVal { get; set; } - public MqlTradeCheckResult TradeCheckResult { get; set; } + public MqlTradeCheckResult? TradeCheckResult { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/OrderSendAsyncRequest.cs b/MtApi5/Requests/OrderSendAsyncRequest.cs index d4fa43a9..1330d420 100644 --- a/MtApi5/Requests/OrderSendAsyncRequest.cs +++ b/MtApi5/Requests/OrderSendAsyncRequest.cs @@ -4,6 +4,6 @@ { public override RequestType RequestType => RequestType.OrderSendAsync; - public MqlTradeRequest TradeRequest { get; set; } + public MqlTradeRequest? TradeRequest { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/OrderSendRequest.cs b/MtApi5/Requests/OrderSendRequest.cs index 94743258..7257d22b 100644 --- a/MtApi5/Requests/OrderSendRequest.cs +++ b/MtApi5/Requests/OrderSendRequest.cs @@ -4,6 +4,6 @@ { public override RequestType RequestType => RequestType.OrderSend; - public MqlTradeRequest TradeRequest { get; set; } + public MqlTradeRequest? TradeRequest { get; set; } } } diff --git a/MtApi5/Requests/OrderSendResult.cs b/MtApi5/Requests/OrderSendResult.cs index 45e44f56..827b2bde 100644 --- a/MtApi5/Requests/OrderSendResult.cs +++ b/MtApi5/Requests/OrderSendResult.cs @@ -3,6 +3,6 @@ internal class OrderSendResult { public bool RetVal { get; set; } - public MqlTradeResult TradeResult { get; set; } + public MqlTradeResult? TradeResult { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/PositionCloseResult.cs b/MtApi5/Requests/PositionCloseResult.cs index 7fb411a0..d290f625 100644 --- a/MtApi5/Requests/PositionCloseResult.cs +++ b/MtApi5/Requests/PositionCloseResult.cs @@ -3,6 +3,6 @@ internal class PositionCloseResult { public bool RetVal { get; set; } - public MqlTradeResult TradeResult { get; set; } + public MqlTradeResult? TradeResult { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/PositionOpenRequest.cs b/MtApi5/Requests/PositionOpenRequest.cs index 289b5516..8478d236 100644 --- a/MtApi5/Requests/PositionOpenRequest.cs +++ b/MtApi5/Requests/PositionOpenRequest.cs @@ -4,12 +4,12 @@ { public override RequestType RequestType => RequestType.PositionOpen; - public string Symbol { get; set; } + public string? Symbol { get; set; } public ENUM_ORDER_TYPE OrderType { get; set; } public double Volume { get; set; } public double Price { get; set; } public double Sl { get; set; } public double Tp { get; set; } - public string Comment { get; set; } + public string? Comment { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/Response.cs b/MtApi5/Requests/Response.cs index 831aef4c..cc338339 100644 --- a/MtApi5/Requests/Response.cs +++ b/MtApi5/Requests/Response.cs @@ -3,8 +3,8 @@ internal class Response { public int ErrorCode { get; set; } - public string ErrorMessage { get; set; } + public string? ErrorMessage { get; set; } - public T Value { get; set; } + public required T Value { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/SellRequest.cs b/MtApi5/Requests/SellRequest.cs index f276a8cc..ed797625 100644 --- a/MtApi5/Requests/SellRequest.cs +++ b/MtApi5/Requests/SellRequest.cs @@ -5,10 +5,10 @@ public override RequestType RequestType => RequestType.Sell; public double Volume { get; set; } - public string Symbol { 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; } + public string? Comment { get; set; } } } diff --git a/MtApi5/Requests/SymbolInfoStringRequest.cs b/MtApi5/Requests/SymbolInfoStringRequest.cs index 7b77b347..662a52c3 100644 --- a/MtApi5/Requests/SymbolInfoStringRequest.cs +++ b/MtApi5/Requests/SymbolInfoStringRequest.cs @@ -4,7 +4,7 @@ { public override RequestType RequestType => RequestType.SymbolInfoString; - public string SymbolName { get; set; } + public string? SymbolName { get; set; } public ENUM_SYMBOL_INFO_STRING PropId { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/SymbolInfoStringResult.cs b/MtApi5/Requests/SymbolInfoStringResult.cs index 38b186e5..de957e36 100644 --- a/MtApi5/Requests/SymbolInfoStringResult.cs +++ b/MtApi5/Requests/SymbolInfoStringResult.cs @@ -3,6 +3,6 @@ internal class SymbolInfoStringResult { public bool RetVal { get; set; } - public string StringVar { get; set; } + public string? StringVar { get; set; } } } \ No newline at end of file diff --git a/MtApi5/Requests/SymbolInfoTickRequest.cs b/MtApi5/Requests/SymbolInfoTickRequest.cs index 17131c88..f788e6cf 100644 --- a/MtApi5/Requests/SymbolInfoTickRequest.cs +++ b/MtApi5/Requests/SymbolInfoTickRequest.cs @@ -1,14 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi5.Requests +namespace MtApi5.Requests { internal class SymbolInfoTickRequest : RequestBase { public override RequestType RequestType => RequestType.SymbolInfoTick; - public string SymbolName { get; set; } + public string? SymbolName { get; set; } } } diff --git a/MtApi5/packages.config b/MtApi5/packages.config old mode 100644 new mode 100755 diff --git a/MtClient/MtClient.csproj b/MtClient/MtClient.csproj index bb23fb7d..64812869 100755 --- a/MtClient/MtClient.csproj +++ b/MtClient/MtClient.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + $(SolutionDir)build\products