From 3785ee4ace496a1b8609b34f7bacd73f02cba2ed Mon Sep 17 00:00:00 2001 From: vdemydiuk Date: Mon, 10 Oct 2016 15:49:53 +0300 Subject: [PATCH] Small refactoring MtApi (MT5) and MtService. Started version 1.0.22 of MtService --- MTApiService/MtClient.cs | 185 ++--- MTApiService/MtResponse.cs | 2 - MTApiService/Properties/AssemblyInfo.cs | 4 +- MtApi5/ExtensionMethods.cs | 15 +- MtApi5/MtApi5.csproj | 1 + MtApi5/MtApi5Client.cs | 801 ++++++++++--------- TestClients/MtApi5TestClient/MainWindow.xaml | 4 +- 7 files changed, 488 insertions(+), 524 deletions(-) diff --git a/MTApiService/MtClient.cs b/MTApiService/MtClient.cs index 57bee4b4..5f6c0070 100755 --- a/MTApiService/MtClient.cs +++ b/MTApiService/MtClient.cs @@ -9,97 +9,93 @@ namespace MTApiService [CallbackBehavior(UseSynchronizationContext = false)] public class MtClient: IMtApiCallback, IDisposable { - private static string SERVICE_NAME = "MtApiService"; + private const string ServiceName = "MtApiService"; public delegate void MtQuoteHandler(MtQuote quote); + #region Fields + private MtApiProxy _proxy; + private bool _isConnected; + #endregion + #region Public Methods public void Open(string host, int port) { Debug.WriteLine("[INFO] MtClient::Open"); if (string.IsNullOrEmpty(host)) - throw new ArgumentNullException("host", "host is null or empty"); + throw new ArgumentNullException(nameof(host), "host is null or empty"); if (port < 0 || port > 65536) - throw new ArgumentOutOfRangeException("port", "port value is invalid"); + throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid"); - var urlService = string.Format("net.tcp://{0}:{1}/{2}", host, port, SERVICE_NAME); + var urlService = $"net.tcp://{host}:{port}/{ServiceName}"; - lock (mClientLocker) + if (_proxy != null) + return; + + var bind = new NetTcpBinding(SecurityMode.None) { - if (mProxy != null) - return; - - var bind = new NetTcpBinding(SecurityMode.None) + MaxReceivedMessageSize = 2147483647, + MaxBufferSize = 2147483647, + MaxBufferPoolSize = 2147483647, + ReaderQuotas = { - MaxReceivedMessageSize = 2147483647, - MaxBufferSize = 2147483647, - MaxBufferPoolSize = 2147483647, - ReaderQuotas = - { - MaxArrayLength = 2147483647, - MaxBytesPerRead = 2147483647, - MaxDepth = 2147483647, - MaxStringContentLength = 2147483647, - MaxNameTableCharCount = 2147483647 - } - }; - // Commented next statement since it is not required + MaxArrayLength = 2147483647, + MaxBytesPerRead = 2147483647, + MaxDepth = 2147483647, + MaxStringContentLength = 2147483647, + MaxNameTableCharCount = 2147483647 + } + }; + // Commented next statement since it is not required - mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService)); - mProxy.Faulted += mProxy_Faulted; - } + _proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService)); + _proxy.Faulted += ProxyFaulted; } public void Open(int port) { if (port < 0 || port > 65536) - throw new ArgumentOutOfRangeException("port", "port value is invalid"); + throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid"); - var urlService = string.Format("net.pipe://localhost/{0}_{1}", SERVICE_NAME, port); + var urlService = $"net.pipe://localhost/{ServiceName}_{port}"; - lock (mClientLocker) + if (_proxy != null) + return; + + var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { - if (mProxy != null) - return; - - var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) + MaxReceivedMessageSize = 2147483647, + MaxBufferSize = 2147483647, + MaxBufferPoolSize = 2147483647, + ReaderQuotas = { - MaxReceivedMessageSize = 2147483647, - MaxBufferSize = 2147483647, - MaxBufferPoolSize = 2147483647, - ReaderQuotas = - { - MaxArrayLength = 2147483647, - MaxBytesPerRead = 2147483647, - MaxDepth = 2147483647, - MaxStringContentLength = 2147483647, - MaxNameTableCharCount = 2147483647 - } - }; - // Commented next statement since it is not required + MaxArrayLength = 2147483647, + MaxBytesPerRead = 2147483647, + MaxDepth = 2147483647, + MaxStringContentLength = 2147483647, + MaxNameTableCharCount = 2147483647 + } + }; + // Commented next statement since it is not required - mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService)); - mProxy.Faulted += mProxy_Faulted; - } + _proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService)); + _proxy.Faulted += ProxyFaulted; } public void Close() { Debug.WriteLine("[INFO] MtClient::Close"); - lock (mClientLocker) + if (_proxy != null) { - if (mProxy != null) - { - mProxy.Faulted -= mProxy_Faulted; - mProxy.Dispose(); - mProxy = null; - } - - mIsConnected = false; + _proxy.Faulted -= ProxyFaulted; + _proxy.Dispose(); + _proxy = null; } + + _isConnected = false; } public void Connect() @@ -108,16 +104,13 @@ namespace MTApiService try { - lock (mClientLocker) - { - if (mProxy != null && mIsConnected == true) - return; + if (_proxy != null && _isConnected) + return; - mIsConnected = mProxy.Connect(); + _isConnected = _proxy.Connect(); - if (mIsConnected == false) - throw new Exception("Connected failed"); - } + if (_isConnected == false) + throw new Exception("Connected failed"); } catch (Exception ex) { @@ -125,7 +118,7 @@ namespace MTApiService Close(); - throw new CommunicationException(string.Format("Connection failed to service")); + throw new CommunicationException("Connection failed to service"); } } @@ -135,13 +128,9 @@ namespace MTApiService try { - lock (mClientLocker) - { - mIsConnected = false; + _isConnected = false; - if (mProxy != null) - mProxy.Disconnect(); - } + _proxy?.Disconnect(); } catch (Exception ex) { @@ -159,11 +148,8 @@ namespace MTApiService try { - lock (mClientLocker) - { - if (mProxy != null && mIsConnected == true) - result = mProxy.SendCommand(new MtCommand(commandType, commandParameters)); - } + if (_proxy != null && _isConnected) + result = _proxy.SendCommand(new MtCommand(commandType, commandParameters)); } catch (Exception ex) { @@ -185,11 +171,8 @@ namespace MTApiService try { - lock (mClientLocker) - { - if (mProxy != null && mIsConnected == true) - result = mProxy.GetQuotes(); - } + if (_proxy != null && _isConnected) + result = _proxy.GetQuotes(); } catch (Exception ex) { @@ -209,15 +192,11 @@ namespace MTApiService public void OnQuoteUpdate(MtQuote quote) { - if (quote != null) - { - if (QuoteUpdated != null) - { - QuoteUpdated(quote); - } + if (quote == null) return; - Debug.WriteLine("[INFO] MtClient::OnQuoteUpdate: " + quote); - } + QuoteUpdated?.Invoke(quote); + + Debug.WriteLine("[INFO] MtClient::OnQuoteUpdate: " + quote); } public void OnQuoteAdded(MtQuote quote) @@ -252,31 +231,19 @@ namespace MTApiService #endregion #region Properties - public bool IsConnected - { - get - { - lock (mClientLocker) - { - return mProxy.State == CommunicationState.Opened && mIsConnected == true; - } - } - } + public bool IsConnected => _proxy.State == CommunicationState.Opened && _isConnected; #endregion #region Private Methods - void mProxy_Faulted(object sender, EventArgs e) + private void ProxyFaulted(object sender, EventArgs e) { - Debug.WriteLine("[INFO] MtClient::mProxy_Faulted"); + Debug.WriteLine("[INFO] MtClient::ProxyFaulted"); Close(); - if (ServerFailed != null) - { - ServerFailed(this, EventArgs.Empty); - } + ServerFailed?.Invoke(this, EventArgs.Empty); } #endregion @@ -300,11 +267,5 @@ namespace MTApiService public event EventHandler ServerFailed; public event EventHandler MtEventReceived; #endregion - - #region Fields - private readonly object mClientLocker = new object(); - private MtApiProxy mProxy = null; - private bool mIsConnected = false; - #endregion } } diff --git a/MTApiService/MtResponse.cs b/MTApiService/MtResponse.cs index 060de1a1..0dfbf5db 100755 --- a/MTApiService/MtResponse.cs +++ b/MTApiService/MtResponse.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Runtime.Serialization; using System.Collections; diff --git a/MTApiService/Properties/AssemblyInfo.cs b/MTApiService/Properties/AssemblyInfo.cs index e248bf80..18b87533 100755 --- a/MTApiService/Properties/AssemblyInfo.cs +++ b/MTApiService/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 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.21.0")] -[assembly: AssemblyFileVersion("1.0.21.0")] +[assembly: AssemblyVersion("1.0.22.0")] +[assembly: AssemblyFileVersion("1.0.22.0")] diff --git a/MtApi5/ExtensionMethods.cs b/MtApi5/ExtensionMethods.cs index 3a55e5aa..d05395b8 100755 --- a/MtApi5/ExtensionMethods.cs +++ b/MtApi5/ExtensionMethods.cs @@ -1,28 +1,19 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace MtApi5 { - static class ExtensionMethods + internal static class ExtensionMethods { #region Event Methods public static void FireEvent(this EventHandler eventHandler, object sender) { - if (eventHandler != null) - { - eventHandler(sender, EventArgs.Empty); - } + eventHandler?.Invoke(sender, EventArgs.Empty); } public static void FireEvent(this EventHandler eventHandler, object sender, T e) where T : EventArgs { - if (eventHandler != null) - { - eventHandler(sender, e); - } + eventHandler?.Invoke(sender, e); } #endregion diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj index aedabacf..07da94b4 100755 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -35,6 +35,7 @@ + diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 279fbef4..c63ff088 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -21,7 +21,7 @@ namespace MtApi5 #endregion - private const char PARAM_SEPARATOR = ';'; + private const char ParamSeparator = ';'; public delegate void QuoteHandler(object sender, string symbol, double bid, double ask); @@ -85,8 +85,12 @@ namespace MtApi5 /// public IEnumerable GetQuotes() { - var quotes = _client.GetQuotes(); - return quotes != null ? (from q in quotes select q.Parse()) : null; + IEnumerable quotes; + lock (_client) + { + quotes = _client.GetQuotes(); + } + return quotes?.Select(q => q.Parse()); } /// @@ -121,7 +125,7 @@ namespace MtApi5 var strResult = SendCommand(Mt5CommandType.OrderSend, commandParameters); - return strResult.ParseResult(PARAM_SEPARATOR, out result); + return strResult.ParseResult(ParamSeparator, out result); } /// @@ -145,7 +149,7 @@ namespace MtApi5 var strResult = SendCommand(Mt5CommandType.OrderCalcMargin, commandParameters); - return strResult.ParseResult(PARAM_SEPARATOR, out margin); + return strResult.ParseResult(ParamSeparator, out margin); } /// @@ -157,20 +161,20 @@ namespace MtApi5 ///Type of the order, can be one of the two values of the ENUM_ORDER_TYPE enumeration: ORDER_TYPE_BUY or ORDER_TYPE_SELL. ///Symbol name. ///Volume of the trade operation. - ///Open price. - ///Close price. + ///Open price. + ///Close price. ///The variable, to which the calculated value of the profit will be written in case the function is successfully executed. ///The estimated profit value depends on many factors, and can differ in different market environments. /// /// The function returns true in case of success; otherwise it returns false. If an invalid order type is specified, the function will return false. /// - public bool OrderCalcProfit(ENUM_ORDER_TYPE action, string symbol, double volume, double price_open, double price_close, out double profit) + public bool OrderCalcProfit(ENUM_ORDER_TYPE action, string symbol, double volume, double priceOpen, double priceClose, out double profit) { - var commandParameters = new ArrayList { (int)action, symbol, volume, price_open, price_close }; + var commandParameters = new ArrayList { (int)action, symbol, volume, priceOpen, priceClose }; var strResult = SendCommand(Mt5CommandType.OrderCalcProfit, commandParameters); - return strResult.ParseResult(PARAM_SEPARATOR, out profit); + return strResult.ParseResult(ParamSeparator, out profit); } /// @@ -197,7 +201,7 @@ namespace MtApi5 var strResult = SendCommand(Mt5CommandType.OrderSend, commandParameters); - return strResult.ParseResult(PARAM_SEPARATOR, out result); + return strResult.ParseResult(ParamSeparator, out result); } /// @@ -233,10 +237,10 @@ namespace MtApi5 /// ///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. /// - ///Identifier of a position property. - public double PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE property_id) + ///Identifier of a position property. + public double PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.PositionGetDouble, commandParameters); } @@ -244,10 +248,10 @@ namespace MtApi5 /// ///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. /// - ///Identifier of a position property. - public long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id) + ///Identifier of a position property. + public long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.PositionGetInteger, commandParameters); } @@ -255,10 +259,10 @@ namespace MtApi5 /// ///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. /// - ///Identifier of a position property. - public string PositionGetString(ENUM_POSITION_PROPERTY_STRING property_id) + ///Identifier of a position property. + public string PositionGetString(ENUM_POSITION_PROPERTY_STRING propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.PositionGetString, commandParameters); } @@ -296,10 +300,10 @@ namespace MtApi5 /// ///Returns the requested property of an order, pre-selected using OrderGetTicket or OrderSelect. /// - /// Identifier of the order property. - public double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id) + /// Identifier of the order property. + public double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.OrderGetDouble, commandParameters); } @@ -307,10 +311,10 @@ namespace MtApi5 /// ///Returns the requested property of an order, pre-selected using OrderGetTicket or OrderSelect. /// - /// Identifier of the order property. - public long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) + /// Identifier of the order property. + public long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.OrderGetInteger, commandParameters); } @@ -318,10 +322,10 @@ namespace MtApi5 /// ///Returns the requested property of an order, pre-selected using OrderGetTicket or OrderSelect. /// - /// Identifier of the order property. - public string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id) + /// Identifier of the order property. + public string OrderGetString(ENUM_ORDER_PROPERTY_STRING propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.OrderGetString, commandParameters); } @@ -329,11 +333,11 @@ namespace MtApi5 /// ///Retrieves the history of deals and orders for the specified period of server time. /// - ///Start date of the request. - ///End date of the request. - public bool HistorySelect(DateTime from_date, DateTime to_date) + ///Start date of the request. + ///End date of the request. + public bool HistorySelect(DateTime fromDate, DateTime toDate) { - var commandParameters = new ArrayList { Mt5TimeConverter.ConvertToMtTime(from_date), Mt5TimeConverter.ConvertToMtTime(to_date) }; + var commandParameters = new ArrayList { Mt5TimeConverter.ConvertToMtTime(fromDate), Mt5TimeConverter.ConvertToMtTime(toDate) }; return SendCommand(Mt5CommandType.HistorySelect, commandParameters); } @@ -341,10 +345,10 @@ namespace MtApi5 /// ///Retrieves the history of deals and orders having the specified position identifier. /// - ///Position identifier that is set to every executed order and every deal. - public bool HistorySelectByPosition(long position_id) + ///Position identifier that is set to every executed order and every deal. + public bool HistorySelectByPosition(long positionId) { - var commandParameters = new ArrayList { position_id }; + var commandParameters = new ArrayList { positionId }; return SendCommand(Mt5CommandType.HistorySelectByPosition, commandParameters); } @@ -382,11 +386,11 @@ namespace MtApi5 /// ///Returns the requested order property. /// - ///Order ticket. - ///Identifier of the order property. - public double HistoryOrderGetDouble(ulong ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id) + ///Order ticket. + ///Identifier of the order property. + public double HistoryOrderGetDouble(ulong ticketNumber, ENUM_ORDER_PROPERTY_DOUBLE propertyId) { - var commandParameters = new ArrayList { ticket_number, (int)property_id }; + var commandParameters = new ArrayList { ticketNumber, (int)propertyId }; return SendCommand(Mt5CommandType.HistoryOrderGetDouble, commandParameters); } @@ -394,11 +398,11 @@ namespace MtApi5 /// ///Returns the requested property of an order. /// - ///Order ticket. - ///Identifier of the order property. - public long HistoryOrderGetInteger(ulong ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id) + ///Order ticket. + ///Identifier of the order property. + public long HistoryOrderGetInteger(ulong ticketNumber, ENUM_ORDER_PROPERTY_INTEGER propertyId) { - var commandParameters = new ArrayList { ticket_number, (int)property_id }; + var commandParameters = new ArrayList { ticketNumber, (int)propertyId }; return SendCommand(Mt5CommandType.HistoryOrderGetInteger, commandParameters); } @@ -406,11 +410,11 @@ namespace MtApi5 /// ///Returns the requested property of an order. /// - ///Order ticket. - ///Identifier of the order property. - public string HistoryOrderGetString(ulong ticket_number, ENUM_ORDER_PROPERTY_STRING property_id) + ///Order ticket. + ///Identifier of the order property. + public string HistoryOrderGetString(ulong ticketNumber, ENUM_ORDER_PROPERTY_STRING propertyId) { - var commandParameters = new ArrayList { ticket_number, (int)property_id }; + var commandParameters = new ArrayList { ticketNumber, (int)propertyId }; return SendCommand(Mt5CommandType.HistoryOrderGetString, commandParameters); } @@ -448,11 +452,11 @@ namespace MtApi5 /// ///Returns the requested property of a deal. /// - ///Deal ticket. - /// Identifier of a deal property. - public double HistoryDealGetDouble(ulong ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id) + ///Deal ticket. + /// Identifier of a deal property. + public double HistoryDealGetDouble(ulong ticketNumber, ENUM_DEAL_PROPERTY_DOUBLE propertyId) { - var commandParameters = new ArrayList { ticket_number, property_id }; + var commandParameters = new ArrayList { ticketNumber, propertyId }; return SendCommand(Mt5CommandType.HistoryDealGetDouble, commandParameters); } @@ -460,11 +464,11 @@ namespace MtApi5 /// ///Returns the requested property of a deal. /// - ///Deal ticket. - /// Identifier of a deal property. - public long HistoryDealGetInteger(ulong ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id) + ///Deal ticket. + /// Identifier of a deal property. + public long HistoryDealGetInteger(ulong ticketNumber, ENUM_DEAL_PROPERTY_INTEGER propertyId) { - var commandParameters = new ArrayList { ticket_number, property_id }; + var commandParameters = new ArrayList { ticketNumber, propertyId }; return SendCommand(Mt5CommandType.HistoryDealGetInteger, commandParameters); } @@ -472,11 +476,11 @@ namespace MtApi5 /// ///Returns the requested property of a deal. /// - ///Deal ticket. - /// Identifier of a deal property. - public string HistoryDealGetString(ulong ticket_number, ENUM_DEAL_PROPERTY_STRING property_id) + ///Deal ticket. + /// Identifier of a deal property. + public string HistoryDealGetString(ulong ticketNumber, ENUM_DEAL_PROPERTY_STRING propertyId) { - var commandParameters = new ArrayList { ticket_number, property_id }; + var commandParameters = new ArrayList { ticketNumber, propertyId }; return SendCommand(Mt5CommandType.HistoryDealGetString, commandParameters); } @@ -524,10 +528,10 @@ namespace MtApi5 /// ///Returns the value of the corresponding account property. /// - ///Identifier of the property. - public double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE property_id) + ///Identifier of the property. + public double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.AccountInfoDouble, commandParameters); } @@ -535,10 +539,10 @@ namespace MtApi5 /// ///Returns the value of the corresponding account property. /// - ///Identifier of the property. - public long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id) + ///Identifier of the property. + public long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.AccountInfoInteger, commandParameters); } @@ -546,10 +550,10 @@ namespace MtApi5 /// ///Returns the value of the corresponding account property. /// - ///Identifier of the property. - public string AccountInfoString(ENUM_ACCOUNT_INFO_STRING property_id) + ///Identifier of the property. + public string AccountInfoString(ENUM_ACCOUNT_INFO_STRING propertyId) { - var commandParameters = new ArrayList { (int)property_id }; + var commandParameters = new ArrayList { (int)propertyId }; return SendCommand(Mt5CommandType.AccountInfoString, commandParameters); } @@ -559,12 +563,12 @@ namespace MtApi5 /// ///Returns information about the state of historical data. /// - ///Symbol name. + ///Symbol name. /// Period. - ///Identifier of the requested property, value of the ENUM_SERIES_INFO_INTEGER enumeration. - public int SeriesInfoInteger(string symbol_name, ENUM_TIMEFRAMES timeframe, ENUM_SERIES_INFO_INTEGER prop_id) + ///Identifier of the requested property, value of the ENUM_SERIES_INFO_INTEGER enumeration. + public int SeriesInfoInteger(string symbolName, ENUM_TIMEFRAMES timeframe, ENUM_SERIES_INFO_INTEGER propId) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, (int)prop_id }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, (int)propId }; return SendCommand(Mt5CommandType.SeriesInfoInteger, commandParameters); } @@ -572,11 +576,11 @@ namespace MtApi5 /// ///Returns the number of bars count in the history for a specified symbol and period. /// - ///Symbol name. + ///Symbol name. /// Period. - public int Bars(string symbol_name, ENUM_TIMEFRAMES timeframe) + public int Bars(string symbolName, ENUM_TIMEFRAMES timeframe) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe }; + var commandParameters = new ArrayList { symbolName, (int)timeframe }; return SendCommand(Mt5CommandType.Bars, commandParameters); } @@ -584,13 +588,13 @@ namespace MtApi5 /// ///Returns the number of bars count in the history for a specified symbol and period. /// - ///Symbol name. + ///Symbol name. ///Period. - ///Bar time corresponding to the first element. - ///Bar time corresponding to the last element. - public int Bars(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time) + ///Bar time corresponding to the first element. + ///Bar time corresponding to the last element. + public int Bars(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; return SendCommand(Mt5CommandType.Bars2, commandParameters); } @@ -598,10 +602,10 @@ namespace MtApi5 /// ///Returns the number of calculated data for the specified indicator. /// - ///The indicator handle, returned by the corresponding indicator function. - public int BarsCalculated(int indicator_handle) + ///The indicator handle, returned by the corresponding indicator function. + public int BarsCalculated(int indicatorHandle) { - var commandParameters = new ArrayList { indicator_handle }; + var commandParameters = new ArrayList { indicatorHandle }; return SendCommand(Mt5CommandType.BarsCalculated, commandParameters); } @@ -609,81 +613,72 @@ namespace MtApi5 /// ///Gets data of a specified buffer of a certain indicator in the necessary quantity. /// - ///The indicator handle, returned by the corresponding indicator function. - ///The indicator buffer number. - ///The position of the first element to copy. + ///The indicator handle, returned by the corresponding indicator function. + ///The indicator buffer number. + ///The position of the first element to copy. ///Data count to copy. ///Array of double type. - public int CopyBuffer(int indicator_handle, int buffer_num, int start_pos, int count, out double[] buffer) + public int CopyBuffer(int indicatorHandle, int bufferNum, int startPos, int count, out double[] buffer) { - var commandParameters = new ArrayList { indicator_handle, buffer_num, start_pos, count }; + var commandParameters = new ArrayList { indicatorHandle, bufferNum, startPos, count }; buffer = SendCommand(Mt5CommandType.CopyBuffer, commandParameters); -<<<<<<< Updated upstream + return buffer?.Length ?? 0; -======= - return buffer != null ? buffer.Length : 0; ->>>>>>> Stashed changes } /// ///Gets data of a specified buffer of a certain indicator in the necessary quantity. /// - ///The indicator handle, returned by the corresponding indicator function. - ///The indicator buffer number. - ///Bar time, corresponding to the first element. + ///The indicator handle, returned by the corresponding indicator function. + ///The indicator buffer number. + ///Bar time, corresponding to the first element. ///Data count to copy. ///Array of double type. - public int CopyBuffer(int indicator_handle, int buffer_num, DateTime start_time, int count, out double[] buffer) + public int CopyBuffer(int indicatorHandle, int bufferNum, DateTime startTime, int count, out double[] buffer) { - var commandParameters = new ArrayList { indicator_handle, buffer_num, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { indicatorHandle, bufferNum, Mt5TimeConverter.ConvertToMtTime(startTime), count }; buffer = SendCommand(Mt5CommandType.CopyBuffer1, commandParameters); -<<<<<<< Updated upstream + return buffer?.Length ?? 0; -======= - return buffer != null ? buffer.Length : 0; ->>>>>>> Stashed changes } /// ///Gets data of a specified buffer of a certain indicator in the necessary quantity. /// - ///The indicator handle, returned by the corresponding indicator function. - ///The indicator buffer number. - ///Bar time, corresponding to the first element. - ///Bar time, corresponding to the last element. + ///The indicator handle, returned by the corresponding indicator function. + ///The indicator buffer number. + ///Bar time, corresponding to the first element. + ///Bar time, corresponding to the last element. ///Array of double type. - public int CopyBuffer(int indicator_handle, int buffer_num, DateTime start_time, DateTime stop_time, out double[] buffer) + public int CopyBuffer(int indicatorHandle, int bufferNum, DateTime startTime, DateTime stopTime, out double[] buffer) { - var commandParameters = new ArrayList { indicator_handle, buffer_num, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { indicatorHandle, bufferNum, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; buffer = SendCommand(Mt5CommandType.CopyBuffer1, commandParameters); -<<<<<<< Updated upstream + return buffer?.Length ?? 0; -======= - return buffer != null ? buffer.Length : 0; ->>>>>>> Stashed changes } /// - ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the rates_array array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. + ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of MqlRates type. - public int CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out MqlRates[] rates_array) + ///Array of MqlRates type. + public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out MqlRates[] ratesArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - rates_array = null; + ratesArray = null; var retVal = SendCommand(Mt5CommandType.CopyRates, commandParameters); if (retVal != null) { - rates_array = new MqlRates[retVal.Length]; - for(int i = 0; i < retVal.Length; i++) + ratesArray = new MqlRates[retVal.Length]; + for(var i = 0; i < retVal.Length; i++) { - rates_array[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) + ratesArray[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) , retVal[i].open , retVal[i].high , retVal[i].low @@ -694,30 +689,30 @@ namespace MtApi5 } } - return rates_array?.Length ?? 0; + return ratesArray?.Length ?? 0; } /// - ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the rates_array array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. + ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of MqlRates type. - public int CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out MqlRates[] rates_array) + ///Array of MqlRates type. + public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out MqlRates[] ratesArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - rates_array = null; + ratesArray = null; var retVal = SendCommand(Mt5CommandType.CopyRates1, commandParameters); if (retVal != null) { - rates_array = new MqlRates[retVal.Length]; - for (int i = 0; i < retVal.Length; i++) + ratesArray = new MqlRates[retVal.Length]; + for (var i = 0; i < retVal.Length; i++) { - rates_array[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) + ratesArray[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) , retVal[i].open , retVal[i].high , retVal[i].low @@ -728,30 +723,30 @@ namespace MtApi5 } } - return rates_array?.Length ?? 0; + return ratesArray?.Length ?? 0; } /// - ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the rates_array array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. + ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///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 symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out MqlRates[] rates_array) + ///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) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - rates_array = null; + ratesArray = null; var retVal = SendCommand(Mt5CommandType.CopyRates2, commandParameters); if (retVal != null) { - rates_array = new MqlRates[retVal.Length]; - for (int i = 0; i < retVal.Length; i++) + ratesArray = new MqlRates[retVal.Length]; + for (var i = 0; i < retVal.Length; i++) { - rates_array[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) + ratesArray[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) , retVal[i].open , retVal[i].high , retVal[i].low @@ -762,445 +757,445 @@ namespace MtApi5 } } - return rates_array?.Length ?? 0; + return ratesArray?.Length ?? 0; } /// ///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of DatetTme type. - public int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out DateTime[] time_array) + ///Array of DatetTme type. + public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out DateTime[] timeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - time_array = null; + timeArray = null; var retVal = SendCommand(Mt5CommandType.CopyTime, commandParameters); if (retVal != null) { - time_array = new DateTime[retVal.Length]; - for (int i = 0; i < retVal.Length; i++) + timeArray = new DateTime[retVal.Length]; + for (var i = 0; i < retVal.Length; i++) { - time_array[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); + timeArray[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); } } - return time_array?.Length ?? 0; + return timeArray?.Length ?? 0; } /// ///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of DatetTme type. - public int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out DateTime[] time_array) + ///Array of DatetTme type. + public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out DateTime[] timeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - time_array = null; + timeArray = null; var retVal = SendCommand(Mt5CommandType.CopyTime1, commandParameters); if (retVal != null) { - time_array = new DateTime[retVal.Length]; - for (int i = 0; i < retVal.Length; i++) + timeArray = new DateTime[retVal.Length]; + for (var i = 0; i < retVal.Length; i++) { - time_array[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); + timeArray[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); } } - return time_array?.Length ?? 0; + return timeArray?.Length ?? 0; } /// ///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///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 symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out DateTime[] time_array) + ///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) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - time_array = null; + timeArray = null; var retVal = SendCommand(Mt5CommandType.CopyTime2, commandParameters); if (retVal != null) { - time_array = new DateTime[retVal.Length]; - for (int i = 0; i < retVal.Length; i++) + timeArray = new DateTime[retVal.Length]; + for (var i = 0; i < retVal.Length; i++) { - time_array[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); + timeArray[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); } } - return time_array?.Length ?? 0; + return timeArray?.Length ?? 0; } /// ///The function gets into open_array the history data of bar open prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyOpen(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] open_array) + ///Array of double type. + public int CopyOpen(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] openArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - open_array = SendCommand(Mt5CommandType.CopyOpen, commandParameters); + openArray = SendCommand(Mt5CommandType.CopyOpen, commandParameters); - return open_array?.Length ?? 0; + return openArray?.Length ?? 0; } /// ///The function gets into open_array the history data of bar open prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyOpen(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] open_array) + ///Array of double type. + public int CopyOpen(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] openArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - open_array = SendCommand(Mt5CommandType.CopyOpen1, commandParameters); + openArray = SendCommand(Mt5CommandType.CopyOpen1, commandParameters); - return open_array?.Length ?? 0; + return openArray?.Length ?? 0; } /// ///The function gets into open_array the history data of bar open prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of double type. - public int CopyOpen(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] open_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of double type. + public int CopyOpen(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] openArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - open_array = SendCommand(Mt5CommandType.CopyOpen2, commandParameters); + openArray = SendCommand(Mt5CommandType.CopyOpen2, commandParameters); - return open_array?.Length ?? 0; + return openArray?.Length ?? 0; } /// ///The function gets into high_array the history data of highest bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyHigh(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] high_array) + ///Array of double type. + public int CopyHigh(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] highArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - high_array = SendCommand(Mt5CommandType.CopyHigh, commandParameters); + highArray = SendCommand(Mt5CommandType.CopyHigh, commandParameters); - return high_array?.Length ?? 0; + return highArray?.Length ?? 0; } /// ///The function gets into high_array the history data of highest bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyHigh(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] high_array) + ///Array of double type. + public int CopyHigh(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] highArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - high_array = SendCommand(Mt5CommandType.CopyHigh1, commandParameters); + highArray = SendCommand(Mt5CommandType.CopyHigh1, commandParameters); - return high_array?.Length ?? 0; + return highArray?.Length ?? 0; } /// ///The function gets into high_array the history data of highest bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of double type. - public int CopyHigh(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] high_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of double type. + public int CopyHigh(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] highArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - high_array = SendCommand(Mt5CommandType.CopyHigh2, commandParameters); + highArray = SendCommand(Mt5CommandType.CopyHigh2, commandParameters); - return high_array?.Length ?? 0; + return highArray?.Length ?? 0; } /// ///The function gets into low_array the history data of minimal bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] low_array) + ///Array of double type. + public int CopyLow(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] lowArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - low_array = SendCommand(Mt5CommandType.CopyLow, commandParameters); + lowArray = SendCommand(Mt5CommandType.CopyLow, commandParameters); - return low_array?.Length ?? 0; + return lowArray?.Length ?? 0; } /// ///The function gets into low_array the history data of minimal bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] low_array) + ///Array of double type. + public int CopyLow(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] lowArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - low_array = SendCommand(Mt5CommandType.CopyLow1, commandParameters); + lowArray = SendCommand(Mt5CommandType.CopyLow1, commandParameters); - return low_array?.Length ?? 0; + return lowArray?.Length ?? 0; } /// ///The function gets into low_array the history data of minimal bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of double type. - public int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] low_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of double type. + public int CopyLow(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] lowArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - low_array = SendCommand(Mt5CommandType.CopyLow2, commandParameters); + lowArray = SendCommand(Mt5CommandType.CopyLow2, commandParameters); - return low_array?.Length ?? 0; + return lowArray?.Length ?? 0; } /// ///The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] close_array) + ///Array of double type. + public int CopyClose(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] closeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - close_array = SendCommand(Mt5CommandType.CopyClose, commandParameters); + closeArray = SendCommand(Mt5CommandType.CopyClose, commandParameters); - return close_array?.Length ?? 0; + return closeArray?.Length ?? 0; } /// ///The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of double type. - public int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] close_array) + ///Array of double type. + public int CopyClose(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] closeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - close_array = SendCommand(Mt5CommandType.CopyClose1, commandParameters); + closeArray = SendCommand(Mt5CommandType.CopyClose1, commandParameters); - return close_array?.Length ?? 0; + return closeArray?.Length ?? 0; } /// ///The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of double type. - public int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] close_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of double type. + public int CopyClose(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] closeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - close_array = SendCommand(Mt5CommandType.CopyClose2, commandParameters); + closeArray = SendCommand(Mt5CommandType.CopyClose2, commandParameters); - return close_array?.Length ?? 0; + return closeArray?.Length ?? 0; } /// ///The function gets into volume_array the history data of tick volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of long type. - public int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out long[] volume_array) + ///Array of long type. + public int CopyTickVolume(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out long[] volumeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - volume_array = SendCommand(Mt5CommandType.CopyTickVolume, commandParameters); + volumeArray = SendCommand(Mt5CommandType.CopyTickVolume, commandParameters); - return volume_array?.Length ?? 0; + return volumeArray?.Length ?? 0; } /// ///The function gets into volume_array the history data of tick volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of long type. - public int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out long[] volume_array) + ///Array of long type. + public int CopyTickVolume(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out long[] volumeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - volume_array = SendCommand(Mt5CommandType.CopyTickVolume1, commandParameters); + volumeArray = SendCommand(Mt5CommandType.CopyTickVolume1, commandParameters); - return volume_array?.Length ?? 0; + return volumeArray?.Length ?? 0; } /// ///The function gets into volume_array the history data of tick volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of long type. - public int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out long[] volume_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of long type. + public int CopyTickVolume(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out long[] volumeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - volume_array = SendCommand(Mt5CommandType.CopyTickVolume2, commandParameters); + volumeArray = SendCommand(Mt5CommandType.CopyTickVolume2, commandParameters); - return volume_array?.Length ?? 0; + return volumeArray?.Length ?? 0; } /// ///The function gets into volume_array the history data of trade volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of long type. - public int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out long[] volume_array) + ///Array of long type. + public int CopyRealVolume(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out long[] volumeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - volume_array = SendCommand(Mt5CommandType.CopyRealVolume, commandParameters); + volumeArray = SendCommand(Mt5CommandType.CopyRealVolume, commandParameters); - return volume_array?.Length ?? 0; + return volumeArray?.Length ?? 0; } /// ///The function gets into volume_array the history data of trade volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of long type. - public int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out long[] volume_array) + ///Array of long type. + public int CopyRealVolume(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out long[] volumeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - volume_array = SendCommand(Mt5CommandType.CopyRealVolume1, commandParameters); + volumeArray = SendCommand(Mt5CommandType.CopyRealVolume1, commandParameters); - return volume_array?.Length ?? 0; + return volumeArray?.Length ?? 0; } /// ///The function gets into volume_array the history data of trade volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of long type. - public int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out long[] volume_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of long type. + public int CopyRealVolume(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out long[] volumeArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - volume_array = SendCommand(Mt5CommandType.CopyRealVolume2, commandParameters); + volumeArray = SendCommand(Mt5CommandType.CopyRealVolume2, commandParameters); - return volume_array?.Length ?? 0; + return volumeArray?.Length ?? 0; } /// ///The function gets into spread_array the history data of spread values for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start position for the first element to copy. + ///The start position for the first element to copy. ///Data count to copy. - ///Array of long type. - public int CopySpread(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out int[] spread_array) + ///Array of long type. + public int CopySpread(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out int[] spreadArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count }; - spread_array = SendCommand(Mt5CommandType.CopySpread, commandParameters); + spreadArray = SendCommand(Mt5CommandType.CopySpread, commandParameters); - return spread_array?.Length ?? 0; + return spreadArray?.Length ?? 0; } /// ///The function gets into spread_array the history data of spread values for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. + ///The start time for the first element to copy. ///Data count to copy. - ///Array of long type. - public int CopySpread(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out int[] spread_array) + ///Array of long type. + public int CopySpread(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out int[] spreadArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count }; - spread_array = SendCommand(Mt5CommandType.CopySpread1, commandParameters); + spreadArray = SendCommand(Mt5CommandType.CopySpread1, commandParameters); - return spread_array?.Length ?? 0; + return spreadArray?.Length ?? 0; } /// ///The function gets into spread_array the history data of spread values for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// - ///Symbol name. + ///Symbol name. ///Period. - ///The start time for the first element to copy. - ///The start time for the last element to copy. - ///Array of long type. - public int CopySpread(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out int[] spread_array) + ///The start time for the first element to copy. + ///The start time for the last element to copy. + ///Array of long type. + public int CopySpread(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out int[] spreadArray) { - var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; + var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) }; - spread_array = SendCommand(Mt5CommandType.CopySpread2, commandParameters); + spreadArray = SendCommand(Mt5CommandType.CopySpread2, commandParameters); - return spread_array?.Length ?? 0; + return spreadArray?.Length ?? 0; } #endregion @@ -1232,11 +1227,11 @@ namespace MtApi5 /// ///Selects a symbol in the Market Watch window or removes a symbol from the window. /// - ///Symbol name. + ///Symbol name. ///Switch. If the value is false, a symbol should be removed from MarketWatch, otherwise a symbol should be selected in this window. A symbol can't be removed if the symbol chart is open, or there are open positions for this symbol. - public bool SymbolSelect(string name, bool selected) + public bool SymbolSelect(string symbolName, bool selected) { - var commandParameters = new ArrayList { name, selected }; + var commandParameters = new ArrayList { symbolName, selected }; return SendCommand(Mt5CommandType.SymbolSelect, commandParameters); } @@ -1244,10 +1239,10 @@ namespace MtApi5 /// ///The function checks whether data of a selected symbol in the terminal are synchronized with data on the trade server. /// - ///Symbol name. - public bool SymbolIsSynchronized(string name) + ///Symbol name. + public bool SymbolIsSynchronized(string symbolName) { - var commandParameters = new ArrayList { name }; + var commandParameters = new ArrayList { symbolName }; return SendCommand(Mt5CommandType.SymbolIsSynchronized, commandParameters); } @@ -1255,11 +1250,11 @@ namespace MtApi5 /// ///Returns the corresponding property of a specified symbol. /// - ///Symbol name. - ///Identifier of a symbol property. - public double SymbolInfoDouble(string name, ENUM_SYMBOL_INFO_DOUBLE prop_id) + ///Symbol name. + ///Identifier of a symbol property. + public double SymbolInfoDouble(string symbolName, ENUM_SYMBOL_INFO_DOUBLE propId) { - var commandParameters = new ArrayList { name, (int)prop_id }; + var commandParameters = new ArrayList { symbolName, (int)propId }; return SendCommand(Mt5CommandType.SymbolInfoDouble, commandParameters); } @@ -1267,11 +1262,11 @@ namespace MtApi5 /// ///Returns the corresponding property of a specified symbol. /// - ///Symbol name. - ///Identifier of a symbol property. - public long SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id) + ///Symbol name. + ///Identifier of a symbol property. + public long SymbolInfoInteger(string symbolName, ENUM_SYMBOL_INFO_INTEGER propId) { - var commandParameters = new ArrayList { name, (int)prop_id }; + var commandParameters = new ArrayList { symbolName, (int)propId }; return SendCommand(Mt5CommandType.SymbolInfoInteger, commandParameters); } @@ -1279,11 +1274,11 @@ namespace MtApi5 /// ///Returns the corresponding property of a specified symbol. /// - ///Symbol name. - ///Identifier of a symbol property. - public string SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING prop_id) + ///Symbol name. + ///Identifier of a symbol property. + public string SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId) { - var commandParameters = new ArrayList { name, (int)prop_id }; + var commandParameters = new ArrayList { symbolName, (int)propId }; return SendCommand(Mt5CommandType.SymbolInfoString, commandParameters); } @@ -1315,34 +1310,34 @@ namespace MtApi5 ///Allows receiving time of beginning and end of the specified quoting sessions for a specified symbol and weekday. /// ///Symbol name. - ///Day of the week - ///Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0. + ///Day of the week + ///Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0. ///Session beginning time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. ///Session end time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. - public bool SymbolInfoSessionQuote(string name, ENUM_DAY_OF_WEEK day_of_week, uint session_index, out DateTime from, out DateTime to) + public bool SymbolInfoSessionQuote(string name, ENUM_DAY_OF_WEEK dayOfWeek, uint sessionIndex, out DateTime from, out DateTime to) { - var commandParameters = new ArrayList { name, (int)day_of_week, session_index }; + var commandParameters = new ArrayList { name, (int)dayOfWeek, sessionIndex }; string strResult = SendCommand(Mt5CommandType.SymbolInfoSessionQuote, commandParameters); - return strResult.ParseResult(PARAM_SEPARATOR, out from, out to); + return strResult.ParseResult(ParamSeparator, out from, out to); } /// ///Allows receiving time of beginning and end of the specified trading sessions for a specified symbol and weekday. /// ///Symbol name. - ///Day of the week - ///Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0. + ///Day of the week + ///Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0. ///Session beginning time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. ///Session end time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. - public bool SymbolInfoSessionTrade(string name, ENUM_DAY_OF_WEEK day_of_week, uint session_index, out DateTime from, out DateTime to) + public bool SymbolInfoSessionTrade(string name, ENUM_DAY_OF_WEEK dayOfWeek, uint sessionIndex, out DateTime from, out DateTime to) { - var commandParameters = new ArrayList { name, (int)day_of_week, session_index }; + var commandParameters = new ArrayList { name, (int)dayOfWeek, sessionIndex }; string strResult = SendCommand(Mt5CommandType.SymbolInfoSessionTrade, commandParameters); - return strResult.ParseResult(PARAM_SEPARATOR, out from, out to); + return strResult.ParseResult(ParamSeparator, out from, out to); } /// @@ -1419,8 +1414,11 @@ namespace MtApi5 try { - _client.Open(host, port); - _client.Connect(); + lock (_client) + { + _client.Open(host, port); + _client.Connect(); + } } catch (Exception e) { @@ -1445,8 +1443,11 @@ namespace MtApi5 try { - _client.Open(port); - _client.Connect(); + lock (_client) + { + _client.Open(port); + _client.Connect(); + } } catch (Exception e) { @@ -1466,8 +1467,11 @@ namespace MtApi5 private void Disconnect() { - _client.Disconnect(); - _client.Close(); + lock (_client) + { + _client.Disconnect(); + _client.Close(); + } ConnectionState = Mt5ConnectionState.Disconnected; ConnectionStateChanged.FireEvent(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Disconnected, "Disconnected")); @@ -1478,53 +1482,60 @@ namespace MtApi5 MtResponse response; try { - response = _client.SendCommand((int)commandType, commandParameters); + lock (_client) + { + response = _client.SendCommand((int) commandType, commandParameters); + } } catch (CommunicationException ex) { throw new Exception(ex.Message, ex); } - if (response is MtResponseDouble) - return (T)Convert.ChangeType(((MtResponseDouble)response).Value, typeof(T)); + var responseValue = GetResponseValue(response); + return responseValue != null ? (T) responseValue : default(T); + } - if (response is MtResponseInt) - return (T)Convert.ChangeType(((MtResponseInt)response).Value, typeof(T)); + private static object GetResponseValue(MtResponse response) + { + var doubleValue = (response as MtResponseDouble)?.Value; + if (doubleValue != null) return doubleValue; - if (response is MtResponseLong) - return (T)Convert.ChangeType(((MtResponseLong)response).Value, typeof(T)); + var intValue = (response as MtResponseInt)?.Value; + if (intValue != null) return intValue; - if (response is MtResponseULong) - return (T)Convert.ChangeType(((MtResponseULong)response).Value, typeof(T)); + var longValue = (response as MtResponseLong)?.Value; + if (longValue != null) return longValue; - if (response is MtResponseBool) - return (T)Convert.ChangeType(((MtResponseBool)response).Value, typeof(T)); + var ulongValue = (response as MtResponseULong)?.Value; + if (ulongValue != null) return ulongValue; - if (response is MtResponseString) - return (T)Convert.ChangeType(((MtResponseString)response).Value, typeof(T)); + var boolValue = (response as MtResponseBool)?.Value; + if (boolValue != null) return boolValue; - if (response is MtResponseDoubleArray) - return (T)Convert.ChangeType(((MtResponseDoubleArray)response).Value, typeof(T)); + var stringValue = (response as MtResponseString)?.Value; + if (stringValue != null) return stringValue; - if (response is MtResponseIntArray) - return (T)Convert.ChangeType(((MtResponseIntArray)response).Value, typeof(T)); + var doubleArrayValue = (response as MtResponseDoubleArray)?.Value; + if (doubleArrayValue != null) return doubleArrayValue; - if (response is MtResponseLongArray) - return (T)Convert.ChangeType(((MtResponseLongArray)response).Value, typeof(T)); + var intArrayValue = (response as MtResponseIntArray)?.Value; + if (intArrayValue != null) return intArrayValue; - if (response is MtResponseArrayList) - return (T)Convert.ChangeType(((MtResponseArrayList)response).Value, typeof(T)); + var longArrayValue = (response as MtResponseLongArray)?.Value; + if (longArrayValue != null) return longArrayValue; - if (response is MtResponseMqlRatesArray) - return (T)Convert.ChangeType(((MtResponseMqlRatesArray)response).Value, typeof(T)); + var arrayListValue = (response as MtResponseArrayList)?.Value; + if (arrayListValue != null) return arrayListValue; - if (response is MtResponseMqlTick) - return (T)Convert.ChangeType(((MtResponseMqlTick)response).Value, typeof(T)); + var mqlRatesArrayValue = (response as MtResponseMqlRatesArray)?.Value; + if (mqlRatesArrayValue != null) return mqlRatesArrayValue; - if (response is MtResponseMqlBookInfoArray) - return (T)Convert.ChangeType(((MtResponseMqlBookInfoArray)response).Value, typeof(T)); + var mqlTickValue = (response as MtResponseMqlTick)?.Value; + if (mqlTickValue != null) return mqlTickValue; - return default(T); + var mqlBookInfoArrayValue = (response as MtResponseMqlBookInfoArray)?.Value; + return mqlBookInfoArrayValue; } private void mClient_QuoteUpdated(MtQuote quote) @@ -1561,7 +1572,9 @@ namespace MtApi5 private void OnConnected() { - _isBacktestingMode = IsTesting(); + // INFO: disabled backtesting mode while solution of window handle in testing mode is not found + //_isBacktestingMode = IsTesting(); + if (_isBacktestingMode) { BacktestingReady(); diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml index 2fc0c85c..5d858056 100755 --- a/TestClients/MtApi5TestClient/MainWindow.xaml +++ b/TestClients/MtApi5TestClient/MainWindow.xaml @@ -316,9 +316,9 @@ - + - +