From a830dc11a6389bc9464c66c8ef8043a5a9c860b4 Mon Sep 17 00:00:00 2001 From: Viacheslav Demydiuk Date: Sun, 16 Jun 2024 13:57:50 +0300 Subject: [PATCH] Refactored MtApi4 (MT4) for working with new architecture --- MetaTraderApi_2022.sln | 67 +- MtApi/Events/MtChartEvent.cs | 2 +- MtApi/Events/MtEventTypes.cs | 3 +- MtApi/Events/OnLockTicksEvent.cs | 2 +- MtApi/FlagFontStyle.cs | 4 +- MtApi/IMtLogger.cs | 11 + MtApi/Monitors/AvailabilityOrdersEventArgs.cs | 16 +- MtApi/Monitors/MtMonitorBase.cs | 4 +- .../ModifiedOrdersEventArgs.cs | 8 +- .../ModifiedOrdersMonitor.cs | 19 +- .../OrderModification/MtModifiedOrder.cs | 14 +- .../OrderModification/OrderModifiedTypes.cs | 8 +- MtApi/Monitors/TimerTradeMonitor.cs | 3 +- MtApi/Monitors/TradeMonitor.cs | 18 +- MtApi/Monitors/Triggers/IMonitorTrigger.cs | 4 +- MtApi/Monitors/Triggers/NewBarTrigger.cs | 8 +- MtApi/Monitors/Triggers/TimeElapsedTrigger.cs | 11 +- MtApi/MqlRates.cs | 4 +- MtApi/MqlTick.cs | 4 +- MtApi/MtApi.csproj | 181 +- MtApi/MtApiClient.cs | 2205 +++++++++-------- MtApi/MtApiColorConverter.cs | 6 +- MtApi/MtApiTimeConverter.cs | 11 +- MtApi/MtCommandType.cs | 23 +- MtApi/MtConnectionEventArgs.cs | 16 +- MtApi/MtConnectionException.cs | 8 +- MtApi/MtConnectionState.cs | 7 +- MtApi/MtExecutionException.cs | 14 +- MtApi/MtLockTicksEventArgs.cs | 4 +- MtApi/MtOrder.cs | 8 +- MtApi/MtProtocol/FuncResult.cs | 8 + MtApi/MtProtocol/ICustomRequest.cs | 13 + MtApi/MtProtocol/MqlTick.cs | 12 + MtApi/MtProtocol/MtRpcQuote.cs | 9 + MtApi/MtProtocol/Response.cs | 10 + MtApi/MtQuote.cs | 15 +- MtApi/MtQuoteEventArgs.cs | 13 +- MtApi/MtQuotesEventArgs.cs | 8 + MtApi/MtSession.cs | 6 +- MtApi/MtTimeBar.cs | 6 +- MtApi/MtTypes.cs | 4 +- MtApi/OrderSelectMode.cs | 7 +- MtApi/OrderSelectSource.cs | 7 +- MtApi/PriceConstantsType.cs | 7 +- MtApi/Properties/AssemblyInfo.cs | 36 - MtApi/Requests/CopyRatesRequest.cs | 43 - MtApi/Requests/GetOrderRequest.cs | 11 - MtApi/Requests/GetOrdersRequest.cs | 9 - MtApi/Requests/ICustomRequest.cs | 25 - MtApi/Requests/OrderCloseByRequest.cs | 12 - MtApi/Requests/OrderCloseRequest.cs | 14 - MtApi/Requests/OrderDeleteRequest.cs | 11 - MtApi/Requests/OrderModifyRequest.cs | 15 - MtApi/Requests/OrderSendRequest.cs | 20 - MtApi/Requests/RequestBase.cs | 7 - MtApi/Requests/RequestType.cs | 20 - MtApi/Requests/SeriesInfoIntegerRequest.cs | 11 - MtApi/Requests/SessionRequest.cs | 14 - MtApi/Requests/SymbolInfoDoubleRequest.cs | 12 - MtApi/Requests/SymbolInfoTickRequest.cs | 9 - MtApi/Responses/CopyRatesResponse.cs | 9 - MtApi/Responses/GetOrderResponse.cs | 7 - MtApi/Responses/GetOrdersResponse.cs | 9 - MtApi/Responses/ICustomResponse.cs | 7 - MtApi/Responses/OrderSendResponse.cs | 7 - MtApi/Responses/ResponseBase.cs | 8 - MtApi/Responses/SeriesInfoIntegerResponse.cs | 7 - MtApi/Responses/SessionResponse.cs | 7 - MtApi/Responses/SymbolInfoDoubleResponse.cs | 7 - MtApi/Responses/SymbolInfoTickResponse.cs | 7 - MtApi/SeriesIdentifier.cs | 7 +- MtApi/TimeBarArgs.cs | 4 +- MtApi/packages.config | 0 MtApiInstaller/CustomActions.wxs | 14 +- MtApiInstaller/MtApiInstaller.wixproj | 42 +- MtApiInstaller/Product.wxs | 94 +- MtApiSetupActions/CustomAction.cs | 61 +- MtApiSetupActions/MtApiSetupActions.csproj | 62 +- MtApiSetupActions/Properties/AssemblyInfo.cs | 35 - MtClient/MtRpcClient.cs | 63 +- MtService/MtService.vcxproj | 15 + TestClients/TestApiClientUI/Form1.cs | 46 +- .../Properties/AssemblyInfo.cs | 36 - .../Properties/Resources.Designer.cs | 63 - .../TestApiClientUI/Properties/Resources.resx | 117 - .../Properties/Settings.Designer.cs | 26 - .../Properties/Settings.settings | 7 - .../TestApiClientUI/TestApiClientUI.csproj | 182 +- TestClients/TestApiClientUI/app.config | 2 +- 89 files changed, 1648 insertions(+), 2390 deletions(-) create mode 100755 MtApi/IMtLogger.cs create mode 100755 MtApi/MtProtocol/FuncResult.cs create mode 100755 MtApi/MtProtocol/ICustomRequest.cs create mode 100755 MtApi/MtProtocol/MqlTick.cs create mode 100755 MtApi/MtProtocol/MtRpcQuote.cs create mode 100755 MtApi/MtProtocol/Response.cs create mode 100755 MtApi/MtQuotesEventArgs.cs delete mode 100644 MtApi/Properties/AssemblyInfo.cs delete mode 100644 MtApi/Requests/CopyRatesRequest.cs delete mode 100755 MtApi/Requests/GetOrderRequest.cs delete mode 100755 MtApi/Requests/GetOrdersRequest.cs delete mode 100755 MtApi/Requests/ICustomRequest.cs delete mode 100755 MtApi/Requests/OrderCloseByRequest.cs delete mode 100755 MtApi/Requests/OrderCloseRequest.cs delete mode 100755 MtApi/Requests/OrderDeleteRequest.cs delete mode 100755 MtApi/Requests/OrderModifyRequest.cs delete mode 100755 MtApi/Requests/OrderSendRequest.cs delete mode 100644 MtApi/Requests/RequestBase.cs delete mode 100644 MtApi/Requests/RequestType.cs delete mode 100755 MtApi/Requests/SeriesInfoIntegerRequest.cs delete mode 100644 MtApi/Requests/SessionRequest.cs delete mode 100755 MtApi/Requests/SymbolInfoDoubleRequest.cs delete mode 100755 MtApi/Requests/SymbolInfoTickRequest.cs delete mode 100644 MtApi/Responses/CopyRatesResponse.cs delete mode 100755 MtApi/Responses/GetOrderResponse.cs delete mode 100755 MtApi/Responses/GetOrdersResponse.cs delete mode 100755 MtApi/Responses/ICustomResponse.cs delete mode 100755 MtApi/Responses/OrderSendResponse.cs delete mode 100755 MtApi/Responses/ResponseBase.cs delete mode 100755 MtApi/Responses/SeriesInfoIntegerResponse.cs delete mode 100644 MtApi/Responses/SessionResponse.cs delete mode 100755 MtApi/Responses/SymbolInfoDoubleResponse.cs delete mode 100755 MtApi/Responses/SymbolInfoTickResponse.cs mode change 100644 => 100755 MtApi/packages.config delete mode 100644 MtApiSetupActions/Properties/AssemblyInfo.cs delete mode 100644 TestClients/TestApiClientUI/Properties/AssemblyInfo.cs delete mode 100644 TestClients/TestApiClientUI/Properties/Resources.Designer.cs delete mode 100644 TestClients/TestApiClientUI/Properties/Resources.resx delete mode 100644 TestClients/TestApiClientUI/Properties/Settings.Designer.cs delete mode 100644 TestClients/TestApiClientUI/Properties/Settings.settings diff --git a/MetaTraderApi_2022.sln b/MetaTraderApi_2022.sln index 7302ad35..21bc6ea8 100755 --- a/MetaTraderApi_2022.sln +++ b/MetaTraderApi_2022.sln @@ -15,12 +15,24 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestClients", "TestClients" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MtApi5TestClient", "TestClients\MtApi5TestClient\MtApi5TestClient.csproj", "{38B9C657-BC2F-44F0-8824-54B31F2A64F5}" EndProject -Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "MtApi5Installer", "MtApi5Installer\MtApi5Installer.wixproj", "{A9ED070F-AB4D-4380-9DDE-5D931AC71333}" +Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "MtApi5Installer", "MtApi5Installer\MtApi5Installer.wixproj", "{A9ED070F-AB4D-4380-9DDE-5D931AC71333}" ProjectSection(ProjectDependencies) = postProject {AC8B5010-DA75-477E-9CA5-547C649E12D8} = {AC8B5010-DA75-477E-9CA5-547C649E12D8} {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556} = {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MTConnector", "MTConnector\MTConnector.vcxproj", "{2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MtApi", "MtApi\MtApi.csproj", "{7A76C388-A8FB-4949-8170-24D4742E934E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApiClientUI", "TestClients\TestApiClientUI\TestApiClientUI.csproj", "{663CC515-EAAE-47D4-8933-5008C2DA1160}" +EndProject +Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "MtApiInstaller", "MtApiInstaller\MtApiInstaller.wixproj", "{78B94552-DB17-40EC-B7C6-23D32DB85DC1}" + ProjectSection(ProjectDependencies) = postProject + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F} = {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F} + {7A76C388-A8FB-4949-8170-24D4742E934E} = {7A76C388-A8FB-4949-8170-24D4742E934E} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -60,55 +72,84 @@ Global {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Debug|x64.ActiveCfg = Debug|x64 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Debug|x64.Build.0 = Debug|x64 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Debug|x86.ActiveCfg = Debug|Win32 - {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Debug|x86.Build.0 = Debug|Win32 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|Any CPU.ActiveCfg = Release|x64 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|Any CPU.Build.0 = Release|x64 {CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x64.ActiveCfg = Release|x64 {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 {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|x64.ActiveCfg = Debug|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|x64.Build.0 = Debug|Any CPU - {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|x86.ActiveCfg = Debug|x86 - {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|x86.Build.0 = Debug|x86 + {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Debug|x86.ActiveCfg = Debug|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|Any CPU.Build.0 = Release|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|x64.ActiveCfg = Release|Any CPU {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|x64.Build.0 = Release|Any CPU - {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|x86.ActiveCfg = Release|x86 - {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|x86.Build.0 = Release|x86 + {38B9C657-BC2F-44F0-8824-54B31F2A64F5}.Release|x86.ActiveCfg = Release|Any CPU {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Debug|Any CPU.ActiveCfg = Debug|x64 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Debug|Any CPU.Build.0 = Debug|x64 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Debug|x64.ActiveCfg = Debug|x64 - {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Debug|x64.Build.0 = Debug|x64 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Debug|x86.ActiveCfg = Debug|x86 - {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Debug|x86.Build.0 = Debug|x86 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Release|Any CPU.ActiveCfg = Release|x64 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Release|Any CPU.Build.0 = Release|x64 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Release|x64.ActiveCfg = Release|x64 - {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Release|x64.Build.0 = Release|x64 {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Release|x86.ActiveCfg = Release|x86 - {A9ED070F-AB4D-4380-9DDE-5D931AC71333}.Release|x86.Build.0 = Release|x86 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Debug|Any CPU.ActiveCfg = Debug|x64 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Debug|Any CPU.Build.0 = Debug|x64 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Debug|x64.ActiveCfg = Debug|x64 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Debug|x86.ActiveCfg = Debug|Win32 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Debug|x86.Build.0 = Debug|Win32 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Release|Any CPU.ActiveCfg = Release|x64 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Release|Any CPU.Build.0 = Release|x64 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Release|x64.ActiveCfg = Release|x64 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Release|x86.ActiveCfg = Release|Win32 + {2BE5FAC1-7FB7-45C3-9215-31A5BC4B964F}.Release|x86.Build.0 = Release|Win32 + {7A76C388-A8FB-4949-8170-24D4742E934E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Debug|x64.ActiveCfg = Debug|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Debug|x86.ActiveCfg = Debug|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Debug|x86.Build.0 = Debug|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Release|Any CPU.Build.0 = Release|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Release|x64.ActiveCfg = Release|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Release|x86.ActiveCfg = Release|Any CPU + {7A76C388-A8FB-4949-8170-24D4742E934E}.Release|x86.Build.0 = Release|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Debug|Any CPU.Build.0 = Debug|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Debug|x64.ActiveCfg = Debug|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Debug|x86.ActiveCfg = Debug|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Release|Any CPU.ActiveCfg = Release|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Release|Any CPU.Build.0 = Release|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Release|x64.ActiveCfg = Release|Any CPU + {663CC515-EAAE-47D4-8933-5008C2DA1160}.Release|x86.ActiveCfg = Release|Any CPU + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Debug|Any CPU.ActiveCfg = Debug|x64 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Debug|Any CPU.Build.0 = Debug|x64 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Debug|x64.ActiveCfg = Debug|x64 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Debug|x86.ActiveCfg = Debug|x86 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Debug|x86.Build.0 = Debug|x86 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Release|Any CPU.ActiveCfg = Release|x64 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Release|Any CPU.Build.0 = Release|x64 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Release|x64.ActiveCfg = Release|x64 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Release|x86.ActiveCfg = Release|x86 + {78B94552-DB17-40EC-B7C6-23D32DB85DC1}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {38B9C657-BC2F-44F0-8824-54B31F2A64F5} = {0C166554-D20F-4996-AA33-436997058FA1} + {663CC515-EAAE-47D4-8933-5008C2DA1160} = {0C166554-D20F-4996-AA33-436997058FA1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7F3C954E-FEF0-4161-B557-9F8D62D7A39F} diff --git a/MtApi/Events/MtChartEvent.cs b/MtApi/Events/MtChartEvent.cs index 9e765ace..ddbed5f1 100644 --- a/MtApi/Events/MtChartEvent.cs +++ b/MtApi/Events/MtChartEvent.cs @@ -6,6 +6,6 @@ public int EventId { get; set; } public long Lparam { get; set; } public double Dparam { get; set; } - public string Sparam { get; set; } + public string Sparam { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/MtApi/Events/MtEventTypes.cs b/MtApi/Events/MtEventTypes.cs index 413d4cc3..b212faa1 100644 --- a/MtApi/Events/MtEventTypes.cs +++ b/MtApi/Events/MtEventTypes.cs @@ -4,6 +4,7 @@ { LastTimeBar = 1, ChartEvent = 2, - OnLockTicks = 3 + OnLockTicks = 3, + OnTick = 4 } } diff --git a/MtApi/Events/OnLockTicksEvent.cs b/MtApi/Events/OnLockTicksEvent.cs index 92f37f37..9e72e886 100644 --- a/MtApi/Events/OnLockTicksEvent.cs +++ b/MtApi/Events/OnLockTicksEvent.cs @@ -2,6 +2,6 @@ { internal class OnLockTicksEvent { - public string Instrument { get; set; } + public string Instrument { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/MtApi/FlagFontStyle.cs b/MtApi/FlagFontStyle.cs index 13f857b1..8aaf63d8 100644 --- a/MtApi/FlagFontStyle.cs +++ b/MtApi/FlagFontStyle.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi +namespace MtApi { [Flags] public enum FlagFontStyle diff --git a/MtApi/IMtLogger.cs b/MtApi/IMtLogger.cs new file mode 100755 index 00000000..0bc2ad8c --- /dev/null +++ b/MtApi/IMtLogger.cs @@ -0,0 +1,11 @@ +namespace MtApi +{ + public interface IMtLogger + { + void Debug(object message); + void Error(object message); + void Fatal(object message); + void Info(object message); + void Warn(object message); + } +} diff --git a/MtApi/Monitors/AvailabilityOrdersEventArgs.cs b/MtApi/Monitors/AvailabilityOrdersEventArgs.cs index 3f569321..c085eb2d 100644 --- a/MtApi/Monitors/AvailabilityOrdersEventArgs.cs +++ b/MtApi/Monitors/AvailabilityOrdersEventArgs.cs @@ -1,22 +1,14 @@ -using System; -using System.Collections.Generic; - -namespace MtApi.Monitors +namespace MtApi.Monitors { - public class AvailabilityOrdersEventArgs : EventArgs + public class AvailabilityOrdersEventArgs(List opened, List closed) : EventArgs { - public AvailabilityOrdersEventArgs(List opened, List closed) - { - Opened = opened; - Closed = closed; - } /// /// Contains all newly opened orders since the last time the monitor checked the open orders. /// - public List Opened { get; private set; } + public List Opened { get; private set; } = opened; /// /// Contains all newly closed orders since the last time the monitor checked the open orders. /// - public List Closed { get; private set; } + public List Closed { get; private set; } = closed; } } diff --git a/MtApi/Monitors/MtMonitorBase.cs b/MtApi/Monitors/MtMonitorBase.cs index 8f5c0407..d878beca 100644 --- a/MtApi/Monitors/MtMonitorBase.cs +++ b/MtApi/Monitors/MtMonitorBase.cs @@ -80,8 +80,8 @@ namespace MtApi.Monitors MonitorTrigger.Stop(); } } - private void MonitorTriggerRaised(object sender, EventArgs e) => OnTriggerRaised(); - private void ApiClientConnectionStateChanged(object sender, MtConnectionEventArgs e) + private void MonitorTriggerRaised(object? sender, EventArgs e) => OnTriggerRaised(); + private void ApiClientConnectionStateChanged(object? sender, MtConnectionEventArgs e) { if (e.Status == MtConnectionState.Connected) OnMtConnected(); diff --git a/MtApi/Monitors/OrderModification/ModifiedOrdersEventArgs.cs b/MtApi/Monitors/OrderModification/ModifiedOrdersEventArgs.cs index d803ea8d..cf38f325 100644 --- a/MtApi/Monitors/OrderModification/ModifiedOrdersEventArgs.cs +++ b/MtApi/Monitors/OrderModification/ModifiedOrdersEventArgs.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MtApi.Monitors +namespace MtApi.Monitors { public class ModifiedOrdersEventArgs : EventArgs { diff --git a/MtApi/Monitors/OrderModification/ModifiedOrdersMonitor.cs b/MtApi/Monitors/OrderModification/ModifiedOrdersMonitor.cs index 5a4618f6..ed148b20 100644 --- a/MtApi/Monitors/OrderModification/ModifiedOrdersMonitor.cs +++ b/MtApi/Monitors/OrderModification/ModifiedOrdersMonitor.cs @@ -1,16 +1,11 @@ using MtApi.Monitors.Triggers; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MtApi.Monitors { public class ModifiedOrdersMonitor : MtMonitorBase { #region Fields - private List _lastOrders = null; + private List? _lastOrders; #endregion @@ -25,7 +20,7 @@ namespace MtApi.Monitors /// /// Will be raised when this monitor detects changes on open orders /// - public event EventHandler OrdersModified; + public event EventHandler? OrdersModified; #endregion #region ctor @@ -41,7 +36,7 @@ namespace MtApi.Monitors /// Requests all current open orders /// /// - private List GetOrders() => IsMtConnected ? ApiClient.GetOrders(OrderSelectSource.MODE_TRADES) : null; + private List? GetOrders() => IsMtConnected ? ApiClient.GetOrders(OrderSelectSource.MODE_TRADES) : null; protected override void OnTriggerRaised() { if(_lastOrders == null) @@ -49,19 +44,23 @@ namespace MtApi.Monitors _lastOrders = GetOrders(); return; } - List currentOrders = GetOrders(); + + var currentOrders = GetOrders() ?? ([]); OrderModifiedTypes omt = OrderModifiedTypes; var mtModifiedOrders = currentOrders .Select(co => new MtModifiedOrder(_lastOrders.FirstOrDefault(x => x.Ticket == co.Ticket), co)) .ToList(); - List modifiedOrders = new List(); + + List modifiedOrders = new(); modifiedOrders.AddRange(GetMtModifiedOrdersWithModType(mtModifiedOrders, omt, OrderModifiedTypes.TakeProfit)); //If the takeprofit were changed between both calls modifiedOrders.AddRange(GetMtModifiedOrdersWithModType(mtModifiedOrders, omt, OrderModifiedTypes.StopLoss)); //If the stoploss were changed between both calls modifiedOrders.AddRange(GetMtModifiedOrdersWithModType(mtModifiedOrders, omt, OrderModifiedTypes.Operation)); //If an order changed from limit / stop order to an open order + if (modifiedOrders.Count > 0) OrdersModified?.Invoke(this, new ModifiedOrdersEventArgs(modifiedOrders)); _lastOrders = currentOrders; } + private static IEnumerable GetMtModifiedOrdersWithModType(IEnumerable orders, OrderModifiedTypes globalSearchFlag, OrderModifiedTypes modifiedType) => globalSearchFlag.HasFlag(modifiedType) ? orders.Where(o => o.ModifyType.HasFlag(modifiedType)) : new List(); } diff --git a/MtApi/Monitors/OrderModification/MtModifiedOrder.cs b/MtApi/Monitors/OrderModification/MtModifiedOrder.cs index 7bb82d0c..deae8fc1 100644 --- a/MtApi/Monitors/OrderModification/MtModifiedOrder.cs +++ b/MtApi/Monitors/OrderModification/MtModifiedOrder.cs @@ -1,21 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MtApi.Monitors +namespace MtApi.Monitors { public class MtModifiedOrder { /// /// The order in its old state (before the changes) /// - public MtOrder OldOrder { get; } + public MtOrder? OldOrder { get; } /// /// The order in its new state (after the changes) /// - public MtOrder NewOrder { get; } + public MtOrder? NewOrder { get; } /// /// The changes found by this instance /// @@ -25,7 +19,7 @@ namespace MtApi.Monitors /// /// The order in its old state (before the changes) /// The order in its new state (after the changes) - public MtModifiedOrder(MtOrder oldOrder, MtOrder newOrder) + public MtModifiedOrder(MtOrder? oldOrder, MtOrder ?newOrder) { if (oldOrder != null && newOrder != null && oldOrder.Ticket != newOrder.Ticket) throw new ArgumentException(nameof(oldOrder) + " and " + nameof(newOrder) + " need to have the same ticket id"); diff --git a/MtApi/Monitors/OrderModification/OrderModifiedTypes.cs b/MtApi/Monitors/OrderModification/OrderModifiedTypes.cs index 74c351b8..ad353a23 100644 --- a/MtApi/Monitors/OrderModification/OrderModifiedTypes.cs +++ b/MtApi/Monitors/OrderModification/OrderModifiedTypes.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MtApi.Monitors +namespace MtApi.Monitors { [Flags] public enum OrderModifiedTypes diff --git a/MtApi/Monitors/TimerTradeMonitor.cs b/MtApi/Monitors/TimerTradeMonitor.cs index 769ada89..4f1b9f87 100644 --- a/MtApi/Monitors/TimerTradeMonitor.cs +++ b/MtApi/Monitors/TimerTradeMonitor.cs @@ -1,5 +1,4 @@ -using System; -using MtApi.Monitors.Triggers; +using MtApi.Monitors.Triggers; namespace MtApi.Monitors { diff --git a/MtApi/Monitors/TradeMonitor.cs b/MtApi/Monitors/TradeMonitor.cs index 668f1fd9..a2a855fe 100644 --- a/MtApi/Monitors/TradeMonitor.cs +++ b/MtApi/Monitors/TradeMonitor.cs @@ -1,23 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MtApi.Monitors.Triggers; +using MtApi.Monitors.Triggers; namespace MtApi.Monitors { public class TradeMonitor : MtMonitorBase { #region Fields - private List _prevOrders; - private readonly object _locker = new object(); + private List? _prevOrders; + private readonly object _locker = new(); #endregion #region Events // // Summary: // Occurs when orders are opened or closed. - public event EventHandler AvailabilityOrdersChanged; + public event EventHandler? AvailabilityOrdersChanged; #endregion #region ctor @@ -73,10 +69,10 @@ namespace MtApi.Monitors { var openedOrders = new List(); var closedOrders = new List(); - List prevOrders; + List? prevOrders; // get current orders from MetaTrader - var tradesOrders = ApiClient.GetOrders(OrderSelectSource.MODE_TRADES); + var tradesOrders = ApiClient.GetOrders(OrderSelectSource.MODE_TRADES) ?? []; lock (_locker) prevOrders = _prevOrders; @@ -92,7 +88,7 @@ namespace MtApi.Monitors if (closeOrdersTemp.Count > 0) { //get closed orders from history with actual values - var historyOrders = ApiClient.GetOrders(OrderSelectSource.MODE_HISTORY); + var historyOrders = ApiClient.GetOrders(OrderSelectSource.MODE_HISTORY) ?? []; closedOrders = closeOrdersTemp.Where(cot => historyOrders.Find(a => a.Ticket == cot.Ticket) != null).ToList(); } } diff --git a/MtApi/Monitors/Triggers/IMonitorTrigger.cs b/MtApi/Monitors/Triggers/IMonitorTrigger.cs index 54e268d8..b628fc85 100644 --- a/MtApi/Monitors/Triggers/IMonitorTrigger.cs +++ b/MtApi/Monitors/Triggers/IMonitorTrigger.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi.Monitors.Triggers +namespace MtApi.Monitors.Triggers { /// /// Interface for triggers which can be used to trigger a . diff --git a/MtApi/Monitors/Triggers/NewBarTrigger.cs b/MtApi/Monitors/Triggers/NewBarTrigger.cs index 4c39109b..20447848 100644 --- a/MtApi/Monitors/Triggers/NewBarTrigger.cs +++ b/MtApi/Monitors/Triggers/NewBarTrigger.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi.Monitors.Triggers +namespace MtApi.Monitors.Triggers { /// /// Raises the event if a bar is closed and a new one started. @@ -23,7 +21,7 @@ namespace MtApi.Monitors.Triggers /// /// Event will be called if the trigger raised. /// - public event EventHandler Raised; + public event EventHandler? Raised; #endregion #region ctor @@ -46,7 +44,7 @@ namespace MtApi.Monitors.Triggers #endregion #region Private methods - private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e) + private void _apiClient_OnLastTimeBar(object? sender, TimeBarArgs e) { if (_isStarted) Raised?.Invoke(this, EventArgs.Empty); diff --git a/MtApi/Monitors/Triggers/TimeElapsedTrigger.cs b/MtApi/Monitors/Triggers/TimeElapsedTrigger.cs index 65d0b59d..51782aa8 100644 --- a/MtApi/Monitors/Triggers/TimeElapsedTrigger.cs +++ b/MtApi/Monitors/Triggers/TimeElapsedTrigger.cs @@ -1,12 +1,11 @@ -using System; -using System.Timers; +using System.Timers; namespace MtApi.Monitors.Triggers { public class TimeElapsedTrigger : IMonitorTrigger { #region Fields - readonly Timer _timer; + readonly System.Timers.Timer _timer; #endregion #region Properties @@ -34,7 +33,7 @@ namespace MtApi.Monitors.Triggers /// /// Returns true if the trigger is started, otherwise false /// - public event EventHandler Raised; + public event EventHandler? Raised; #endregion #region ctor @@ -45,7 +44,7 @@ namespace MtApi.Monitors.Triggers /// If true, the trigger will raise continuosly after elapsed , otherwise the trigger will raise only once after elapsed . public TimeElapsedTrigger(TimeSpan time, bool autoReset = true) { - _timer = new Timer(time.TotalMilliseconds); + _timer = new System.Timers.Timer(time.TotalMilliseconds); _timer.Elapsed += _timer_Elapsed; AutoReset = autoReset; } @@ -63,7 +62,7 @@ namespace MtApi.Monitors.Triggers #endregion #region private methods - private void _timer_Elapsed(object sender, ElapsedEventArgs e) + private void _timer_Elapsed(object? sender, ElapsedEventArgs e) { _timer.Elapsed -= _timer_Elapsed; Raised?.Invoke(this, EventArgs.Empty); diff --git a/MtApi/MqlRates.cs b/MtApi/MqlRates.cs index 36fca8c5..2115d5d9 100644 --- a/MtApi/MqlRates.cs +++ b/MtApi/MqlRates.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi +namespace MtApi { public class MqlRates { diff --git a/MtApi/MqlTick.cs b/MtApi/MqlTick.cs index f362cf27..85f08839 100755 --- a/MtApi/MqlTick.cs +++ b/MtApi/MqlTick.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi +namespace MtApi { public class MqlTick { diff --git a/MtApi/MtApi.csproj b/MtApi/MtApi.csproj index c601a6f5..bff65bf1 100755 --- a/MtApi/MtApi.csproj +++ b/MtApi/MtApi.csproj @@ -1,167 +1,16 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {7A76C388-A8FB-4949-8170-24D4742E934E} - Library - Properties - MtApi - MtApi - v4.5 - 512 - - - - - true - full - false - ..\build\products\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - ..\build\products\Release\ - TRACE - prompt - 4 - AnyCPU - false - - - false - - - - - - - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {DE76D5C7-B99C-4467-8408-78173BDD84E0} - MTApiService - - - - - - - - - - - - + + + net8.0 + enable + enable + 2.0.0 + $(SolutionDir)build\products + true + + + + + + + \ No newline at end of file diff --git a/MtApi/MtApiClient.cs b/MtApi/MtApiClient.cs index 627b264c..83d4a714 100755 --- a/MtApi/MtApiClient.cs +++ b/MtApi/MtApiClient.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using MTApiService; -using System.Drawing; +using System.Drawing; using System.Collections; -using System.ServiceModel; -using MtApi.Requests; -using MtApi.Responses; using Newtonsoft.Json; -using System.Threading.Tasks; using MtApi.Events; +using MtApi.MtProtocol; +using MtClient; namespace MtApi { @@ -22,30 +16,34 @@ namespace MtApi //Special constant public const int NULL = 0; public const int EMPTY = -1; - - private const string LogProfileName = "MtApiClient"; #endregion #region Private Fields - private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApiClient)); + private IMtLogger Log { get; } + + private MtRpcClient? _client; + private readonly object _locker = new(); + + private readonly Dictionary> _mtEventHandlers = []; + private HashSet _experts = []; + private Dictionary _quotes = []; + private readonly EventWaitHandle _quotesWaiter = new AutoResetEvent(false); - private MtClient _client; - private readonly object _locker = new object(); private MtConnectionState _connectionState = MtConnectionState.Disconnected; - private volatile bool _isBacktestingMode; private int _executorHandle; #endregion #region ctor - public MtApiClient() + + public MtApiClient(IMtLogger? log = null) { -#if (DEBUG) - const LogLevel logLevel = LogLevel.Debug; -#else - const LogLevel logLevel = LogLevel.Info; -#endif - LogConfigurator.Setup(LogProfileName, logLevel); + _mtEventHandlers[MtEventTypes.ChartEvent] = ReceiveOnChartEvent; + _mtEventHandlers[MtEventTypes.LastTimeBar] = ReceivedOnLastTimeBarEvent; + _mtEventHandlers[MtEventTypes.OnLockTicks] = ReceivedOnLockTicksEvent; + _mtEventHandlers[MtEventTypes.OnTick] = ReceivedOnTickEvent; + + Log = log ?? new StubMtLogger(); } #endregion @@ -67,8 +65,8 @@ namespace MtApi ///Port of host connection (default 8222) public void BeginConnect(int port) { - Log.Info($"BeginConnect: port = {port}"); - Task.Factory.StartNew(() => Connect(port)); + Log.Info($"BeginConnect: localhost, port = {port}"); + Task.Factory.StartNew(() => Connect("localhost", port)); } /// @@ -85,9 +83,11 @@ namespace MtApi /// public List GetQuotes() { - var client = Client; - var quotes = client != null ? client.GetQuotes() : null; - return quotes?.Select(q => new MtQuote(q)).ToList(); + _quotesWaiter.WaitOne(10000); // wait 10 sec for loading all quotes from MetaTrader + lock (_locker) + { + return _quotes.Values.ToList(); + } } #endregion @@ -140,120 +140,114 @@ namespace MtApi [Obsolete("OrderClosePrice is deprecated, please use GetOrder instead.")] public double OrderClosePrice() { - return SendCommand(MtCommandType.OrderClosePrice, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderClosePrice); } [Obsolete("OrderClosePrice is deprecated, please use GetOrder instead.")] public double OrderClosePrice(int ticket) { - var commandParameters = new ArrayList { ticket }; - double retVal = SendCommand(MtCommandType.OrderClosePriceByTicket, commandParameters); - - return retVal; + Dictionary cmdParams = new() { { "Ticket", ticket } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderClosePriceByTicket, cmdParams); } [Obsolete("OrderCloseTime is deprecated, please use GetOrder instead.")] public DateTime OrderCloseTime() { - var commandResponse = SendCommand(MtCommandType.OrderCloseTime, null); + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.OrderCloseTime); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } [Obsolete("OrderComment is deprecated, please use GetOrder instead.")] - public string OrderComment() + public string? OrderComment() { - return SendCommand(MtCommandType.OrderComment, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderComment); } [Obsolete("OrderCommission is deprecated, please use GetOrder instead.")] public double OrderCommission() { - return SendCommand(MtCommandType.OrderCommission, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderCommission); } [Obsolete("OrderExpiration is deprecated, please use GetOrder instead.")] public DateTime OrderExpiration() { - var commandResponse = SendCommand(MtCommandType.OrderExpiration, null); + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.OrderExpiration); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } [Obsolete("OrderLots is deprecated, please use GetOrder instead.")] public double OrderLots() { - return SendCommand(MtCommandType.OrderLots, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderLots); } [Obsolete("OrderMagicNumber is deprecated, please use GetOrder instead.")] public int OrderMagicNumber() { - return SendCommand(MtCommandType.OrderMagicNumber, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderMagicNumber); } [Obsolete("OrderOpenPrice is deprecated, please use GetOrder instead.")] public double OrderOpenPrice() { - return SendCommand(MtCommandType.OrderOpenPrice, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderOpenPrice); } [Obsolete("OrderOpenPrice is deprecated, please use GetOrder instead.")] public double OrderOpenPrice(int ticket) { - var commandParameters = new ArrayList { ticket }; - var retVal = SendCommand(MtCommandType.OrderOpenPriceByTicket, commandParameters); - - return retVal; + Dictionary cmdParams = new() { { "Ticket", ticket } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderOpenPriceByTicket, cmdParams); } [Obsolete("OrderOpenTime is deprecated, please use GetOrder instead.")] public DateTime OrderOpenTime() { - var commandResponse = SendCommand(MtCommandType.OrderOpenTime, null); + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.OrderOpenTime); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } [Obsolete("OrderProfit is deprecated, please use GetOrder instead.")] public double OrderProfit() { - return SendCommand(MtCommandType.OrderProfit, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderProfit); } [Obsolete("OrderStopLoss is deprecated, please use GetOrder instead.")] public double OrderStopLoss() { - return SendCommand(MtCommandType.OrderStopLoss, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderStopLoss); } [Obsolete("OrderSymbol is deprecated, please use GetOrder instead.")] - public string OrderSymbol() + public string? OrderSymbol() { - return SendCommand(MtCommandType.OrderSymbol, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderSymbol); } [Obsolete("OrderTakeProfit is deprecated, please use GetOrder instead.")] public double OrderTakeProfit() { - return SendCommand(MtCommandType.OrderTakeProfit, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderTakeProfit); } [Obsolete("OrderTicket is deprecated, please use GetOrder instead.")] public int OrderTicket() { - return SendCommand(MtCommandType.OrderTicket, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderTicket); } [Obsolete("OrderType is deprecated, please use GetOrder instead.")] public TradeOperation OrderType() { - var retVal = SendCommand(MtCommandType.OrderType, null); - - return (TradeOperation)retVal; + return (TradeOperation) SendCommand(ExecutorHandle, MtCommandType.OrderType); } [Obsolete("OrderSwap is deprecated, please use GetOrder instead.")] public double OrderSwap() { - return SendCommand(MtCommandType.OrderSwap, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderSwap); } #endregion @@ -264,21 +258,12 @@ namespace MtApi { Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}, expiration = {expiration}, arrowColor = {arrowColor}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)cmd, - Volume = volume, - Price = price, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - Comment = comment, - Magic = magic, - Expiration = MtApiTimeConverter.ConvertToMtTime(expiration), - ArrowColor = MtApiColorConverter.ConvertToMtColor(arrowColor) - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", cmd }, + { "Volume", volume }, { "Price", price }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit }, { "Comment", comment }, { "Magic", magic }, + { "Expiration", MtApiTimeConverter.ConvertToMtTime(expiration) }, { "ArrowColor", MtApiColorConverter.ConvertToMtColor(arrowColor) } }; + + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit @@ -286,20 +271,12 @@ namespace MtApi { Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}, expiration = {expiration}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)cmd, - Volume = volume, - Price = price, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - Comment = comment, - Magic = magic, - Expiration = MtApiTimeConverter.ConvertToMtTime(expiration) - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", cmd }, + { "Volume", volume }, { "Price", price }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit }, { "Comment", comment }, { "Magic", magic }, + { "Expiration", MtApiTimeConverter.ConvertToMtTime(expiration) } }; + + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit @@ -307,19 +284,11 @@ namespace MtApi { Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)cmd, - Volume = volume, - Price = price, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - Comment = comment, - Magic = magic - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", cmd }, + { "Volume", volume }, { "Price", price }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit }, { "Comment", comment }, { "Magic", magic } }; + + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit @@ -327,43 +296,29 @@ namespace MtApi { Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)cmd, - Volume = volume, - Price = price, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - Comment = comment - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", cmd }, + { "Volume", volume }, { "Price", price }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit }, { "Comment", comment } }; + + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit) { Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)cmd, - Volume = volume, - Price = price, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", cmd }, + { "Volume", volume }, { "Price", price }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit } }; + + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit) { Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}"); - double dPrice; - return double.TryParse(price, out dPrice) ? + return double.TryParse(price, out double dPrice) ? OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit) : 0; } @@ -389,186 +344,132 @@ namespace MtApi return OrderSendSell(symbol, volume, slippage, stoploss, takeprofit, null, 0); } - public int OrderSendBuy(string symbol, double volume, int slippage, double stoploss, double takeprofit, string comment, int magic) + public int OrderSendBuy(string symbol, double volume, int slippage, double stoploss, double takeprofit, string? comment, int magic) { Log.Debug($"OrderSendBuy: symbol = {symbol}, volume = {volume}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)TradeOperation.OP_BUY, - Volume = volume, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - Comment = comment, - Magic = magic, - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", (int)TradeOperation.OP_BUY }, + { "Volume", volume }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit }, { "Magic", magic } }; + if (string.IsNullOrEmpty(comment) == false) + cmdParams["Comment"] = comment; + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } - public int OrderSendSell(string symbol, double volume, int slippage, double stoploss, double takeprofit, string comment, int magic) + public int OrderSendSell(string symbol, double volume, int slippage, double stoploss, double takeprofit, string? comment, int magic) { Log.Debug($"OrderSendSell: symbol = {symbol}, volume = {volume}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}"); - var response = SendRequest(new OrderSendRequest - { - Symbol = symbol, - Cmd = (int)TradeOperation.OP_SELL, - Volume = volume, - Slippage = slippage, - Stoploss = stoploss, - Takeprofit = takeprofit, - Comment = comment, - Magic = magic, - }); - return response?.Ticket ?? -1; + Dictionary cmdParams = new() { { "Symbol", symbol }, { "Cmd", (int)TradeOperation.OP_SELL }, + { "Volume", volume }, { "Slippage", slippage }, { "Stoploss", stoploss}, + { "Takeprofit", takeprofit }, { "Magic", magic } }; + if (string.IsNullOrEmpty(comment) == false) + cmdParams["Comment"] = comment; + return SendCommand(ExecutorHandle, MtCommandType.OrderSend, cmdParams); } public bool OrderClose(int ticket, double lots, double price, int slippage, Color color) { Log.Debug($"OrderClose: ticket = {ticket}, lots = {lots}, price = {price}, slippage = {slippage}, color = {color}"); - var response = SendRequest(new OrderCloseRequest - { - Ticket = ticket, - Lots = lots, - Price = price, - Slippage = slippage, - ArrowColor = MtApiColorConverter.ConvertToMtColor(color) - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Lots", lots }, + { "Price", price }, { "Slippage", slippage }, { "ArrowColor", color} }; + return SendCommand(ExecutorHandle, MtCommandType.OrderClose, cmdParams); } public bool OrderClose(int ticket, double lots, double price, int slippage) { Log.Debug($"OrderClose: ticket = {ticket}, lots = {lots}, price = {price}, slippage = {slippage}"); - var response = SendRequest(new OrderCloseRequest - { - Ticket = ticket, - Lots = lots, - Price = price, - Slippage = slippage, - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Lots", lots }, + { "Price", price }, { "Slippage", slippage } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderClose, cmdParams); } public bool OrderClose(int ticket, double lots, int slippage) { Log.Debug($"OrderClose: ticket = {ticket}, lots = {lots}, slippage = {slippage}"); - var response = SendRequest(new OrderCloseRequest - { - Ticket = ticket, - Lots = lots, - Slippage = slippage, - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Lots", lots }, + { "Slippage", slippage } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderClose, cmdParams); } public bool OrderClose(int ticket, int slippage) { Log.Debug($"OrderClose: ticket = {ticket}, slippage = {slippage}"); - var response = SendRequest(new OrderCloseRequest - { - Ticket = ticket, - Slippage = slippage, - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Slippage", slippage } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderClose, cmdParams); } public bool OrderCloseBy(int ticket, int opposite, Color color) { Log.Debug($"OrderCloseBy: ticket = {ticket}, opposite = {opposite}, color = {color}"); - var response = SendRequest(new OrderCloseByRequest - { - Ticket = ticket, - Opposite = opposite, - ArrowColor = MtApiColorConverter.ConvertToMtColor(color) - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Opposite", opposite }, + { "ColorValue", MtApiColorConverter.ConvertToMtColor(color) } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderCloseBy, cmdParams); } public bool OrderCloseBy(int ticket, int opposite) { Log.Debug($"OrderCloseBy: ticket = {ticket}, opposite = {opposite}"); - var response = SendRequest(new OrderCloseByRequest - { - Ticket = ticket, - Opposite = opposite, - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, { "Opposite", opposite } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderCloseBy, cmdParams); } public bool OrderDelete(int ticket, Color color) { Log.Debug($"OrderDelete: ticket = {ticket}, color = {color}"); - var response = SendRequest(new OrderDeleteRequest - { - Ticket = ticket, - ArrowColor = MtApiColorConverter.ConvertToMtColor(color), - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, + { "ArrowColor", MtApiColorConverter.ConvertToMtColor(color) } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderDelete, cmdParams); } public bool OrderDelete(int ticket) { Log.Debug($"OrderDelete: ticket = {ticket}"); - var response = SendRequest(new OrderDeleteRequest - { - Ticket = ticket, - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderDelete, cmdParams); } public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrowColor) { Log.Debug($"OrderModify: ticket = {ticket}, price = {price}, stoploss = {stoploss}, takeprofit = {takeprofit}, expiration = {expiration}, arrowColor = {arrowColor}"); - var response = SendRequest(new OrderModifyRequest - { - Ticket = ticket, - Price = price, - Stoploss = stoploss, - Takeprofit = takeprofit, - Expiration = MtApiTimeConverter.ConvertToMtTime(expiration), - ArrowColor = MtApiColorConverter.ConvertToMtColor(arrowColor) - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, + { "Price", price }, { "Stoploss", stoploss}, { "Takeprofit", takeprofit }, + { "Expiration", MtApiTimeConverter.ConvertToMtTime(expiration) }, + { "ArrowColor", MtApiColorConverter.ConvertToMtColor(arrowColor) } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderModify, cmdParams); } public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration) { Log.Debug($"OrderModify: ticket = {ticket}, price = {price}, stoploss = {stoploss}, takeprofit = {takeprofit}, expiration = {expiration}"); - var response = SendRequest(new OrderModifyRequest - { - Ticket = ticket, - Price = price, - Stoploss = stoploss, - Takeprofit = takeprofit, - Expiration = MtApiTimeConverter.ConvertToMtTime(expiration), - }); - return response != null; + Dictionary cmdParams = new() { { "Ticket", ticket }, + { "Price", price }, { "Stoploss", stoploss}, { "Takeprofit", takeprofit }, + { "Expiration", MtApiTimeConverter.ConvertToMtTime(expiration) } }; + return SendCommand(ExecutorHandle, MtCommandType.OrderModify, cmdParams); } public void OrderPrint() { - SendCommand(MtCommandType.OrderPrint, null); + SendCommand(ExecutorHandle, MtCommandType.OrderPrint); } public bool OrderSelect(int index, OrderSelectMode select, OrderSelectSource pool) { Log.Debug($"OrderSelect: index = {index}, select = {select}, pool = {pool}"); - var commandParameters = new ArrayList { index, (int)select, (int)pool }; - return SendCommand(MtCommandType.OrderSelect, commandParameters); + Dictionary cmdParams = new() { { "Index", index }, + { "Select", (int)select }, { "Pool", (int)pool} }; + return SendCommand(ExecutorHandle, MtCommandType.OrderSelect, cmdParams); } public bool OrderSelect(int index, OrderSelectMode select) @@ -578,29 +479,30 @@ namespace MtApi public int OrdersHistoryTotal() { - return SendCommand(MtCommandType.OrdersHistoryTotal, null); + return SendCommand(ExecutorHandle, MtCommandType.OrdersHistoryTotal); } public int OrdersTotal() { - return SendCommand(MtCommandType.OrdersTotal, null); + return SendCommand(ExecutorHandle, MtCommandType.OrdersTotal); } public bool OrderCloseAll() { - return SendCommand(MtCommandType.OrderCloseAll, null); + return SendCommand(ExecutorHandle, MtCommandType.OrderCloseAll); } - public MtOrder GetOrder(int index, OrderSelectMode select, OrderSelectSource pool) + public MtOrder? GetOrder(int index, OrderSelectMode select, OrderSelectSource pool) { - var response = SendRequest(new GetOrderRequest { Index = index, Select = (int) select, Pool = (int) pool}); - return response?.Order; + Dictionary cmdParams = new() { { "Index", index }, + { "Select", (int)select }, { "Pool", (int)pool} }; + return SendCommand(ExecutorHandle, MtCommandType.GetOrder, cmdParams); } - public List GetOrders(OrderSelectSource pool) + public List? GetOrders(OrderSelectSource pool) { - var response = SendRequest(new GetOrdersRequest { Pool = (int)pool }); - return response != null ? response.Orders : new List(); + Dictionary cmdParams = new() { { "Pool", (int)pool} }; + return SendCommand>(ExecutorHandle, MtCommandType.GetOrders, cmdParams); } #endregion @@ -615,7 +517,7 @@ namespace MtApi /// public int GetLastError() { - return SendCommand(MtCommandType.GetLastError, null); + return SendCommand(ExecutorHandle, MtCommandType.GetLastError); } /// @@ -626,7 +528,7 @@ namespace MtApi /// public bool IsConnected() { - return SendCommand(MtCommandType.IsConnected, null); + return SendCommand(ExecutorHandle, MtCommandType.IsConnected); } /// @@ -637,7 +539,7 @@ namespace MtApi /// public bool IsDemo() { - return SendCommand(MtCommandType.IsDemo, null); + return SendCommand(ExecutorHandle, MtCommandType.IsDemo); } /// @@ -648,7 +550,7 @@ namespace MtApi /// public bool IsDllsAllowed() { - return SendCommand(MtCommandType.IsDllsAllowed, null); + return SendCommand(ExecutorHandle, MtCommandType.IsDllsAllowed); } /// @@ -659,7 +561,7 @@ namespace MtApi /// public bool IsExpertEnabled() { - return SendCommand(MtCommandType.IsExpertEnabled, null); + return SendCommand(ExecutorHandle, MtCommandType.IsExpertEnabled); } /// @@ -670,7 +572,7 @@ namespace MtApi /// public bool IsLibrariesAllowed() { - return SendCommand(MtCommandType.IsLibrariesAllowed, null); + return SendCommand(ExecutorHandle, MtCommandType.IsLibrariesAllowed); } /// @@ -681,7 +583,7 @@ namespace MtApi /// public bool IsOptimization() { - return SendCommand(MtCommandType.IsOptimization, null); + return SendCommand(ExecutorHandle, MtCommandType.IsOptimization); } /// @@ -695,7 +597,7 @@ namespace MtApi /// public bool IsStopped() { - return SendCommand(MtCommandType.IsStopped, null); + return SendCommand(ExecutorHandle, MtCommandType.IsStopped); } /// @@ -706,7 +608,7 @@ namespace MtApi /// public bool IsTesting() { - return SendCommand(MtCommandType.IsTesting, null); + return SendCommand(ExecutorHandle, MtCommandType.IsTesting); } /// @@ -717,7 +619,7 @@ namespace MtApi /// public bool IsTradeAllowed() { - return SendCommand(MtCommandType.IsTradeAllowed, null); + return SendCommand(ExecutorHandle, MtCommandType.IsTradeAllowed); } /// @@ -728,7 +630,7 @@ namespace MtApi /// public bool IsTradeContextBusy() { - return SendCommand(MtCommandType.IsTradeContextBusy, null); + return SendCommand(ExecutorHandle, MtCommandType.IsTradeContextBusy); } /// @@ -739,7 +641,7 @@ namespace MtApi /// public bool IsVisualMode() { - return SendCommand(MtCommandType.IsVisualMode, null); + return SendCommand(ExecutorHandle, MtCommandType.IsVisualMode); } /// @@ -751,16 +653,16 @@ namespace MtApi /// public int UninitializeReason() { - return SendCommand(MtCommandType.UninitializeReason, null); + return SendCommand(ExecutorHandle, MtCommandType.UninitializeReason); } /// ///Print the error description. /// - public string ErrorDescription(int errorCode) + public string? ErrorDescription(int errorCode) { - var commandParameters = new ArrayList { errorCode }; - return SendCommand(MtCommandType.ErrorDescription, commandParameters); + Dictionary cmdParams = new() { { "ErrorCode", errorCode } }; + return SendCommand(ExecutorHandle, MtCommandType.ErrorDescription, cmdParams); } /// @@ -770,10 +672,10 @@ namespace MtApi /// ///Value of string type. /// - public string TerminalInfoString(ENUM_TERMINAL_INFO_STRING propertyId) + public string? TerminalInfoString(ENUM_TERMINAL_INFO_STRING propertyId) { - var commandParameters = new ArrayList { (int)propertyId }; - return SendCommand(MtCommandType.TerminalInfoString, commandParameters); + Dictionary cmdParams = new() { { "PropertyId", (int)propertyId } }; + return SendCommand(ExecutorHandle, MtCommandType.TerminalInfoString, cmdParams); } /// @@ -785,8 +687,8 @@ namespace MtApi /// public int TerminalInfoInteger(EnumTerminalInfoInteger propertyId) { - var commandParameters = new ArrayList { (int)propertyId }; - return SendCommand(MtCommandType.TerminalInfoInteger, commandParameters); + Dictionary cmdParams = new() { { "PropertyId", (int)propertyId } }; + return SendCommand(ExecutorHandle, MtCommandType.TerminalInfoInteger, cmdParams); } /// @@ -798,8 +700,8 @@ namespace MtApi /// public double TerminalInfoDouble(EnumTerminalInfoDouble propertyId) { - var commandParameters = new ArrayList { (int)propertyId }; - return SendCommand(MtCommandType.TerminalInfoDouble, commandParameters); + Dictionary cmdParams = new() { { "PropertyId", (int)propertyId } }; + return SendCommand(ExecutorHandle, MtCommandType.TerminalInfoDouble, cmdParams); } /// @@ -808,9 +710,9 @@ namespace MtApi /// ///The name of company owning the client terminal. /// - public string TerminalCompany() + public string? TerminalCompany() { - return SendCommand(MtCommandType.TerminalCompany, null); + return SendCommand(ExecutorHandle, MtCommandType.TerminalCompany); } /// @@ -819,9 +721,9 @@ namespace MtApi /// ///Client terminal name. /// - public string TerminalName() + public string? TerminalName() { - return SendCommand(MtCommandType.TerminalName, null); + return SendCommand(ExecutorHandle, MtCommandType.TerminalName); } /// @@ -830,9 +732,9 @@ namespace MtApi /// ///The directory, from which the client terminal was launched. /// - public string TerminalPath() + public string? TerminalPath() { - return SendCommand(MtCommandType.TerminalPath, null); + return SendCommand(ExecutorHandle, MtCommandType.TerminalPath); } #endregion @@ -841,89 +743,91 @@ namespace MtApi public double AccountBalance() { - return SendCommand(MtCommandType.AccountBalance, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountBalance); } public double AccountCredit() { - return SendCommand(MtCommandType.AccountCredit, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountCredit); } - public string AccountCompany() + public string? AccountCompany() { - return SendCommand(MtCommandType.AccountCompany, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountCompany); } - public string AccountCurrency() + public string? AccountCurrency() { - return SendCommand(MtCommandType.AccountCurrency, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountCurrency); } public double AccountEquity() { - return SendCommand(MtCommandType.AccountEquity, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountEquity); } public double AccountFreeMargin() { - return SendCommand(MtCommandType.AccountFreeMargin, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountFreeMargin); } public double AccountFreeMarginCheck(string symbol, TradeOperation cmd, double volume) { - var commandParameters = new ArrayList { symbol, (int)cmd, volume }; - return SendCommand(MtCommandType.AccountFreeMarginCheck, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Cmd", cmd }, { "Volume", volume } }; + return SendCommand(ExecutorHandle, MtCommandType.AccountFreeMarginCheck, cmdParams); } public double AccountFreeMarginMode() { - return SendCommand(MtCommandType.AccountFreeMarginMode, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountFreeMarginMode); } public int AccountLeverage() { - return SendCommand(MtCommandType.AccountLeverage, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountLeverage); } public double AccountMargin() { - return SendCommand(MtCommandType.AccountMargin, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountMargin); } - public string AccountName() + public string? AccountName() { - return SendCommand(MtCommandType.AccountName, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountName); } public int AccountNumber() { - return SendCommand(MtCommandType.AccountNumber, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountNumber); } public double AccountProfit() { - return SendCommand(MtCommandType.AccountProfit, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountProfit); } - public string AccountServer() + public string? AccountServer() { - return SendCommand(MtCommandType.AccountServer, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountServer); } public int AccountStopoutLevel() { - return SendCommand(MtCommandType.AccountStopoutLevel, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountStopoutLevel); } public int AccountStopoutMode() { - return SendCommand(MtCommandType.AccountStopoutMode, null); + return SendCommand(ExecutorHandle, MtCommandType.AccountStopoutMode); } public bool ChangeAccount(string login, string password, string host) { - var commandParameters = new ArrayList { login, password, host}; - return SendCommand(MtCommandType.ChangeAccount, commandParameters); + Dictionary cmdParams = new() { { "Login", login }, + { "Password", password }, { "Host", host } }; + return SendCommand(ExecutorHandle, MtCommandType.ChangeAccount, cmdParams); } #endregion @@ -932,25 +836,26 @@ namespace MtApi public void Alert(string msg) { - var commandParameters = new ArrayList { msg }; - SendCommand(MtCommandType.Alert, commandParameters); + Dictionary cmdParams = new() { { "Msg", msg } }; + SendCommand(ExecutorHandle, MtCommandType.Alert, cmdParams); } public void Comment(string msg) { - var commandParameters = new ArrayList { msg }; - SendCommand(MtCommandType.Comment, commandParameters); + Dictionary cmdParams = new() { { "Msg", msg } }; + SendCommand(ExecutorHandle, MtCommandType.Comment, cmdParams); } public int GetTickCount() { - return SendCommand(MtCommandType.GetTickCount, null); + return SendCommand(ExecutorHandle, MtCommandType.GetTickCount); } public int MessageBox(string text, string caption, int flag) { - var commandParameters = new ArrayList { text, caption, flag }; - return SendCommand(MtCommandType.MessageBoxA, commandParameters); + Dictionary cmdParams = new() { { "Text", text }, + { "Caption", caption }, { "Flag", flag } }; + return SendCommand(ExecutorHandle, MtCommandType.MessageBoxA, cmdParams); } public int MessageBox(string text, string caption) @@ -960,44 +865,46 @@ namespace MtApi public int MessageBox(string text) { - var commandParameters = new ArrayList { text }; - return SendCommand(MtCommandType.MessageBox, commandParameters); + Dictionary cmdParams = new() { { "Text", text } }; + return SendCommand(ExecutorHandle, MtCommandType.MessageBox, cmdParams); } public bool PlaySound(string filename) { - var commandParameters = new ArrayList { filename }; - return SendCommand(MtCommandType.PlaySound, commandParameters); + Dictionary cmdParams = new() { { "Filename", filename } }; + return SendCommand(ExecutorHandle, MtCommandType.PlaySound, cmdParams); } public void Print(string msg) { - var commandParameters = new ArrayList { msg }; - SendCommand(MtCommandType.Print, commandParameters); + Dictionary cmdParams = new() { { "Msg", msg } }; + SendCommand(ExecutorHandle, MtCommandType.Print, cmdParams); } public bool SendFTP(string filename) { - var commandParameters = new ArrayList { filename }; - return SendCommand(MtCommandType.SendFTP, commandParameters); + Dictionary cmdParams = new() { { "Filename", filename } }; + return SendCommand(ExecutorHandle, MtCommandType.SendFTP, cmdParams); } public bool SendFTP(string filename, string ftpPath) { - var commandParameters = new ArrayList { filename, ftpPath }; - return SendCommand(MtCommandType.SendFTPA, commandParameters); + Dictionary cmdParams = new() { { "Filename", filename }, + { "FtpPath", ftpPath } }; + return SendCommand(ExecutorHandle, MtCommandType.SendFTPA, cmdParams); } public bool SendMail(string subject, string someText) { - var commandParameters = new ArrayList { subject, someText }; - return SendCommand(MtCommandType.SendMail, commandParameters); + Dictionary cmdParams = new() { { "Subject", subject }, + { "SomeText", someText } }; + return SendCommand(ExecutorHandle, MtCommandType.SendMail, cmdParams); } public void Sleep(int milliseconds) { - var commandParameters = new ArrayList { milliseconds }; - SendCommand(MtCommandType.Sleep, commandParameters); + Dictionary cmdParams = new() { { "Milliseconds", milliseconds } }; + SendCommand(ExecutorHandle, MtCommandType.Sleep, cmdParams); } #endregion @@ -1006,109 +913,109 @@ namespace MtApi public int Day() { - return SendCommand(MtCommandType.Day, null); + return SendCommand(ExecutorHandle, MtCommandType.Day); } public int DayOfWeek() { - return SendCommand(MtCommandType.DayOfWeek, null); + return SendCommand(ExecutorHandle, MtCommandType.DayOfWeek); } public int DayOfYear() { - return SendCommand(MtCommandType.DayOfYear, null); + return SendCommand(ExecutorHandle, MtCommandType.DayOfYear); } public int Hour() { - return SendCommand(MtCommandType.Hour, null); + return SendCommand(ExecutorHandle, MtCommandType.Hour); } public int Minute() { - return SendCommand(MtCommandType.Minute, null); + return SendCommand(ExecutorHandle, MtCommandType.Minute); } public int Month() { - return SendCommand(MtCommandType.Month, null); + return SendCommand(ExecutorHandle, MtCommandType.Month); } public int Seconds() { - return SendCommand(MtCommandType.Seconds, null); + return SendCommand(ExecutorHandle, MtCommandType.Seconds); } public DateTime TimeCurrent() { - var commandResponse = SendCommand(MtCommandType.TimeCurrent, null); + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.TimeCurrent); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } public DateTime TimeGMT() { - var commandResponse = SendCommand(MtCommandType.TimeGMT, null); + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.TimeGMT); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } public int TimeDay(DateTime date) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) }; - return SendCommand(MtCommandType.TimeDay, commandParameters); + Dictionary cmdParams = new() { { "Date", MtApiTimeConverter.ConvertToMtTime(date) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeDay, cmdParams); } public int TimeDayOfWeek(DateTime date) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) }; - return SendCommand(MtCommandType.TimeDayOfWeek, commandParameters); + Dictionary cmdParams = new() { { "Date", MtApiTimeConverter.ConvertToMtTime(date) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeDayOfWeek, cmdParams); } public int TimeDayOfYear(DateTime date) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) }; - return SendCommand(MtCommandType.TimeDayOfYear, commandParameters); + Dictionary cmdParams = new() { { "Date", MtApiTimeConverter.ConvertToMtTime(date) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeDayOfYear, cmdParams); } public int TimeHour(DateTime time) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(time) }; - return SendCommand(MtCommandType.TimeHour, commandParameters); + Dictionary cmdParams = new() { { "TIme", MtApiTimeConverter.ConvertToMtTime(time) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeHour, cmdParams); } public DateTime TimeLocal() { - var commandResponse = SendCommand(MtCommandType.TimeLocal, null); + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.TimeLocal); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } public int TimeMinute(DateTime time) - { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(time) }; - return SendCommand(MtCommandType.TimeMinute, commandParameters); + {; + Dictionary cmdParams = new() { { "TIme", MtApiTimeConverter.ConvertToMtTime(time) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeMinute, cmdParams); } public int TimeMonth(DateTime time) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(time) }; - return SendCommand(MtCommandType.TimeMonth, commandParameters); + Dictionary cmdParams = new() { { "TIme", MtApiTimeConverter.ConvertToMtTime(time) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeMonth, cmdParams); } public int TimeSeconds(DateTime time) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(time) }; - return SendCommand(MtCommandType.TimeSeconds, commandParameters); + Dictionary cmdParams = new() { { "TIme", MtApiTimeConverter.ConvertToMtTime(time) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeSeconds, cmdParams); } public int TimeYear(DateTime time) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(time) }; - return SendCommand(MtCommandType.TimeYear, commandParameters); + Dictionary cmdParams = new() { { "TIme", MtApiTimeConverter.ConvertToMtTime(time) } }; + return SendCommand(ExecutorHandle, MtCommandType.TimeYear, cmdParams); } public int Year(DateTime time) { - var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(time) }; - return SendCommand(MtCommandType.Year, commandParameters); + Dictionary cmdParams = new() { { "TIme", MtApiTimeConverter.ConvertToMtTime(time) } }; + return SendCommand(ExecutorHandle, MtCommandType.Year, cmdParams); } #endregion @@ -1116,50 +1023,51 @@ namespace MtApi #region Global Variables Functions public bool GlobalVariableCheck(string name) { - var commandParameters = new ArrayList { name }; - return SendCommand(MtCommandType.GlobalVariableCheck, commandParameters); + Dictionary cmdParams = new() { { "Name", name } }; + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariableCheck, cmdParams); } public bool GlobalVariableDel(string name) { - var commandParameters = new ArrayList { name }; - return SendCommand(MtCommandType.GlobalVariableDel, commandParameters); + Dictionary cmdParams = new() { { "Name", name } }; + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariableDel, cmdParams); } public double GlobalVariableGet(string name) { - var commandParameters = new ArrayList { name }; - return SendCommand(MtCommandType.GlobalVariableGet, commandParameters); + Dictionary cmdParams = new() { { "Name", name } }; + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariableGet, cmdParams); } - public string GlobalVariableName(int index) + public string? GlobalVariableName(int index) { - var commandParameters = new ArrayList { index }; - return SendCommand(MtCommandType.GlobalVariableName, commandParameters); + Dictionary cmdParams = new() { { "Index", index } }; + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariableName, cmdParams); } public DateTime GlobalVariableSet(string name, double value) { - var commandParameters = new ArrayList { name, value }; - var commandResponse = SendCommand(MtCommandType.GlobalVariableSet, commandParameters); + Dictionary cmdParams = new() { { "Name", name }, { "Value", value } }; + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.GlobalVariableSet, cmdParams); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } public bool GlobalVariableSetOnCondition(string name, double value, double checkValue) { - var commandParameters = new ArrayList { name, value, checkValue }; - return SendCommand(MtCommandType.GlobalVariableSetOnCondition, commandParameters); + Dictionary cmdParams = new() { { "Name", name }, { "Value", value }, + { "CheckValue", checkValue } }; + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariableSetOnCondition, cmdParams); } public int GlobalVariablesDeleteAll(string prefixName) { - var commandParameters = new ArrayList { prefixName }; - return SendCommand(MtCommandType.GlobalVariableSetOnCondition, commandParameters); + Dictionary cmdParams = new() { { "PrefixName", prefixName } }; + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariableSetOnCondition, cmdParams); } public int GlobalVariablesTotal() { - return SendCommand(MtCommandType.GlobalVariablesTotal, null); + return SendCommand(ExecutorHandle, MtCommandType.GlobalVariablesTotal, null); } #endregion @@ -1167,497 +1075,545 @@ namespace MtApi #region Technical Indicators public double iAC(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - return SendCommand(MtCommandType.iAC, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iAC, cmdParams); } public double iAD(string symbol, int timeframe, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, shift }; - return SendCommand(MtCommandType.iAD, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iAD, cmdParams); } public double iAlligator(string symbol, int timeframe, int jawPeriod, int jawShift, int teethPeriod, int teethShift, int lipsPeriod, int lipsShift, int maMethod, int appliedPrice, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, jawPeriod, jawShift, teethPeriod, teethShift, lipsPeriod, lipsShift, maMethod, appliedPrice, mode, shift }; - return SendCommand(MtCommandType.iAlligator, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "JawPeriod", jawPeriod }, + { "JawShift", jawShift }, { "TeethPeriod", teethPeriod }, + { "TeethShift", teethShift }, { "LipsPeriod", lipsPeriod }, + { "LipsShift", lipsShift }, { "MaMethod", maMethod }, + { "AppliedPrice", appliedPrice }, { "Mode", mode }, + { "Shift", shift } }; + + return SendCommand(ExecutorHandle, MtCommandType.iAlligator, cmdParams); } public double iADX(string symbol, int timeframe, int period, int appliedPrice, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, mode, shift }; - return SendCommand(MtCommandType.iADX, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "AppliedPrice", appliedPrice }, { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iADX, cmdParams); } public double iATR(string symbol, int timeframe, int period, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, shift }; - return SendCommand(MtCommandType.iATR, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iATR, cmdParams); } public double iAO(string symbol, int timeframe, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, shift }; - return SendCommand(MtCommandType.iAO, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iAO, cmdParams); } public double iBearsPower(string symbol, int timeframe, int period, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift }; - return SendCommand(MtCommandType.iBearsPower, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iBearsPower, cmdParams); } public double iBands(string symbol, int timeframe, int period, int deviation, int bandsShift, int appliedPrice, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, deviation, bandsShift, appliedPrice, mode, shift }; - return SendCommand(MtCommandType.iBands, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "Deviation", deviation }, { "BandsShift", bandsShift }, + { "AppliedPrice", appliedPrice }, { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iBands, cmdParams); } public double iBandsOnArray(double[] array, int total, int period, int deviation, int bandsShift, int mode, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] {}); - commandParameters.Add(total); - commandParameters.Add(period); - commandParameters.Add(deviation); - commandParameters.Add(bandsShift); - commandParameters.Add(mode); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iBandsOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "Period", period }, { "Deviation", deviation }, + { "BandsShift", bandsShift }, { "Mode", mode }, + { "Data", array ?? [] }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iBandsOnArray, cmdParams); } public double iBullsPower(string symbol, int timeframe, int period, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift }; - return SendCommand(MtCommandType.iBullsPower, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iBullsPower, cmdParams); } public double iCCI(string symbol, int timeframe, int period, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift }; - return SendCommand(MtCommandType.iCCI, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iCCI, cmdParams); } public double iCCIOnArray(double[] array, int total, int period, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] { }); - commandParameters.Add(total); - commandParameters.Add(period); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iCCIOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "Period", period }, + { "Data", array ?? [] }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iCCIOnArray, cmdParams); } public double iCustom(string symbol, int timeframe, string name, int[] parameters, int mode, int shift) { - var response = SendRequest(new ICustomRequest - { - Symbol = symbol, - Timeframe = timeframe, - Name = name, - Mode = mode, - Shift = shift, - Params = new ArrayList(parameters), - ParamsType = ICustomRequest.ParametersType.Int - }); - return response?.Value ?? double.NaN; + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Name", name }, { "Mode", mode }, + { "Shift", shift }, { "ParamsType", (int)ParametersType.Int }, + { "Params", new ArrayList(parameters) } }; + + return SendCommand(ExecutorHandle, MtCommandType.iCustom, cmdParams); } public double iCustom(string symbol, int timeframe, string name, double[] parameters, int mode, int shift) { - var response = SendRequest(new ICustomRequest - { - Symbol = symbol, - Timeframe = timeframe, - Name = name, - Mode = mode, - Shift = shift, - Params = new ArrayList(parameters), - ParamsType = ICustomRequest.ParametersType.Double - }); - return response?.Value ?? double.NaN; + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Name", name }, { "Mode", mode }, + { "Shift", shift }, { "ParamsType", (int)ParametersType.Double }, + { "Params", new ArrayList(parameters) } }; + + return SendCommand(ExecutorHandle, MtCommandType.iCustom, cmdParams); } public double iCustom(string symbol, int timeframe, string name, int mode, int shift) { - var response = SendRequest(new ICustomRequest - { - Symbol = symbol, - Timeframe = timeframe, - Name = name, - Mode = mode, - Shift = shift - }); - return response?.Value ?? double.NaN; + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Name", name }, { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iCustom, cmdParams); } public double iDeMarker(string symbol, int timeframe, int period, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, shift }; - return SendCommand(MtCommandType.iDeMarker, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iDeMarker, cmdParams); } public double iEnvelopes(string symbol, int timeframe, int maPeriod, int maMethod, int maShift, int appliedPrice, double deviation, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, maPeriod, maMethod, maShift, appliedPrice, deviation, mode, shift }; - return SendCommand(MtCommandType.iEnvelopes, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "MaPeriod", maPeriod }, + { "MaMethod", maMethod }, { "MaShift", maShift }, + { "AppliedPrice", appliedPrice }, { "Deviation", deviation }, + { "Mode", mode }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iEnvelopes, cmdParams); } public double iEnvelopesOnArray(double[] array, int total, int maPeriod, int maMethod, int maShift, double deviation, int mode, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] {}); - commandParameters.Add(total); - commandParameters.Add(maPeriod); - commandParameters.Add(maMethod); - commandParameters.Add(maShift); - commandParameters.Add(deviation); - commandParameters.Add(mode); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iEnvelopesOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "MaPeriod", maPeriod }, { "MaMethod", maMethod }, + { "MaShift", maShift }, { "Deviation", deviation }, + { "Mode", mode }, { "Shift", shift }, + { "Data", array ?? [] } }; + return SendCommand(ExecutorHandle, MtCommandType.iEnvelopesOnArray, cmdParams); } public double iForce(string symbol, int timeframe, int period, int maMethod, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, maMethod, appliedPrice, shift }; - return SendCommand(MtCommandType.iForce, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "MaMethod", maMethod }, { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iForce, cmdParams); } public double iFractals(string symbol, int timeframe, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, mode, shift }; - return SendCommand(MtCommandType.iFractals, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iFractals, cmdParams); } public double iGator(string symbol, int timeframe, int jawPeriod, int jawShift, int teethPeriod, int teethShift, int lipsPeriod, int lipsShift, int maMethod, int appliedPrice, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, jawPeriod, jawShift, teethPeriod, teethShift, lipsPeriod, lipsShift, maMethod, appliedPrice, mode, shift }; - return SendCommand(MtCommandType.iGator, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "JawPeriod", jawPeriod }, + { "JawShift", jawShift }, { "TeethPeriod", teethPeriod }, + { "TeethShift", teethShift }, { "LipsPeriod", lipsPeriod }, + { "LipsShift", lipsShift }, { "MaMethod", maMethod }, + { "AppliedPrice", appliedPrice }, + { "Mode", mode }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iGator, cmdParams); } public double iIchimoku(string symbol, int timeframe, int tenkanSen, int kijunSen, int senkouSpanB, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, tenkanSen, kijunSen, senkouSpanB, mode, shift }; - return SendCommand(MtCommandType.iIchimoku, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "TenkanSen", tenkanSen }, + { "KijunSen", kijunSen }, + { "SenkouSpanB", senkouSpanB }, + { "Mode", mode }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iIchimoku, cmdParams); } public double iBWMFI(string symbol, int timeframe, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, shift }; - return SendCommand(MtCommandType.iBWMFI, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iBWMFI, cmdParams); } public double iMomentum(string symbol, int timeframe, int period, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift }; - return SendCommand(MtCommandType.iMomentum, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "AppliedPrice", appliedPrice }, { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iMomentum, cmdParams); } public double iMomentumOnArray(double[] array, int total, int period, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] {}); - commandParameters.Add(total); - commandParameters.Add(period); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iMomentumOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "Period", period }, + { "Shift", shift }, { "Data", array ?? [] } }; + return SendCommand(ExecutorHandle, MtCommandType.iMomentumOnArray, cmdParams); } public double iMFI(string symbol, int timeframe, int period, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, shift }; - return SendCommand(MtCommandType.iMFI, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iMFI, cmdParams); } public double iMA(string symbol, int timeframe, int period, int maShift, int maMethod, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, maShift, maMethod, appliedPrice, shift }; - return SendCommand(MtCommandType.iMA, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, { "Period", period }, + { "MaShift", maShift }, + { "MaMethod", maMethod }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iMA, cmdParams); } public double iMAOnArray(double[] array, int total, int period, int maShift, int maMethod, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] {}); - commandParameters.Add(total); - commandParameters.Add(period); - commandParameters.Add(maShift); - commandParameters.Add(maMethod); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iMAOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "Period", period }, + { "MaShift", maShift }, + { "MaMethod", maMethod }, + { "Shift", shift }, + { "Data", array ?? [] } }; + return SendCommand(ExecutorHandle, MtCommandType.iMAOnArray, cmdParams); } public double iOsMA(string symbol, int timeframe, int fastEmaPeriod, int slowEmaPeriod, int signalPeriod, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, fastEmaPeriod, slowEmaPeriod, signalPeriod, appliedPrice, shift }; - return SendCommand(MtCommandType.iOsMA, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "FastEmaPeriod", fastEmaPeriod }, + { "SlowEmaPeriod", slowEmaPeriod }, + { "SignalPeriod", signalPeriod }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iOsMA, cmdParams); } public double iMACD(string symbol, int timeframe, int fastEmaPeriod, int slowEmaPeriod, int signalPeriod, int appliedPrice, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, fastEmaPeriod, slowEmaPeriod, signalPeriod, appliedPrice, mode, shift }; - return SendCommand(MtCommandType.iMACD, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "FastEmaPeriod", fastEmaPeriod }, + { "SlowEmaPeriod", slowEmaPeriod }, + { "SignalPeriod", signalPeriod }, + { "AppliedPrice", appliedPrice }, + { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iMACD, cmdParams); } public double iOBV(string symbol, int timeframe, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, appliedPrice, shift }; - return SendCommand(MtCommandType.iOBV, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iOBV, cmdParams); } public double iSAR(string symbol, int timeframe, double step, double maximum, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, step, maximum, shift }; - return SendCommand(MtCommandType.iSAR, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "Step", step }, + { "Maximum", maximum }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iSAR, cmdParams); } public double iRSI( string symbol, int timeframe, int period, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift }; - return SendCommand(MtCommandType.iRSI, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "Period", period }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iRSI, cmdParams); } public double iRSIOnArray(double[] array, int total, int period, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] {}); - commandParameters.Add(total); - commandParameters.Add(period); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iMomentumOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "Period", period }, + { "Shift", shift }, + { "Data", array ?? [] } }; + return SendCommand(ExecutorHandle, MtCommandType.iMomentumOnArray, cmdParams); } public double iRVI(string symbol, int timeframe, int period, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, mode, shift }; - return SendCommand(MtCommandType.iRVI, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "Period", period }, + { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iRVI, cmdParams); } public double iStdDev(string symbol, int timeframe, int maPeriod, int maShift, int maMethod, int appliedPrice, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, maPeriod, maShift, maMethod, appliedPrice, shift }; - return SendCommand(MtCommandType.iStdDev, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "MaPeriod", maPeriod }, + { "MaShift", maShift }, + { "MaMethod", maMethod }, + { "AppliedPrice", appliedPrice }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iStdDev, cmdParams); } public double iStdDevOnArray(double[] array, int total, int maPeriod, int maShift, int maMethod, int shift) { - var arraySize = array?.Length ?? 0; - var commandParameters = new ArrayList { arraySize }; - commandParameters.AddRange(array ?? new double[] {}); - commandParameters.Add(total); - commandParameters.Add(maPeriod); - commandParameters.Add(maShift); - commandParameters.Add(maMethod); - commandParameters.Add(shift); - - return SendCommand(MtCommandType.iStdDevOnArray, commandParameters); + Dictionary cmdParams = new() { { "Total", total }, + { "MaPeriod", maPeriod }, + { "MaShift", maShift }, + { "MaMethod", maMethod }, + { "Shift", shift }, + { "Data", array ?? [] } }; + return SendCommand(ExecutorHandle, MtCommandType.iStdDevOnArray, cmdParams); } public double iStochastic(string symbol, int timeframe, int pKperiod, int pDperiod, int slowing, int method, int priceField, int mode, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, pKperiod, pDperiod, slowing, method, priceField, mode, shift }; - return SendCommand(MtCommandType.iStochastic, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "Kperiod", pKperiod }, + { "Dperiod", pDperiod }, + { "Slowing", slowing }, + { "Method", method }, + { "PriceField", priceField }, + { "Mode", mode }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iStochastic, cmdParams); } public double iWPR(string symbol, int timeframe, int period, int shift) { - var commandParameters = new ArrayList { symbol, timeframe, period, shift }; - return SendCommand(MtCommandType.iWPR, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe }, + { "Period", period }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iWPR, cmdParams); } #endregion #region Timeseries access public int iBars(string symbol, ChartPeriod timeframe) { - var commandParameters = new ArrayList { symbol, (int)timeframe }; - return SendCommand(MtCommandType.iBars, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.iBars, cmdParams); } public int iBarShift(string symbol, ChartPeriod timeframe, DateTime time, bool exact) { - var commandParameters = new ArrayList { symbol, (int)timeframe, MtApiTimeConverter.ConvertToMtTime(time), exact }; - return SendCommand(MtCommandType.iBarShift, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Time", MtApiTimeConverter.ConvertToMtTime(time) }, + { "Exact", exact } }; + return SendCommand(ExecutorHandle, MtCommandType.iBarShift, cmdParams); } public double iClose(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - return SendCommand(MtCommandType.iClose, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iClose, cmdParams); } public double iHigh(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - return SendCommand(MtCommandType.iHigh, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iHigh, cmdParams); } public int iHighest(string symbol, ChartPeriod timeframe, SeriesIdentifier type, int count, int start) { - var commandParameters = new ArrayList { symbol, (int)timeframe, (int)type, count, start }; - return SendCommand(MtCommandType.iHighest, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Type", (int)type }, + { "Count", count }, + { "StartValue", start } }; + return SendCommand(ExecutorHandle, MtCommandType.iHighest, cmdParams); } public double iLow(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - return SendCommand(MtCommandType.iLow, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iLow, cmdParams); } public int iLowest(string symbol, ChartPeriod timeframe, SeriesIdentifier type, int count, int start) { - var commandParameters = new ArrayList { symbol, (int)timeframe, (int)type, count, start }; - return SendCommand(MtCommandType.iLowest, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Type", type }, + { "Count", count }, + { "Start", start } }; + return SendCommand(ExecutorHandle, MtCommandType.iLowest, cmdParams); } public double iOpen(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - return SendCommand(MtCommandType.iOpen, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iOpen, cmdParams); } public DateTime iTime(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - var commandResponse = SendCommand(MtCommandType.iTime, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Shift", shift } }; + var commandResponse = SendCommand(ExecutorHandle, MtCommandType.iTime, cmdParams); return MtApiTimeConverter.ConvertFromMtTime(commandResponse); } public double iVolume(string symbol, ChartPeriod timeframe, int shift) { - var commandParameters = new ArrayList { symbol, (int)timeframe, shift }; - return SendCommand(MtCommandType.iVolume, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.iVolume, cmdParams); } - //public double[] iCloseArray(string symbol, ChartPeriod timeframe, int shift, int valueCount) - //{ - // int doubleArraySendLimit = DoubleArrayLimit; - // int limitCount = valueCount / doubleArraySendLimit; - // int valueCountModulo = valueCount - limitCount * doubleArraySendLimit; - - // var resultArray = new double[valueCount]; - // for (int i = 0; i < limitCount; i++) - // { - // var commandParameters = new ArrayList { symbol, (int)timeframe, i * doubleArraySendLimit, doubleArraySendLimit }; - // var result = SendCommand(MtCommandType.iCloseArray, commandParameters); - // if (result != null) - // Array.Copy(result, 0, resultArray, i * doubleArraySendLimit, doubleArraySendLimit); - // } - - // if (valueCountModulo > 0) - // { - // var commandParameters = new ArrayList { symbol, (int)timeframe, limitCount * doubleArraySendLimit, valueCountModulo }; - // var result = SendCommand(MtCommandType.iCloseArray, commandParameters); - // if (result != null) - // Array.Copy(result, 0, resultArray, limitCount * doubleArraySendLimit, valueCountModulo); - // } - // return resultArray; - - // var commandParameters = new ArrayList { symbol, (int)timeframe, shift, valueCount }; - // return SendCommand(MtCommandType.iCloseArray, commandParameters); - //} - - public double[] iCloseArray(string symbol, ChartPeriod timeframe) + public double[]? iCloseArray(string symbol, ChartPeriod timeframe) { - var commandParameters = new ArrayList { symbol, (int)timeframe }; - return SendCommand(MtCommandType.iCloseArray, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.iCloseArray, cmdParams); } - public double[] iHighArray(string symbol, ChartPeriod timeframe) + public double[]? iHighArray(string symbol, ChartPeriod timeframe) { - var commandParameters = new ArrayList { symbol, (int)timeframe }; - return SendCommand(MtCommandType.iHighArray, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.iHighArray, cmdParams); } - public double[] iLowArray(string symbol, ChartPeriod timeframe) + public double[]? iLowArray(string symbol, ChartPeriod timeframe) { - var commandParameters = new ArrayList { symbol, (int)timeframe }; - return SendCommand(MtCommandType.iLowArray, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.iLowArray, cmdParams); } - public double[] iOpenArray(string symbol, ChartPeriod timeframe) + public double[]? iOpenArray(string symbol, ChartPeriod timeframe) { - var commandParameters = new ArrayList { symbol, (int)timeframe }; - return SendCommand(MtCommandType.iOpenArray, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.iOpenArray, cmdParams); } - public double[] iVolumeArray(string symbol, ChartPeriod timeframe) + public double[]? iVolumeArray(string symbol, ChartPeriod timeframe) { - var commandParameters = new ArrayList { symbol, (int)timeframe }; - return SendCommand(MtCommandType.iVolumeArray, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.iVolumeArray, cmdParams); } - public DateTime[] iTimeArray(string symbol, ChartPeriod timeframe) + public DateTime[]? iTimeArray(string symbol, ChartPeriod timeframe) { - DateTime[] result = null; - - var commandParameters = new ArrayList { symbol, (int)timeframe }; - - var response = SendCommand(MtCommandType.iTimeArray, commandParameters); - + DateTime[]? result = null; + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", (int)timeframe } }; + var response = SendCommand(ExecutorHandle, MtCommandType.iTimeArray, cmdParams); if (response != null) { result = new DateTime[response.Length]; - for(var i = 0; i < response.Length; i++) - { result[i] = MtApiTimeConverter.ConvertFromMtTime(response[i]); - } } - return result; } public bool RefreshRates() { - return SendCommand(MtCommandType.RefreshRates, null); + return SendCommand(ExecutorHandle, MtCommandType.RefreshRates, null); } - public List CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count) + public List? CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count) { - var response = SendRequest(new CopyRates1Request - { - SymbolName = symbolName, - Timeframe = timeframe, - StartPos = startPos, - Count = count - }); - return response?.Rates; + Dictionary cmdParams = new() { { "SymbolName", symbolName }, + { "Timeframe", (int)timeframe }, { "StartPos", startPos }, { "Count", count }, + { "CopyRatesType", 1 } }; + return SendCommand>(ExecutorHandle, MtCommandType.CopyRates, cmdParams); } - public List CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count) + public List? CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count) { - var response = SendRequest(new CopyRates2Request - { - SymbolName = symbolName, - Timeframe = timeframe, - StartTime = MtApiTimeConverter.ConvertToMtTime(startTime), - Count = count - }); - return response?.Rates; + Dictionary cmdParams = new() { { "SymbolName", symbolName }, + { "Timeframe", (int)timeframe }, { "StartTime", MtApiTimeConverter.ConvertToMtTime(startTime) },{ "Count", count }, + { "CopyRatesType", 2 } }; + return SendCommand>(ExecutorHandle, MtCommandType.CopyRates, cmdParams); } - public List CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime) + public List? CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime) { - var response = SendRequest(new CopyRates3Request - { - SymbolName = symbolName, - Timeframe = timeframe, - StartTime = MtApiTimeConverter.ConvertToMtTime(startTime), - StopTime = MtApiTimeConverter.ConvertToMtTime(stopTime) - }); - return response?.Rates; + Dictionary cmdParams = new() { { "SymbolName", symbolName }, + { "Timeframe", (int)timeframe }, { "StartTime", MtApiTimeConverter.ConvertToMtTime(startTime) }, + { "StopTime", MtApiTimeConverter.ConvertToMtTime(stopTime) }, + { "CopyRatesType", 3 } }; + return SendCommand>(ExecutorHandle, MtCommandType.CopyRates, cmdParams); } /// @@ -1671,14 +1627,9 @@ namespace MtApi /// public long SeriesInfoInteger(string symbolName, ENUM_TIMEFRAMES timeframe, EnumSeriesInfoInteger propId) { - var response = SendRequest(new SeriesInfoIntegerRequest - { - SymbolName = symbolName, - Timeframe = (int)timeframe, - PropId = (int)propId - }); - - return response?.Value ?? 0; + Dictionary cmdParams = new() { { "SymbolName", symbolName }, + { "Timeframe", (int)timeframe }, { "PropId", (int)propId } }; + return SendCommand(ExecutorHandle, MtCommandType.SeriesInfoInteger, cmdParams); } #endregion @@ -1695,8 +1646,9 @@ namespace MtApi /// public double MarketInfo(string symbol, MarketInfoModeType type) { - var commandParameters = new ArrayList { symbol, (int)type }; - return SendCommand(MtCommandType.MarketInfo, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Type", (int)type } }; + return SendCommand(ExecutorHandle, MtCommandType.MarketInfo, cmdParams); } /// @@ -1708,8 +1660,8 @@ namespace MtApi /// public int SymbolsTotal(bool selected) { - var commandParameters = new ArrayList { selected }; - return SendCommand(MtCommandType.SymbolsTotal, commandParameters); + Dictionary cmdParams = new() { { "Selected", selected } }; + return SendCommand(ExecutorHandle, MtCommandType.SymbolsTotal, cmdParams); } /// @@ -1720,10 +1672,11 @@ namespace MtApi /// ///Value of string type with the symbol name. /// - public string SymbolName(int pos, bool selected) + public string? SymbolName(int pos, bool selected) { - var commandParameters = new ArrayList { pos, selected }; - return SendCommand(MtCommandType.SymbolName, commandParameters); + Dictionary cmdParams = new() { { "Pos", pos }, + { "Selected", selected } }; + return SendCommand(ExecutorHandle, MtCommandType.SymbolName, cmdParams); } /// @@ -1736,8 +1689,9 @@ namespace MtApi /// public bool SymbolSelect(string name, bool select) { - var commandParameters = new ArrayList { name, select }; - return SendCommand(MtCommandType.SymbolSelect, commandParameters); + Dictionary cmdParams = new() { { "Name", name }, + { "Select", select } }; + return SendCommand(ExecutorHandle, MtCommandType.SymbolSelect, cmdParams); } /// @@ -1750,8 +1704,9 @@ namespace MtApi /// public long SymbolInfoInteger(string name, EnumSymbolInfoInteger propId) { - var commandParameters = new ArrayList { name, (int)propId }; - return SendCommand(MtCommandType.SymbolInfoInteger, commandParameters); + Dictionary cmdParams = new() { { "Name", name }, + { "PropId", (int)propId } }; + return SendCommand(ExecutorHandle, MtCommandType.SymbolInfoInteger, cmdParams); } /// @@ -1762,10 +1717,11 @@ namespace MtApi /// ///The value of string type. /// - public string SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING propId) + public string? SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING propId) { - var commandParameters = new ArrayList { name, (int)propId }; - return SendCommand(MtCommandType.SymbolInfoString, commandParameters); + Dictionary cmdParams = new() { { "Name", name }, + { "PropId", (int)propId } }; + return SendCommand(ExecutorHandle, MtCommandType.SymbolInfoString, cmdParams); } /// @@ -1779,10 +1735,11 @@ namespace MtApi /// ///The value session. /// - public MtSession SymbolInfoSession(string symbol, DayOfWeek dayOfWeek, uint index, SessionType type) + public MtSession? SymbolInfoSession(string symbol, DayOfWeek dayOfWeek, uint index, SessionType type) { - var responce = SendRequest(new SessionRequest { Symbol = symbol, DayOfWeek = dayOfWeek, SessionIndex = (int)index, SessionType = type }); - return responce?.Session; + Dictionary cmdParams = new() { { "SymbolName", symbol }, + { "DayOfWeek", (int)dayOfWeek }, { "SessionIndex", (int)index }, { "SessionType", type } }; + return SendCommand(ExecutorHandle, MtCommandType.Session, cmdParams); } /// @@ -1795,13 +1752,9 @@ namespace MtApi /// public double SymbolInfoDouble(string symbolName, EnumSymbolInfoDouble propId) { - var response = SendRequest(new SymbolInfoDoubleRequest - { - SymbolName = symbolName, - PropId = (int)propId - }); + Dictionary cmdParams = new() { { "SymbolName", symbolName }, { "PropId", (int)propId } }; - return response?.Value ?? 0; + return SendCommand(ExecutorHandle, MtCommandType.SymbolInfoDouble, cmdParams); } /// @@ -1811,14 +1764,10 @@ namespace MtApi /// /// MqlTick object, to which the current prices and time of the last price update will be placed. /// - public MqlTick SymbolInfoTick(string symbol) + public MqlTick? SymbolInfoTick(string symbol) { - var response = SendRequest(new SymbolInfoTickRequest - { - Symbol = symbol - }); - - return response?.Tick; + Dictionary cmdParams = new() { { "Symbol", symbol } }; + return SendCommand(ExecutorHandle, MtCommandType.SymbolInfoTick, cmdParams); } #endregion @@ -1832,7 +1781,7 @@ namespace MtApi /// public long ChartId() { - return SendCommand(MtCommandType.ChartId, null); + return SendCommand(ExecutorHandle, MtCommandType.ChartId); } /// @@ -1840,8 +1789,8 @@ namespace MtApi /// public void ChartRedraw(long chartId = 0) { - var commandParameters = new ArrayList { chartId }; - SendCommand(MtCommandType.ChartRedraw, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId } }; + SendCommand(ExecutorHandle, MtCommandType.ChartRedraw, cmdParams); } /// @@ -1854,8 +1803,9 @@ namespace MtApi /// public bool ChartApplyTemplate(long chartId, string filename) { - var commandParameters = new ArrayList { chartId, filename }; - return SendCommand(MtCommandType.ChartApplyTemplate, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "Filename", filename } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartApplyTemplate, cmdParams); } /// @@ -1868,8 +1818,9 @@ namespace MtApi /// public bool ChartSaveTemplate(long chartId, string filename) { - var commandParameters = new ArrayList { chartId, filename }; - return SendCommand(MtCommandType.ChartSaveTemplate, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "Filename", filename } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartSaveTemplate, cmdParams); } /// @@ -1882,8 +1833,9 @@ namespace MtApi /// public int ChartWindowFind(long chartId, string indicatorShortname) { - var commandParameters = new ArrayList { chartId, indicatorShortname }; - return SendCommand(MtCommandType.ChartWindowFind, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "IndicatorShortname", indicatorShortname } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartWindowFind, cmdParams); } /// @@ -1900,22 +1852,17 @@ namespace MtApi /// public bool ChartTimePriceToXY(long chartId, int subWindow, DateTime? time, double price, out int x, out int y) { - var commandParameters = new ArrayList { chartId, subWindow, MtApiTimeConverter.ConvertToMtTime(time), price }; - var str = SendCommand(MtCommandType.ChartTimePriceToXY, commandParameters); - var res = false; - x = 0; - y = 0; - if (!string.IsNullOrEmpty(str) && str.Contains(";")) - { - var values = str.Split(';'); - if (values.Length > 1) - { - int.TryParse(values[0], out x); - int.TryParse(values[1], out y); - res = true; - } - } - return res; + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "SubWindow", subWindow }, + { "Time", MtApiTimeConverter.ConvertToMtTime(time) }, + { "Price", price } }; + var response = SendCommand>>(ExecutorHandle, MtCommandType.ChartTimePriceToXY, cmdParams); + if (response != null && response.Result != null + && response.Result.TryGetValue("X", out x) + && response.Result.TryGetValue("Y", out y)) + return response.RetVal; + x = 0; y = 0; + return false; } /// @@ -1932,26 +1879,24 @@ namespace MtApi /// public bool ChartXYToTimePrice(long chartId, int x, int y, out int subWindow, out DateTime? time, out double price) { - var commandParameters = new ArrayList { chartId, x, y }; - var str = SendCommand(MtCommandType.ChartXYToTimePrice, commandParameters); - var res = false; + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "X", x }, + { "Y", y } }; + var response = SendCommand>>(ExecutorHandle, MtCommandType.ChartXYToTimePrice, cmdParams); + if (response != null && response.Result != null + && response.Result.TryGetValue("SubWindow", out object? mtSubWindow) + && response.Result.TryGetValue("Time", out object? mtTime) + && response.Result.TryGetValue("Price", out object? mtPrice)) + { + subWindow = Convert.ToInt32(mtSubWindow); + time = MtApiTimeConverter.ConvertFromMtTime(Convert.ToInt32(mtTime)); + price = Convert.ToDouble(mtPrice); + return response.RetVal; + } subWindow = 0; time = null; price = double.NaN; - if (!string.IsNullOrEmpty(str) && str.Contains(";")) - { - var values = str.Split(';'); - if (values.Length > 2) - { - int.TryParse(values[0], out subWindow); - int mt4Time; - int.TryParse(values[1], out mt4Time); - time = MtApiTimeConverter.ConvertFromMtTime(mt4Time); - double.TryParse(values[2], out price); - res = true; - } - } - return res; + return false; } /// @@ -1964,8 +1909,9 @@ namespace MtApi /// public long ChartOpen(string symbol, ENUM_TIMEFRAMES period) { - var commandParameters = new ArrayList { symbol, (int)period }; - return SendCommand(MtCommandType.ChartOpen, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Period", period } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartOpen, cmdParams); } /// @@ -1973,7 +1919,7 @@ namespace MtApi /// public long ChartFirst() { - return SendCommand(MtCommandType.ChartFirst, null); + return SendCommand(ExecutorHandle, MtCommandType.ChartFirst); } /// @@ -1985,8 +1931,8 @@ namespace MtApi /// public long ChartNext(long chartId) { - var commandParameters = new ArrayList { chartId }; - return SendCommand(MtCommandType.ChartNext, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartNext, cmdParams); } /// @@ -1998,8 +1944,8 @@ namespace MtApi /// public bool ChartClose(long chartId) { - var commandParameters = new ArrayList { chartId }; - return SendCommand(MtCommandType.ChartClose, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartClose, cmdParams); } /// @@ -2009,10 +1955,10 @@ namespace MtApi /// ///If chart does not exist, the result will be an empty string. /// - public string ChartSymbol(long chartId) + public string? ChartSymbol(long chartId) { - var commandParameters = new ArrayList { chartId }; - return SendCommand(MtCommandType.ChartSymbol, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartSymbol, cmdParams); } /// @@ -2024,8 +1970,8 @@ namespace MtApi /// public ENUM_TIMEFRAMES ChartPeriod(long chartId) { - var commandParameters = new ArrayList { chartId }; - return (ENUM_TIMEFRAMES) SendCommand(MtCommandType.ChartPeriod, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId } }; + return (ENUM_TIMEFRAMES) SendCommand(ExecutorHandle, MtCommandType.ChartPeriod, cmdParams); } /// @@ -2039,8 +1985,10 @@ namespace MtApi /// public bool ChartSetDouble(long chartId, EnumChartPropertyDouble propId, double value) { - var commandParameters = new ArrayList { chartId, (int)propId, value }; - return SendCommand(MtCommandType.ChartSetDouble, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "PropId", (int)propId }, + { "Value", value } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartSetDouble, cmdParams); } /// @@ -2054,8 +2002,10 @@ namespace MtApi /// public bool ChartSetInteger(long chartId, EnumChartPropertyInteger propId, long value) { - var commandParameters = new ArrayList { chartId, (int)propId, value }; - return SendCommand(MtCommandType.ChartSetInteger, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "PropId", (int)propId }, + { "Value", value } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartSetInteger, cmdParams); } /// @@ -2069,8 +2019,10 @@ namespace MtApi /// public bool ChartSetString(long chartId, EnumChartPropertyString propId, string value) { - var commandParameters = new ArrayList { chartId, (int)propId, value }; - return SendCommand(MtCommandType.ChartSetString, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "PropId", (int)propId }, + { "Value", value } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartSetString, cmdParams); } /// @@ -2084,8 +2036,10 @@ namespace MtApi /// public double ChartGetDouble(long chartId, EnumChartPropertyDouble propId, int subWindow = 0) { - var commandParameters = new ArrayList { chartId, (int)propId, subWindow }; - return SendCommand(MtCommandType.ChartGetDouble, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "PropId", (int)propId }, + { "SubWindow", subWindow } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartGetDouble, cmdParams); } /// @@ -2099,8 +2053,10 @@ namespace MtApi /// public long ChartGetInteger(long chartId, EnumChartPropertyInteger propId, int subWindow = 0) { - var commandParameters = new ArrayList { chartId, (int)propId, subWindow }; - return SendCommand(MtCommandType.ChartGetInteger, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "PropId", (int)propId }, + { "SubWindow", subWindow } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartGetInteger, cmdParams); } /// @@ -2111,10 +2067,11 @@ namespace MtApi /// ///The value of string type. /// - public string ChartGetString(long chartId, EnumChartPropertyString propId) + public string? ChartGetString(long chartId, EnumChartPropertyString propId) { - var commandParameters = new ArrayList { chartId, (int)propId }; - return SendCommand(MtCommandType.ChartGetString, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "PropId", (int)propId } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartGetString, cmdParams); } /// @@ -2128,8 +2085,10 @@ namespace MtApi /// public bool ChartNavigate(long chartId, int position, int shift = 0) { - var commandParameters = new ArrayList { chartId, position, shift }; - return SendCommand(MtCommandType.ChartNavigate, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "Position", position }, + { "Shift", shift } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartNavigate, cmdParams); } /// @@ -2143,8 +2102,10 @@ namespace MtApi /// public bool ChartIndicatorDelete(long chartId, int subWindow, string indicatorShortname) { - var commandParameters = new ArrayList { chartId, subWindow, indicatorShortname }; - return SendCommand(MtCommandType.ChartIndicatorDelete, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "SubWindow", subWindow }, + { "IndicatorShortname", indicatorShortname } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartIndicatorDelete, cmdParams); } /// @@ -2156,10 +2117,12 @@ namespace MtApi /// ///The short name of the indicator which is set in the INDICATOR_SHORTNAME property with the IndicatorSetString() function. /// - public string ChartIndicatorName(long chartId, int subWindow, int index) + public string? ChartIndicatorName(long chartId, int subWindow, int index) { - var commandParameters = new ArrayList { chartId, subWindow, index }; - return SendCommand(MtCommandType.ChartIndicatorName, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "SubWindow", subWindow }, + { "Index", index } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartIndicatorName, cmdParams); } /// @@ -2172,8 +2135,9 @@ namespace MtApi /// public int ChartIndicatorsTotal(long chartId, int subWindow) { - var commandParameters = new ArrayList { chartId, subWindow }; - return SendCommand(MtCommandType.ChartIndicatorsTotal, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "SubWindow", subWindow } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartIndicatorsTotal, cmdParams); } /// @@ -2181,7 +2145,7 @@ namespace MtApi /// public int ChartWindowOnDropped() { - return SendCommand(MtCommandType.ChartWindowOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.ChartWindowOnDropped); } /// @@ -2189,7 +2153,7 @@ namespace MtApi /// public double ChartPriceOnDropped() { - return SendCommand(MtCommandType.ChartPriceOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.ChartPriceOnDropped); } /// @@ -2197,7 +2161,7 @@ namespace MtApi /// public DateTime ChartTimeOnDropped() { - var res = SendCommand(MtCommandType.ChartTimeOnDropped, null); + var res = SendCommand(ExecutorHandle, MtCommandType.ChartTimeOnDropped); return MtApiTimeConverter.ConvertFromMtTime(res); } @@ -2206,7 +2170,7 @@ namespace MtApi /// public int ChartXOnDropped() { - return SendCommand(MtCommandType.ChartXOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.ChartXOnDropped); } /// @@ -2214,7 +2178,7 @@ namespace MtApi /// public int ChartYOnDropped() { - return SendCommand(MtCommandType.ChartYOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.ChartYOnDropped); } /// @@ -2228,8 +2192,10 @@ namespace MtApi /// public bool ChartSetSymbolPeriod(long chartId, string symbol, ENUM_TIMEFRAMES period) { - var commandParameters = new ArrayList { chartId, symbol, (int)period }; - return SendCommand(MtCommandType.ChartSetSymbolPeriod, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "Symbol", symbol }, + { "Period", period } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartSetSymbolPeriod, cmdParams); } /// @@ -2245,8 +2211,12 @@ namespace MtApi /// public bool ChartScreenShot(long chartId, string filename, int width, int height, EnumAlignMode alignMode = EnumAlignMode.ALIGN_RIGHT) { - var commandParameters = new ArrayList { chartId, filename, width, height, (int)alignMode }; - return SendCommand(MtCommandType.ChartScreenShot, commandParameters); + Dictionary cmdParams = new() { { "ChartId", chartId }, + { "Filename", filename }, + { "Width", width }, + { "Height", height }, + { "AlignMode", (int)alignMode } }; + return SendCommand(ExecutorHandle, MtCommandType.ChartScreenShot, cmdParams); } /// @@ -2257,7 +2227,7 @@ namespace MtApi /// public int WindowBarsPerChart() { - return SendCommand(MtCommandType.WindowBarsPerChart, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowBarsPerChart); } /// @@ -2266,9 +2236,9 @@ namespace MtApi /// ///The name of the executed Expert Advisor, script, custom indicator, or library, depending on the MQL4 program, from which this function has been called. /// - public string WindowExpertName() + public string? WindowExpertName() { - return SendCommand(MtCommandType.WindowExpertName, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowExpertName); } /// @@ -2280,8 +2250,8 @@ namespace MtApi /// public int WindowFind(string name) { - var commandParameters = new ArrayList { name }; - return SendCommand(MtCommandType.WindowFind, commandParameters); + Dictionary cmdParams = new() { { "Name", name } }; + return SendCommand(ExecutorHandle, MtCommandType.WindowFind, cmdParams); } /// @@ -2292,7 +2262,7 @@ namespace MtApi /// public int WindowFirstVisibleBar() { - return SendCommand(MtCommandType.WindowFirstVisibleBar, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowFirstVisibleBar); } /// @@ -2305,8 +2275,9 @@ namespace MtApi /// public int WindowHandle(string symbol, int timeframe) { - var commandParameters = new ArrayList { symbol, timeframe }; - return SendCommand(MtCommandType.WindowHandle, commandParameters); + Dictionary cmdParams = new() { { "Symbol", symbol }, + { "Timeframe", timeframe } }; + return SendCommand(ExecutorHandle, MtCommandType.WindowHandle, cmdParams); } /// @@ -2318,8 +2289,8 @@ namespace MtApi /// public bool WindowIsVisible(int index) { - var commandParameters = new ArrayList { index }; - return SendCommand(MtCommandType.WindowIsVisible, commandParameters); + Dictionary cmdParams = new() { { "Index", index } }; + return SendCommand(ExecutorHandle, MtCommandType.WindowIsVisible, cmdParams); } /// @@ -2330,7 +2301,7 @@ namespace MtApi /// public int WindowOnDropped() { - return SendCommand(MtCommandType.WindowOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowOnDropped); } /// @@ -2342,8 +2313,8 @@ namespace MtApi /// public int WindowPriceMax(int index = 0) { - var commandParameters = new ArrayList { index }; - return SendCommand(MtCommandType.WindowPriceMax, commandParameters); + Dictionary cmdParams = new() { { "Index", index } }; + return SendCommand(ExecutorHandle, MtCommandType.WindowPriceMax, cmdParams); } /// @@ -2355,8 +2326,8 @@ namespace MtApi /// public int WindowPriceMin(int index = 0) { - var commandParameters = new ArrayList { index }; - return SendCommand(MtCommandType.WindowPriceMin, commandParameters); + Dictionary cmdParams = new() { { "Index", index } }; + return SendCommand(ExecutorHandle, MtCommandType.WindowPriceMin, cmdParams); } /// @@ -2367,7 +2338,7 @@ namespace MtApi /// public double WindowPriceOnDropped() { - return SendCommand(MtCommandType.WindowPriceOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowPriceOnDropped); } /// @@ -2378,7 +2349,7 @@ namespace MtApi /// public void WindowRedraw() { - SendCommand(MtCommandType.WindowRedraw, null); + SendCommand(ExecutorHandle, MtCommandType.WindowRedraw); } /// @@ -2395,8 +2366,13 @@ namespace MtApi /// public bool WindowScreenShot(string filename, int sizeX, int sizeY, int startBar = -1, int chartScale = -1, int chartMode = -1) { - var commandParameters = new ArrayList { filename, sizeX, sizeY, startBar, chartScale, chartMode }; - return SendCommand(MtCommandType.WindowScreenShot, commandParameters); + Dictionary cmdParams = new() { { "Filename", filename }, + { "SizeX", sizeX }, + { "SizeY", sizeY }, + { "StartBar", startBar }, + { "ChartScale", chartScale }, + { "ChartMode", chartMode } }; + return SendCommand(ExecutorHandle, MtCommandType.WindowScreenShot, cmdParams); } /// @@ -2407,7 +2383,7 @@ namespace MtApi /// public DateTime WindowTimeOnDropped() { - var res = SendCommand(MtCommandType.WindowTimeOnDropped, null); + var res = SendCommand(ExecutorHandle, MtCommandType.WindowTimeOnDropped); return MtApiTimeConverter.ConvertFromMtTime(res); } @@ -2419,7 +2395,7 @@ namespace MtApi /// public int WindowsTotal() { - return SendCommand(MtCommandType.WindowsTotal, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowsTotal); } /// @@ -2430,7 +2406,7 @@ namespace MtApi /// public int WindowXOnDropped() { - return SendCommand(MtCommandType.WindowXOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowXOnDropped); } /// @@ -2441,7 +2417,7 @@ namespace MtApi /// public int WindowYOnDropped() { - return SendCommand(MtCommandType.WindowYOnDropped, null); + return SendCommand(ExecutorHandle, MtCommandType.WindowYOnDropped); } #endregion @@ -2466,26 +2442,20 @@ namespace MtApi public bool ObjectCreate(long chartId, string objectName, EnumObject objectType, int subWindow, DateTime? time1, double price1, DateTime? time2 = null, double? price2 = null, DateTime? time3 = null, double? price3 = null) { - var namedParams = new Dictionary + Dictionary cmdParams = new() { - {nameof(chartId), chartId}, - {nameof(objectName), objectName}, - {nameof(objectType), (int) objectType}, - {nameof(subWindow), subWindow}, - {nameof(time1), MtApiTimeConverter.ConvertToMtTime(time1)}, - {nameof(price1), price1} + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "ObjectType", (int)objectType }, + { "SubWindow", subWindow }, + { "Time1", MtApiTimeConverter.ConvertToMtTime(time1) }, + { "Price1", price1 }, + { "Time2", time2 != null ? MtApiTimeConverter.ConvertToMtTime(time2.Value) : 0 }, + { "Price2", price2 != null ? price2.Value : 0.0 }, + { "Time3", time3 != null ? MtApiTimeConverter.ConvertToMtTime(time3.Value) : 0 }, + { "Price3", price3 != null ? price3.Value : 0.0 } }; - - if (time2 != null) - namedParams.Add(nameof(time2), MtApiTimeConverter.ConvertToMtTime(time2.Value)); - if (price2 != null) - namedParams.Add(nameof(price2), price2.Value); - if (time3 != null) - namedParams.Add(nameof(time3), MtApiTimeConverter.ConvertToMtTime(time3.Value)); - if (price3 != null) - namedParams.Add(nameof(price3), price3.Value); - - return SendCommand(MtCommandType.ObjectCreate, null, namedParams); + return SendCommand(ExecutorHandle, MtCommandType.ObjectCreate, cmdParams); } /// @@ -2498,10 +2468,16 @@ namespace MtApi /// ///Name of the object is returned in case of success. /// - public string ObjectName(long chartId, int objectIndex, int subWindow = EMPTY, int objectType = EMPTY) + public string? ObjectName(long chartId, int objectIndex, int subWindow = EMPTY, int objectType = EMPTY) { - var commandParameters = new ArrayList { chartId, objectIndex, subWindow, objectType }; - return SendCommand(MtCommandType.ObjectName, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectIndex", objectIndex }, + { "SubWindow", subWindow }, + { "ObjectType", objectType } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectName, cmdParams); } /// @@ -2514,8 +2490,12 @@ namespace MtApi /// public bool ObjectDelete(long chartId, string objectName) { - var commandParameters = new ArrayList { chartId, objectName }; - return SendCommand(MtCommandType.ObjectDelete, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectDelete, cmdParams); } /// @@ -2529,8 +2509,13 @@ namespace MtApi /// public int ObjectsDeleteAll(long chartId, int subWindow = EMPTY, int objectType = EMPTY) { - var commandParameters = new ArrayList { chartId, subWindow, objectType }; - return SendCommand(MtCommandType.ObjectsDeleteAll, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "SubWindow", subWindow }, + { "ObjectType", objectType } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectsDeleteAll, cmdParams); } /// @@ -2543,8 +2528,12 @@ namespace MtApi /// public int ObjectFind(long chartId, string objectName) { - var commandParameters = new ArrayList { chartId, objectName }; - return SendCommand(MtCommandType.ObjectFind, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectFind, cmdParams); } /// @@ -2559,8 +2548,14 @@ namespace MtApi /// public DateTime ObjectGetTimeByValue(long chartId, string objectName, double value, int lineId = 0) { - var commandParameters = new ArrayList { chartId, objectName, value, lineId }; - var res = SendCommand(MtCommandType.ObjectGetTimeByValue, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "Value", value }, + { "LineId", lineId } + }; + var res = SendCommand(ExecutorHandle, MtCommandType.ObjectGetTimeByValue, cmdParams); return MtApiTimeConverter.ConvertFromMtTime(res); } @@ -2576,8 +2571,14 @@ namespace MtApi /// public double ObjectGetValueByTime(long chartId, string objectName, DateTime? time, int lineId = 0) { - var commandParameters = new ArrayList { chartId, objectName, time, lineId }; - return SendCommand(MtCommandType.ObjectGetValueByTime, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "Time", MtApiTimeConverter.ConvertToMtTime(time) }, + { "LineId", lineId } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetValueByTime, cmdParams); } /// @@ -2593,8 +2594,15 @@ namespace MtApi /// public bool ObjectMove(long chartId, string objectName, int pointIndex, DateTime? time, double price) { - var commandParameters = new ArrayList { chartId, objectName, pointIndex, MtApiTimeConverter.ConvertToMtTime(time), price }; - return SendCommand(MtCommandType.ObjectMove, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PointIndex", pointIndex }, + { "Time", MtApiTimeConverter.ConvertToMtTime(time) }, + { "Price", price } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectMove, cmdParams); } /// @@ -2608,8 +2616,13 @@ namespace MtApi /// public int ObjectsTotal(long chartId, int subWindow = EMPTY, int type = EMPTY) { - var commandParameters = new ArrayList { chartId, subWindow, type }; - return SendCommand(MtCommandType.ObjectsTotal, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "SubWindow", subWindow }, + { "Type", type } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectsTotal, cmdParams); } /// @@ -2624,8 +2637,14 @@ namespace MtApi /// public double ObjectGetDouble(long chartId, string objectName, EnumObjectPropertyDouble propId, int propModifier = 0) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propModifier }; - return SendCommand(MtCommandType.ObjectGetDouble, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropModifier", propModifier } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetDouble, cmdParams); } /// @@ -2640,8 +2659,14 @@ namespace MtApi /// public long ObjectGetInteger(long chartId, string objectName, EnumObjectPropertyInteger propId, int propModifier = 0) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propModifier }; - return SendCommand(MtCommandType.ObjectGetInteger, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropModifier", propModifier } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetInteger, cmdParams); } /// @@ -2654,10 +2679,16 @@ namespace MtApi /// ///String value. /// - public string ObjectGetString(long chartId, string objectName, EnumObjectPropertyString propId, int propModifier = 0) + public string? ObjectGetString(long chartId, string objectName, EnumObjectPropertyString propId, int propModifier = 0) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propModifier }; - return SendCommand(MtCommandType.ObjectGetString, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropModifier", propModifier } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetString, cmdParams); } /// @@ -2672,8 +2703,14 @@ namespace MtApi /// public bool ObjectSetDouble(long chartId, string objectName, EnumObjectPropertyDouble propId, double propValue) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propValue }; - return SendCommand(MtCommandType.ObjectSetDouble, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropValue", propValue } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetDouble, cmdParams); } /// @@ -2689,9 +2726,15 @@ namespace MtApi /// public bool ObjectSetDouble(long chartId, string objectName, EnumObjectPropertyDouble propId, int propModifier, double propValue) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propValue }; - var namedParams = new Dictionary {{nameof(propModifier), propModifier}}; - return SendCommand(MtCommandType.ObjectSetDouble, commandParameters, namedParams); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropModifier", propModifier }, + { "PropValue", propValue } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetDouble, cmdParams); } /// @@ -2706,8 +2749,14 @@ namespace MtApi /// public bool ObjectSetInteger(long chartId, string objectName, EnumObjectPropertyInteger propId, long propValue) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propValue }; - return SendCommand(MtCommandType.ObjectSetInteger, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropValue", propValue } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetInteger, cmdParams); } /// @@ -2723,9 +2772,15 @@ namespace MtApi /// public bool ObjectSetInteger(long chartId, string objectName, EnumObjectPropertyInteger propId, int propModifier, long propValue) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propValue }; - var namedParams = new Dictionary {{nameof(propModifier), propModifier}}; - return SendCommand(MtCommandType.ObjectSetInteger, commandParameters, namedParams); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropModifier", propModifier }, + { "PropValue", propValue } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetInteger, cmdParams); } /// @@ -2740,8 +2795,14 @@ namespace MtApi /// public bool ObjectSetString(long chartId, string objectName, EnumObjectPropertyString propId, string propValue) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propValue }; - return SendCommand(MtCommandType.ObjectSetString, commandParameters); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropValue", propValue } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetString, cmdParams); } /// @@ -2757,9 +2818,15 @@ namespace MtApi /// public bool ObjectSetString(long chartId, string objectName, EnumObjectPropertyString propId, int propModifier, string propValue) { - var commandParameters = new ArrayList { chartId, objectName, (int)propId, propValue }; - var namedParams = new Dictionary {{nameof(propModifier), propModifier}}; - return SendCommand(MtCommandType.ObjectSetString, commandParameters, namedParams); + Dictionary cmdParams = new() + { + { "ChartId", chartId }, + { "ObjectName", objectName }, + { "PropId", (int)propId }, + { "PropModifier", propModifier }, + { "PropValue", propValue } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetString, cmdParams); } /// @@ -2774,8 +2841,14 @@ namespace MtApi /// public bool TextSetFont(string name, int size, FlagFontStyle flags = 0, int orientation = 0) { - var commandParameters = new ArrayList { name, size, (uint)flags, orientation }; - return SendCommand(MtCommandType.TextSetFont, commandParameters); + Dictionary cmdParams = new() + { + { "Name", name }, + { "Size", size }, + { "Flags", flags }, + { "Orientation", orientation } + }; + return SendCommand(ExecutorHandle, MtCommandType.TextSetFont, cmdParams); } /// @@ -2785,10 +2858,13 @@ namespace MtApi /// ///Object description. For objects of OBJ_TEXT and OBJ_LABEL types, the text drawn by these objects will be returned. /// - public string ObjectDescription(string objectName) + public string? ObjectDescription(string objectName) { - var commandParameters = new ArrayList { objectName }; - return SendCommand(MtCommandType.ObjectDescription, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectDescription, cmdParams); } /// @@ -2799,10 +2875,14 @@ namespace MtApi /// ///The level description of a Fibonacci object. /// - public string ObjectGetFiboDescription(string objectName, int index) + public string? ObjectGetFiboDescription(string objectName, int index) { - var commandParameters = new ArrayList { objectName, index }; - return SendCommand(MtCommandType.ObjectGetFiboDescription, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + { "Index", index } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetFiboDescription, cmdParams); } /// @@ -2815,8 +2895,12 @@ namespace MtApi /// public int ObjectGetShiftByValue(string objectName, double value) { - var commandParameters = new ArrayList { objectName, value }; - return SendCommand(MtCommandType.ObjectGetShiftByValue, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + { "Value", value } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetShiftByValue, cmdParams); } /// @@ -2829,8 +2913,12 @@ namespace MtApi /// public double ObjectGetValueByShift(string objectName, int shift) { - var commandParameters = new ArrayList { objectName, shift }; - return SendCommand(MtCommandType.ObjectGetValueByShift, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + { "Shift", shift } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectGetValueByShift, cmdParams); } /// @@ -2844,8 +2932,13 @@ namespace MtApi /// public bool ObjectSet(string objectName, int index, double value) { - var commandParameters = new ArrayList { objectName, index, value }; - return SendCommand(MtCommandType.ObjectSet, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + { "Index", index }, + { "Value", value } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSet, cmdParams); } /// @@ -2859,8 +2952,13 @@ namespace MtApi /// public bool ObjectSetFiboDescription(string objectName, int index, string text) { - var commandParameters = new ArrayList { objectName, index, text }; - return SendCommand(MtCommandType.ObjectSetFiboDescription, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + { "Index", index }, + { "Text", text } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetFiboDescription, cmdParams); } /// @@ -2874,10 +2972,17 @@ namespace MtApi /// ///Changes the object description. If the function succeeds, the returned value will be true, otherwise false. /// - public bool ObjectSetText(string objectName, string text, int fontSize = 0, string fontName = null, Color? textColor = null) + public bool ObjectSetText(string objectName, string text, int fontSize = 0, string? fontName = null, Color? textColor = null) { - var commandParameters = new ArrayList { objectName, text, fontSize, fontName, MtApiColorConverter.ConvertToMtColor(textColor) }; - return SendCommand(MtCommandType.ObjectSetText, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + { "Text", text }, + { "FontSize", fontSize }, + { "FontName", fontName ?? string.Empty }, + { "TextColor", MtApiColorConverter.ConvertToMtColor(textColor) } + }; + return SendCommand(ExecutorHandle, MtCommandType.ObjectSetText, cmdParams); } /// @@ -2889,8 +2994,11 @@ namespace MtApi /// public EnumObject ObjectType(string objectName) { - var commandParameters = new ArrayList { objectName }; - return (EnumObject)SendCommand(MtCommandType.ObjectType, commandParameters); + Dictionary cmdParams = new() + { + { "ObjectName", objectName }, + }; + return (EnumObject)SendCommand(ExecutorHandle, MtCommandType.ObjectType, cmdParams); } #endregion @@ -2899,13 +3007,13 @@ namespace MtApi public void UnlockTicks() { - SendCommand(MtCommandType.UnlockTicks, null); + SendCommand(ExecutorHandle, MtCommandType.UnlockTicks); } #endregion #region Private Methods - private MtClient Client + private MtRpcClient? Client { get { @@ -2916,7 +3024,7 @@ namespace MtApi } } - private void Connect(MtClient client) + private async Task Connect(string host, int port) { lock (_locker) { @@ -2929,259 +3037,358 @@ namespace MtApi _connectionState = MtConnectionState.Connecting; } - string message = string.IsNullOrEmpty(client.Host) ? $"Connecting to localhost:{client.Port}" : $"Connecting to {client.Host}:{client.Port}"; + string message = $"Connecting to {host}:{port}"; ConnectionStateChanged?.Invoke(this, new MtConnectionEventArgs(MtConnectionState.Connecting, message)); - var state = MtConnectionState.Failed; + var client = new MtRpcClient(host, port, new RpcClientLogger(Log)); + client.ExpertList += Client_ExpertList; + client.ExpertAdded += Client_ExpertAdded; + client.ExpertRemoved += Client_ExpertRemoved; + client.MtEventReceived += Client_MtEventReceived; + client.ConnectionFailed += Client_OnConnectionFailed; + client.Disconnected += Client_Disconnected; - lock (_locker) + try { - try - { - client.Connect(); - state = MtConnectionState.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); - } - - if (state == MtConnectionState.Connected) + await client.Connect(); + Log.Info($"Connected to {host}:{port}"); + lock (_locker) { _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); + _connectionState = MtConnectionState.Connected; } - - _connectionState = state; + client.NotifyClientReady(); + ConnectionStateChanged?.Invoke(this, new MtConnectionEventArgs(MtConnectionState.Connected, $"Connected to {host}:{port}")); } - - ConnectionStateChanged?.Invoke(this, new MtConnectionEventArgs(state, message)); - - if (state == MtConnectionState.Connected) + catch (Exception e) { - OnConnected(); - } - } - - private void Connect(string host, int port) - { - var client = new MtClient(host, port); - Connect(client); - } - - private void Connect(int port) - { - var client = new MtClient(port); - Connect(client); - } - - private void OnConnected() - { - _isBacktestingMode = IsTesting(); - if (_isBacktestingMode) - { - BacktestingReady(); + Log.Warn($"Failed connection to {host}:{port}. {e.Message}"); + lock (_locker) + { + _connectionState = MtConnectionState.Failed; + } + ConnectionStateChanged?.Invoke(this, new MtConnectionEventArgs(MtConnectionState.Failed, e.Message)); } } private void Disconnect(bool failed) { - var state = failed ? MtConnectionState.Failed : MtConnectionState.Disconnected; + var state = failed ? MtConnectionState.Failed : MtConnectionState.Disconnected; var message = failed ? "Connection Failed" : "Disconnected"; + MtRpcClient? client; + lock (_locker) { if (_connectionState == MtConnectionState.Disconnected || _connectionState == MtConnectionState.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 (!failed) - { - _client.Disconnect(); - } - - _client.Dispose(); - - _client = null; - } - _connectionState = state; + client = _client; + _client = null; + + _quotes.Clear(); + _experts.Clear(); + _executorHandle = 0; } + client?.Disconnect(); + Log.Info(message); ConnectionStateChanged?.Invoke(this, new MtConnectionEventArgs(state, message)); } - private T SendCommand(MtCommandType commandType, ArrayList commandParameters, Dictionary namedParams = null) + private T? SendCommand(int expertHandle, MtCommandType commandType, object? payload = null) { - MtResponse response; - var client = Client; if (client == null) { Log.Warn("SendCommand: No connection"); - throw new MtConnectionException("No connection"); + throw new Exception("No connection"); } - try + var payloadJson = payload == null ? string.Empty : JsonConvert.SerializeObject(payload); + Log.Debug($"SendCommand: sending '{payloadJson}' ..."); + + var responseJson = client.SendCommand(expertHandle, (int)commandType, payloadJson); + + Log.Debug($"SendCommand: received response JSON [{responseJson}]"); + + if (string.IsNullOrEmpty(responseJson)) { - response = client.SendCommand((int)commandType, commandParameters, namedParams, ExecutorHandle); - } - catch (CommunicationException ex) - { - Log.Warn($"SendCommand: {ex.Message}"); - throw new MtConnectionException(ex.Message, ex); + Log.Warn("SendCommand: Response JSON from MetaTrader is null or empty"); + throw new MtExecutionException(MtErrorCode.MtApiCustomError, "Response from MetaTrader is null"); } + var response = JsonConvert.DeserializeObject>(responseJson); if (response == null) { - Log.Warn("SendCommand: Response from MetaTrader is null"); + Log.Warn("SendCommand: Failed to deserialize response from JSON"); throw new MtExecutionException(MtErrorCode.MtApiCustomError, "Response from MetaTrader is null"); } if (response.ErrorCode != 0) { - Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}"); - throw new MtExecutionException((MtErrorCode)response.ErrorCode, response.ToString()); - } - - var responseValue = response.GetValue(); - return responseValue != null ? (T)responseValue : default(T); - } - - private T SendRequest(RequestBase request) where T : ResponseBase, new() - { - if (request == null) - return default(T); - - var serializer = JsonConvert.SerializeObject(request, Formatting.None, - new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); - var commandParameters = new ArrayList { serializer }; - - var res = SendCommand(MtCommandType.MtRequest, commandParameters); - - if (res == null) - { - Log.Warn("SendRequest: Response from MetaTrader is null"); - throw new MtExecutionException(MtErrorCode.MtApiCustomError, "Response from MetaTrader is null"); - } - - var response = JsonConvert.DeserializeObject(res); - if (response.ErrorCode != 0) - { - Log.Warn($"SendRequest: ErrorCode = {response.ErrorCode}. {response}"); + Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response.ErrorMessage}"); throw new MtExecutionException((MtErrorCode)response.ErrorCode, response.ErrorMessage); } - return response; + return (response.Value == null) ? default : response.Value; } - private void _client_QuoteUpdated(MTApiService.MtQuote quote) + private void Client_MtEventReceived(object? sender, MtEventArgs e) { - if (quote != null) - { - QuoteUpdate?.Invoke(this, new MtQuoteEventArgs(new MtQuote(quote))); - QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask); - } + Task.Run(() => _mtEventHandlers[(MtEventTypes)e.EventType](e.ExpertHandle, e.Payload)); } - private void _client_ServerDisconnected(object sender, EventArgs e) + private void Client_ExpertList(object? sender, MtExpertListEventArgs e) { - Disconnect(false); + Task.Run(() => ProcessExpertList(e.Experts)); } - private void _client_ServerFailed(object sender, EventArgs e) + private void Client_ExpertAdded(object? sender, MtExpertEventArgs e) { + Task.Run(() => ProcessExpertAdded(e.Expert)); + } + + private void Client_ExpertRemoved(object? sender, MtExpertEventArgs e) + { + Task.Run(() => ProcessExpertRemoved(e.Expert)); + } + + private void Client_OnConnectionFailed(object? sender, EventArgs e) + { + Log.Info("Received connection failed"); Disconnect(true); } - private void _client_QuoteRemoved(MTApiService.MtQuote quote) + private void Client_Disconnected(object? sender, EventArgs e) { - QuoteRemoved?.Invoke(this, new MtQuoteEventArgs(new MtQuote(quote))); + Log.Info("Received normal disconnection"); + Disconnect(false); } - private void _client_QuoteAdded(MTApiService.MtQuote quote) + private void ReceivedOnTickEvent(int expertHandle, string payload) { - QuoteAdded?.Invoke(this, new MtQuoteEventArgs(new MtQuote(quote))); - } + var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null) + return; - private void _client_MtEventReceived(MtEvent e) - { - var eventType = (MtEventTypes) e.EventType; + QuoteUpdated?.Invoke(this, e.Instrument, e.Tick.Bid, e.Tick.Ask); - switch(eventType) + MtQuote quote = new() { - case MtEventTypes.LastTimeBar: - FireOnLastTimeBar(e.ExpertHandle, JsonConvert.DeserializeObject(e.Payload)); - break; - case MtEventTypes.ChartEvent: - FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject(e.Payload)); - break; - case MtEventTypes.OnLockTicks: - FireOnLockTicks(e.ExpertHandle, JsonConvert.DeserializeObject(e.Payload)); - break; - default: - throw new ArgumentOutOfRangeException(); + Instrument = e.Instrument, + Bid = e.Tick.Bid, + Ask = e.Tick.Ask, + ExpertHandle = expertHandle + }; + QuoteUpdate?.Invoke(this, new MtQuoteEventArgs(quote)); + } + + private void ReceivedOnLastTimeBarEvent(int expertHandle, string payload) + { + var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Symbol)) + return; + OnLastTimeBar?.Invoke(this, new TimeBarArgs(expertHandle, e)); + } + + private void ReceiveOnChartEvent(int expertHandle, string payload) + { + var e = JsonConvert.DeserializeObject(payload); + if (e == null) + return; + + OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandle, e)); + } + + private void ReceivedOnLockTicksEvent(int expertHandle, string payload) + { + var e = JsonConvert.DeserializeObject(payload); + if (e == null || string.IsNullOrEmpty(e.Instrument)) + return; + OnLockTicks?.Invoke(this, new MtLockTicksEventArgs(expertHandle, e.Instrument)); + } + + private void ProcessExpertList(HashSet experts) + { + if (experts == null || experts.Count == 0) + { + Log.Warn("ProcessExpertList: expert list invalid or empty"); + return; + } + + Dictionary quotes = []; + foreach (var handle in experts) + { + var quote = GetQuote(handle); + if (quote != null) + quotes[handle] = quote; + } + + lock (_locker) + { + _experts = experts; + _quotes = quotes; + if (_executorHandle == 0) + _executorHandle = (_experts.Count > 0) ? _experts.ElementAt(0) : 0; + } + _quotesWaiter.Set(); + + QuoteList?.Invoke(this, new(quotes.Values.ToList())); + + if (IsTesting()) + { + BacktestingReady(); } } - private void FireOnLastTimeBar(int expertHandler, MtTimeBar timeBar) + private void ProcessExpertAdded(int handle) { - OnLastTimeBar?.Invoke(this, new TimeBarArgs(expertHandler, timeBar)); + Log.Debug($"ProcessExpertAdded: {handle}"); + + bool added; + lock (_locker) + { + added = _experts.Add(handle); + if (_executorHandle == 0) + _executorHandle = (_experts.Count > 0) ? _experts.ElementAt(0) : 0; + } + + if (added) + { + var quote = GetQuote(handle); + if (quote != null) + { + lock (_locker) + { + _quotes[handle] = quote; + } + + QuoteAdded?.Invoke(this, new MtQuoteEventArgs(quote)); + } + else + Log.Warn($"ProcessExpertAdded: failed to get quote for expert {handle}"); + } + else + Log.Warn($"ProcessExpertAdded: expert handle {handle} is already exist"); } - private void FireOnChartEvent(int expertHandler, MtChartEvent chartEvent) + private void ProcessExpertRemoved(int handle) { - OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent)); + Log.Debug($"ProcessExpertRemoved: {handle}"); + + MtQuote? quote = null; + lock (_locker) + { + _experts.Remove(handle); + if (_quotes.TryGetValue(handle, out quote)) + _quotes.Remove(handle); + if (_executorHandle == handle) + _executorHandle = (_experts.Count > 0) ? _experts.ElementAt(0) : 0; + } + + if (quote != null) + QuoteRemoved?.Invoke(this, new MtQuoteEventArgs(quote)); } - private void FireOnLockTicks(int expertHandler, OnLockTicksEvent lockTicksEvent) + private MtQuote? GetQuote(int expertHandle) { - OnLockTicks?.Invoke(this, new MtLockTicksEventArgs(expertHandler, lockTicksEvent.Instrument)); + Log.Debug($"GetQuote: expertHandle = {expertHandle}"); + + var e = SendCommand(expertHandle, MtCommandType.GetQuote); + if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null) + return null; + + MtQuote quote = new() + { + Instrument = e.Instrument, + Bid = e.Tick.Bid, + Ask = e.Tick.Ask, + ExpertHandle = expertHandle, + }; + + return quote; } private void BacktestingReady() { - SendCommand(MtCommandType.BacktestingReady, null); + SendCommand(ExecutorHandle, MtCommandType.BacktestingReady); } #endregion #region Events - public event MtApiQuoteHandler QuoteUpdated; - public event EventHandler QuoteUpdate; - public event EventHandler QuoteAdded; - public event EventHandler QuoteRemoved; - public event EventHandler ConnectionStateChanged; - public event EventHandler OnLastTimeBar; - public event EventHandler OnChartEvent; - public event EventHandler OnLockTicks; + public event MtApiQuoteHandler? QuoteUpdated; + public event EventHandler? QuoteUpdate; + public event EventHandler? QuoteAdded; + public event EventHandler? QuoteRemoved; + public event EventHandler? ConnectionStateChanged; + public event EventHandler? OnLastTimeBar; + public event EventHandler? OnChartEvent; + public event EventHandler? OnLockTicks; + public event EventHandler? QuoteList; #endregion } + + internal enum ParametersType + { + Int = 0, + Double = 1, + String = 2, + Boolean = 3 + } + + internal class RpcClientLogger(IMtLogger logger) : IRpcLogger + { + public void Debug(string message) + { + logger_.Debug(message); + } + + public void Error(string message) + { + logger_.Debug(message); + } + + public void Info(string message) + { + logger_.Debug(message); + } + + public void Warn(string message) + { + logger_.Debug(message); + } + + private readonly IMtLogger logger_ = logger; + } + + internal class StubMtLogger : IMtLogger + { + public void Debug(object message) + { + } + + public void Error(object message) + { + } + + public void Fatal(object message) + { + } + + public void Info(object message) + { + } + + public void Warn(object message) + { + } + } } diff --git a/MtApi/MtApiColorConverter.cs b/MtApi/MtApiColorConverter.cs index 9ae859f8..f27d6e72 100755 --- a/MtApi/MtApiColorConverter.cs +++ b/MtApi/MtApiColorConverter.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; +using System.Drawing; namespace MtApi { diff --git a/MtApi/MtApiTimeConverter.cs b/MtApi/MtApiTimeConverter.cs index 8f35ccb2..1509172e 100755 --- a/MtApi/MtApiTimeConverter.cs +++ b/MtApi/MtApiTimeConverter.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { class MtApiTimeConverter { public static DateTime ConvertFromMtTime(int time) { - DateTime tmpTime = new DateTime(1970, 1, 1); + DateTime tmpTime = new(1970, 1, 1); return new DateTime(tmpTime.Ticks + (time * 0x989680L)); } @@ -18,7 +13,7 @@ namespace MtApi int result = 0; if (time != null && time != DateTime.MinValue) { - DateTime tmpTime = new DateTime(1970, 1, 1); + DateTime tmpTime = new(1970, 1, 1); result = (int)((time.Value.Ticks - tmpTime.Ticks) / 0x989680L); } return result; diff --git a/MtApi/MtCommandType.cs b/MtApi/MtCommandType.cs index 9697dcb0..0c9c3a6f 100644 --- a/MtApi/MtCommandType.cs +++ b/MtApi/MtCommandType.cs @@ -5,13 +5,11 @@ //NoCommand = 0 //trade operations -// OrderSend = 1, -// OrderSendBuy = 1001, -// OrderSendSell = 1002, -// OrderClose = 2, + OrderSend = 1, + OrderClose = 2, // OrderCloseByCurrentPrice = 152, -// OrderCloseBy = 3, + OrderCloseBy = 3, OrderClosePrice = 4, OrderClosePriceByTicket = 1004, OrderCloseTime = 5, @@ -136,7 +134,7 @@ iBullsPower = 106, iCCI = 107, iCCIOnArray = 108, - //iCustom = 109, + iCustom = 109, //iCustom_d = 10109, iDeMarker = 110, iEnvelopes = 111, @@ -278,6 +276,17 @@ WindowXOnDropped = 278, WindowYOnDropped = 279, - ChangeAccount = 280 + ChangeAccount = 280, + + GetOrder = 282, + GetOrders = 283, + CopyRates = 284, + Session = 285, + SeriesInfoInteger = 286, + SeriesInfoString = 287, + SymbolInfoTick = 288, + SymbolInfoDouble = 289, + + GetQuote = 290 } } diff --git a/MtApi/MtConnectionEventArgs.cs b/MtApi/MtConnectionEventArgs.cs index 9254d774..e148a4ef 100755 --- a/MtApi/MtConnectionEventArgs.cs +++ b/MtApi/MtConnectionEventArgs.cs @@ -1,16 +1,8 @@ -using System; - -namespace MtApi +namespace MtApi { - public class MtConnectionEventArgs: EventArgs + public class MtConnectionEventArgs(MtConnectionState status, string message) : EventArgs { - public MtConnectionState Status { get; private set; } - public string ConnectionMessage { get; private set; } - - public MtConnectionEventArgs(MtConnectionState status, string message) - { - Status = status; - ConnectionMessage = message; - } + public MtConnectionState Status { get; private set; } = status; + public string ConnectionMessage { get; private set; } = message; } } diff --git a/MtApi/MtConnectionException.cs b/MtApi/MtConnectionException.cs index 3f705707..fcb43fd3 100644 --- a/MtApi/MtConnectionException.cs +++ b/MtApi/MtConnectionException.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi +namespace MtApi { public class MtConnectionException: Exception { @@ -9,12 +7,12 @@ namespace MtApi { } - public MtConnectionException(string message) + public MtConnectionException(string? message) : this(message, null) { } - public MtConnectionException(string message, Exception exception) + public MtConnectionException(string? message, Exception? exception) : base(message, exception) { } diff --git a/MtApi/MtConnectionState.cs b/MtApi/MtConnectionState.cs index a1655c2d..a71e13b0 100755 --- a/MtApi/MtConnectionState.cs +++ b/MtApi/MtConnectionState.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { public enum MtConnectionState { diff --git a/MtApi/MtExecutionException.cs b/MtApi/MtExecutionException.cs index af294354..0a7ca38a 100644 --- a/MtApi/MtExecutionException.cs +++ b/MtApi/MtExecutionException.cs @@ -1,15 +1,7 @@ -using System; - -namespace MtApi +namespace MtApi { - public class MtExecutionException: Exception + public class MtExecutionException(MtErrorCode errorCode, string? message) : Exception(message) { - public MtExecutionException(MtErrorCode errorCode, string message) - :base(message) - { - ErrorCode = errorCode; - } - - public MtErrorCode ErrorCode { get; private set; } + public MtErrorCode ErrorCode { get; private set; } = errorCode; } } \ No newline at end of file diff --git a/MtApi/MtLockTicksEventArgs.cs b/MtApi/MtLockTicksEventArgs.cs index 9c5dfef5..4d24f986 100644 --- a/MtApi/MtLockTicksEventArgs.cs +++ b/MtApi/MtLockTicksEventArgs.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi +namespace MtApi { public class MtLockTicksEventArgs : EventArgs { diff --git a/MtApi/MtOrder.cs b/MtApi/MtOrder.cs index a9854b7a..68b25142 100644 --- a/MtApi/MtOrder.cs +++ b/MtApi/MtOrder.cs @@ -1,11 +1,9 @@ -using System; - -namespace MtApi +namespace MtApi { public class MtOrder { public int Ticket { get; set; } - public string Symbol { get; set; } + public string Symbol { get; set; } = string.Empty; public TradeOperation Operation { get; set; } public double OpenPrice { get; set; } public double ClosePrice { get; set; } @@ -13,7 +11,7 @@ namespace MtApi public int MtOpenTime { get; set; } public int MtCloseTime { get; set; } public double Profit { get; set; } - public string Comment { get; set; } + public string Comment { get; set; } = string.Empty; public double Commission { get; set; } public int MagicNumber { get; set; } public double Swap { get; set; } diff --git a/MtApi/MtProtocol/FuncResult.cs b/MtApi/MtProtocol/FuncResult.cs new file mode 100755 index 00000000..eb79ef1d --- /dev/null +++ b/MtApi/MtProtocol/FuncResult.cs @@ -0,0 +1,8 @@ +namespace MtApi.MtProtocol +{ + internal class FuncResult + { + public bool RetVal { get; set; } + public T? Result { get; set; } + } +} diff --git a/MtApi/MtProtocol/ICustomRequest.cs b/MtApi/MtProtocol/ICustomRequest.cs new file mode 100755 index 00000000..673944a0 --- /dev/null +++ b/MtApi/MtProtocol/ICustomRequest.cs @@ -0,0 +1,13 @@ +namespace MtApi.MtProtocol +{ + namespace ICustomRequest + { + public enum ParametersType + { + Int = 0, + Double = 1, + String = 2, + Boolean = 3 + } + } +} diff --git a/MtApi/MtProtocol/MqlTick.cs b/MtApi/MtProtocol/MqlTick.cs new file mode 100755 index 00000000..f00db89f --- /dev/null +++ b/MtApi/MtProtocol/MqlTick.cs @@ -0,0 +1,12 @@ +namespace MtApi.MtProtocol +{ + public class MtTick + { + public double Bid { get; set; } // Current Bid price + public double Ask { get; set; } // Current Ask price + public long Time { get; set; } // Time of the last prices update + public double Last { get; set; } // Price of the last deal (Last) + public ulong Volume { get; set; } // Volume for the current Last price + public double VolumeReal { get; set; } // Volume for the current Last price with greater accuracy + } +} \ No newline at end of file diff --git a/MtApi/MtProtocol/MtRpcQuote.cs b/MtApi/MtProtocol/MtRpcQuote.cs new file mode 100755 index 00000000..821a4775 --- /dev/null +++ b/MtApi/MtProtocol/MtRpcQuote.cs @@ -0,0 +1,9 @@ +namespace MtApi.MtProtocol +{ + internal class MtRpcQuote + { + public MtTick? Tick { get; set; } + public string? Instrument { get; set; } + public int ExpertHandle { get; set; } + } +} \ No newline at end of file diff --git a/MtApi/MtProtocol/Response.cs b/MtApi/MtProtocol/Response.cs new file mode 100755 index 00000000..dc87663c --- /dev/null +++ b/MtApi/MtProtocol/Response.cs @@ -0,0 +1,10 @@ +namespace MtApi.MtProtocol +{ + internal class Response + { + public int ErrorCode { get; set; } + public string? ErrorMessage { get; set; } + + public T? Value { get; set; } + } +} \ No newline at end of file diff --git a/MtApi/MtQuote.cs b/MtApi/MtQuote.cs index 0d61c489..fc70d0c2 100755 --- a/MtApi/MtQuote.cs +++ b/MtApi/MtQuote.cs @@ -2,10 +2,10 @@ { public class MtQuote { - public string Instrument { get; private set; } - public double Bid { get; private set; } - public double Ask { get; private set; } - public int ExpertHandle { get; private set; } + public string Instrument { get; set; } = string.Empty; + public double Bid { get; set; } + public double Ask { get; set; } + public int ExpertHandle { get; set; } public MtQuote(string instrument, double bid, double ask) { @@ -14,12 +14,9 @@ Ask = ask; } - internal MtQuote(MTApiService.MtQuote quote) + public MtQuote() { - Instrument = quote.Instrument; - Bid = quote.Bid; - Ask = quote.Ask; - ExpertHandle = quote.ExpertHandle; + } } } diff --git a/MtApi/MtQuoteEventArgs.cs b/MtApi/MtQuoteEventArgs.cs index 1f78edaa..e6a65860 100755 --- a/MtApi/MtQuoteEventArgs.cs +++ b/MtApi/MtQuoteEventArgs.cs @@ -1,14 +1,7 @@ -using System; - -namespace MtApi +namespace MtApi { - public class MtQuoteEventArgs : EventArgs + public class MtQuoteEventArgs(MtQuote quote) : EventArgs { - public MtQuote Quote { get; private set; } - - public MtQuoteEventArgs(MtQuote quote) - { - Quote = quote; - } + public MtQuote Quote { get; private set; } = quote; } } diff --git a/MtApi/MtQuotesEventArgs.cs b/MtApi/MtQuotesEventArgs.cs new file mode 100755 index 00000000..2849151f --- /dev/null +++ b/MtApi/MtQuotesEventArgs.cs @@ -0,0 +1,8 @@ +namespace MtApi +{ + public class MtQuotesEventArgs(IEnumerable quotes) : EventArgs + { + public IEnumerable Quotes { get; } = quotes; + + } +} diff --git a/MtApi/MtSession.cs b/MtApi/MtSession.cs index d8a99791..0a31e4f1 100644 --- a/MtApi/MtSession.cs +++ b/MtApi/MtSession.cs @@ -1,10 +1,8 @@ -using System; - -namespace MtApi +namespace MtApi { public class MtSession { - public string Symbol { get; set; } + public string? Symbol { get; set; } public DayOfWeek DayOfWeek { get; set; } public uint Index { get; set; } public int MtFromTime { get; set; } diff --git a/MtApi/MtTimeBar.cs b/MtApi/MtTimeBar.cs index 5cb01da4..1c0d5440 100644 --- a/MtApi/MtTimeBar.cs +++ b/MtApi/MtTimeBar.cs @@ -1,10 +1,8 @@ -using System; - -namespace MtApi +namespace MtApi { public class MtTimeBar { - public string Symbol { get; set; } + public string Symbol { get; set; } = string.Empty; public int MtOpenTime { get; set; } public int MtCloseTime { get; set; } public double Open { get; set; } diff --git a/MtApi/MtTypes.cs b/MtApi/MtTypes.cs index 81b18a47..ff48f41b 100755 --- a/MtApi/MtTypes.cs +++ b/MtApi/MtTypes.cs @@ -1,6 +1,4 @@ -// ReSharper disable InconsistentNaming - -namespace MtApi +namespace MtApi { public enum ENUM_TERMINAL_INFO_STRING { diff --git a/MtApi/OrderSelectMode.cs b/MtApi/OrderSelectMode.cs index c1dca986..62f203ee 100755 --- a/MtApi/OrderSelectMode.cs +++ b/MtApi/OrderSelectMode.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { public enum OrderSelectMode { diff --git a/MtApi/OrderSelectSource.cs b/MtApi/OrderSelectSource.cs index 533b0053..1d83ca0f 100755 --- a/MtApi/OrderSelectSource.cs +++ b/MtApi/OrderSelectSource.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { public enum OrderSelectSource { diff --git a/MtApi/PriceConstantsType.cs b/MtApi/PriceConstantsType.cs index 2efe87c9..d828febd 100755 --- a/MtApi/PriceConstantsType.cs +++ b/MtApi/PriceConstantsType.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { public enum PriceConstantsType { diff --git a/MtApi/Properties/AssemblyInfo.cs b/MtApi/Properties/AssemblyInfo.cs deleted file mode 100644 index 0bd04aac..00000000 --- a/MtApi/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("MtApi")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("DW")] -[assembly: AssemblyProduct("MtApi")] -[assembly: AssemblyCopyright("Copyright © DW 2011")] -[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("650e3c56-dbce-45d4-a844-94bbe9f9a3bf")] - -// 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.43.0")] -[assembly: AssemblyFileVersion("1.0.43.0")] \ No newline at end of file diff --git a/MtApi/Requests/CopyRatesRequest.cs b/MtApi/Requests/CopyRatesRequest.cs deleted file mode 100644 index a45c77a8..00000000 --- a/MtApi/Requests/CopyRatesRequest.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace MtApi.Requests -{ - internal abstract class CopyRatesRequestBase : RequestBase - { - public enum CopyRatesTypeEnum - { - CopyRates_1 = 1, - CopyRates_2 = 2, - CopyRates_3 = 3, - } - - public override RequestType RequestType => RequestType.CopyRates; - - public abstract CopyRatesTypeEnum CopyRatesType { get; } - - public string SymbolName { get; set; } - public ENUM_TIMEFRAMES Timeframe { get; set; } - } - - internal class CopyRates1Request : CopyRatesRequestBase - { - public override CopyRatesTypeEnum CopyRatesType => CopyRatesTypeEnum.CopyRates_1; - - public int StartPos { get; set; } - public int Count { get; set; } - } - - internal class CopyRates2Request : CopyRatesRequestBase - { - public override CopyRatesTypeEnum CopyRatesType => CopyRatesTypeEnum.CopyRates_2; - - public int StartTime { get; set; } - public int Count { get; set; } - } - - internal class CopyRates3Request : CopyRatesRequestBase - { - public override CopyRatesTypeEnum CopyRatesType => CopyRatesTypeEnum.CopyRates_3; - - public int StartTime { get; set; } - public int StopTime { get; set; } - } -} diff --git a/MtApi/Requests/GetOrderRequest.cs b/MtApi/Requests/GetOrderRequest.cs deleted file mode 100755 index 01cb77de..00000000 --- a/MtApi/Requests/GetOrderRequest.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MtApi.Requests -{ - internal class GetOrderRequest: RequestBase - { - public int Index { get; set; } - public int Select { get; set; } - public int Pool { get; set; } - - public override RequestType RequestType => RequestType.GetOrder; - } -} \ No newline at end of file diff --git a/MtApi/Requests/GetOrdersRequest.cs b/MtApi/Requests/GetOrdersRequest.cs deleted file mode 100755 index 8166c907..00000000 --- a/MtApi/Requests/GetOrdersRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MtApi.Requests -{ - internal class GetOrdersRequest: RequestBase - { - public int Pool { get; set; } - - public override RequestType RequestType => RequestType.GetOrders; - } -} \ No newline at end of file diff --git a/MtApi/Requests/ICustomRequest.cs b/MtApi/Requests/ICustomRequest.cs deleted file mode 100755 index c70ba300..00000000 --- a/MtApi/Requests/ICustomRequest.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections; - -namespace MtApi.Requests -{ - internal class ICustomRequest : RequestBase - { - public enum ParametersType - { - Int = 0, - Double = 1, - String = 2, - Boolean = 3 - } - - public string Symbol { get; set; } - public int Timeframe { get; set; } - public string Name { get; set; } - public int Mode { get; set; } - public int Shift { get; set; } - public ArrayList Params { get; set; } - public ParametersType ParamsType { get; set; } - - public override RequestType RequestType => RequestType.iCustom; - } -} diff --git a/MtApi/Requests/OrderCloseByRequest.cs b/MtApi/Requests/OrderCloseByRequest.cs deleted file mode 100755 index 30d4e04b..00000000 --- a/MtApi/Requests/OrderCloseByRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace MtApi.Requests -{ - internal class OrderCloseByRequest: RequestBase - { - public int Ticket { get; set; } - public int Opposite { get; set; } - - public int? ArrowColor { get; set; } - - public override RequestType RequestType => RequestType.OrderCloseBy; - } -} \ No newline at end of file diff --git a/MtApi/Requests/OrderCloseRequest.cs b/MtApi/Requests/OrderCloseRequest.cs deleted file mode 100755 index 8874a45e..00000000 --- a/MtApi/Requests/OrderCloseRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace MtApi.Requests -{ - internal class OrderCloseRequest: RequestBase - { - public int Ticket { get; set; } - - public double? Lots { get; set; } - public double? Price { get; set; } - public int? Slippage { get; set; } - public int? ArrowColor { get; set; } - - public override RequestType RequestType => RequestType.OrderClose; - } -} \ No newline at end of file diff --git a/MtApi/Requests/OrderDeleteRequest.cs b/MtApi/Requests/OrderDeleteRequest.cs deleted file mode 100755 index c02076fb..00000000 --- a/MtApi/Requests/OrderDeleteRequest.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MtApi.Requests -{ - internal class OrderDeleteRequest: RequestBase - { - public int Ticket { get; set; } - - public int? ArrowColor { get; set; } - - public override RequestType RequestType => RequestType.OrderDelete; - } -} \ No newline at end of file diff --git a/MtApi/Requests/OrderModifyRequest.cs b/MtApi/Requests/OrderModifyRequest.cs deleted file mode 100755 index 91d6ae59..00000000 --- a/MtApi/Requests/OrderModifyRequest.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace MtApi.Requests -{ - internal class OrderModifyRequest: RequestBase - { - public int Ticket { get; set; } - public double Price { get; set; } - public double Stoploss { get; set; } - public double Takeprofit { get; set; } - public int Expiration { get; set; } - - public int? ArrowColor { get; set; } - - public override RequestType RequestType => RequestType.OrderModify; - } -} \ No newline at end of file diff --git a/MtApi/Requests/OrderSendRequest.cs b/MtApi/Requests/OrderSendRequest.cs deleted file mode 100755 index 331302a3..00000000 --- a/MtApi/Requests/OrderSendRequest.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace MtApi.Requests -{ - internal class OrderSendRequest: RequestBase - { - public string Symbol { get; set; } - public int Cmd { get; set; } - public double Volume { get; set; } - - public double? Price { get; set; } - public int? Slippage { get; set; } - public double? Stoploss { get; set; } - public double? Takeprofit { get; set; } - public string Comment { get; set; } - public int? Magic { get; set; } - public int? Expiration { get; set; } - public int? ArrowColor { get; set; } - - public override RequestType RequestType => RequestType.OrderSend; - } -} \ No newline at end of file diff --git a/MtApi/Requests/RequestBase.cs b/MtApi/Requests/RequestBase.cs deleted file mode 100644 index 28988500..00000000 --- a/MtApi/Requests/RequestBase.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Requests -{ - internal abstract class RequestBase - { - public abstract RequestType RequestType { get; } - } -} diff --git a/MtApi/Requests/RequestType.cs b/MtApi/Requests/RequestType.cs deleted file mode 100644 index 38a9d2ae..00000000 --- a/MtApi/Requests/RequestType.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace MtApi.Requests -{ - internal enum RequestType - { - Unknown = 0, - GetOrder = 1, - GetOrders = 2, - OrderSend = 3, - OrderClose = 4, - OrderCloseBy = 5, - OrderDelete = 6, - OrderModify = 7, - iCustom = 8, - CopyRates = 9, - Session = 10, - SeriesInfoInteger = 11, - SymbolInfoDouble = 12, - SymbolInfoTick = 13 - } -} \ No newline at end of file diff --git a/MtApi/Requests/SeriesInfoIntegerRequest.cs b/MtApi/Requests/SeriesInfoIntegerRequest.cs deleted file mode 100755 index 72df77fb..00000000 --- a/MtApi/Requests/SeriesInfoIntegerRequest.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MtApi.Requests -{ - internal class SeriesInfoIntegerRequest: RequestBase - { - public override RequestType RequestType => RequestType.SeriesInfoInteger; - - public string SymbolName { get; set; } - public int Timeframe { get; set; } - public int PropId { get; set; } - } -} diff --git a/MtApi/Requests/SessionRequest.cs b/MtApi/Requests/SessionRequest.cs deleted file mode 100644 index a0da423b..00000000 --- a/MtApi/Requests/SessionRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace MtApi.Requests -{ - internal class SessionRequest : RequestBase - { - public string Symbol { get; set; } - public DayOfWeek DayOfWeek { get; set; } - public int SessionIndex { get; set; } - public SessionType SessionType { get; set; } - - public override RequestType RequestType => RequestType.Session; - } -} \ No newline at end of file diff --git a/MtApi/Requests/SymbolInfoDoubleRequest.cs b/MtApi/Requests/SymbolInfoDoubleRequest.cs deleted file mode 100755 index bf29e24d..00000000 --- a/MtApi/Requests/SymbolInfoDoubleRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace MtApi.Requests -{ - internal class SymbolInfoDoubleRequest : RequestBase - { - public override RequestType RequestType => RequestType.SymbolInfoDouble; - - public string SymbolName { get; set; } - public int PropId { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Requests/SymbolInfoTickRequest.cs b/MtApi/Requests/SymbolInfoTickRequest.cs deleted file mode 100755 index 2e01e95c..00000000 --- a/MtApi/Requests/SymbolInfoTickRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MtApi.Requests -{ - internal class SymbolInfoTickRequest: RequestBase - { - public override RequestType RequestType => RequestType.SymbolInfoTick; - - public string Symbol { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Responses/CopyRatesResponse.cs b/MtApi/Responses/CopyRatesResponse.cs deleted file mode 100644 index 2f303486..00000000 --- a/MtApi/Responses/CopyRatesResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace MtApi.Responses -{ - internal class CopyRatesResponse: ResponseBase - { - public List Rates { get; set; } - } -} diff --git a/MtApi/Responses/GetOrderResponse.cs b/MtApi/Responses/GetOrderResponse.cs deleted file mode 100755 index 84c7d4d3..00000000 --- a/MtApi/Responses/GetOrderResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class GetOrderResponse: ResponseBase - { - public MtOrder Order { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Responses/GetOrdersResponse.cs b/MtApi/Responses/GetOrdersResponse.cs deleted file mode 100755 index ce89e563..00000000 --- a/MtApi/Responses/GetOrdersResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace MtApi.Responses -{ - internal class GetOrdersResponse: ResponseBase - { - public List Orders { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Responses/ICustomResponse.cs b/MtApi/Responses/ICustomResponse.cs deleted file mode 100755 index bb42b0d9..00000000 --- a/MtApi/Responses/ICustomResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class ICustomResponse: ResponseBase - { - public double Value { get; set; } - } -} diff --git a/MtApi/Responses/OrderSendResponse.cs b/MtApi/Responses/OrderSendResponse.cs deleted file mode 100755 index b74f17e3..00000000 --- a/MtApi/Responses/OrderSendResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class OrderSendResponse: ResponseBase - { - public int Ticket { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Responses/ResponseBase.cs b/MtApi/Responses/ResponseBase.cs deleted file mode 100755 index 85a5224a..00000000 --- a/MtApi/Responses/ResponseBase.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace MtApi.Responses -{ - internal class ResponseBase - { - public int ErrorCode { get; set; } - public string ErrorMessage { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Responses/SeriesInfoIntegerResponse.cs b/MtApi/Responses/SeriesInfoIntegerResponse.cs deleted file mode 100755 index 542c0f67..00000000 --- a/MtApi/Responses/SeriesInfoIntegerResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class SeriesInfoIntegerResponse: ResponseBase - { - public long Value { get; set; } - } -} diff --git a/MtApi/Responses/SessionResponse.cs b/MtApi/Responses/SessionResponse.cs deleted file mode 100644 index 53333b8d..00000000 --- a/MtApi/Responses/SessionResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class SessionResponse : ResponseBase - { - public MtSession Session { get; set; } - } -} diff --git a/MtApi/Responses/SymbolInfoDoubleResponse.cs b/MtApi/Responses/SymbolInfoDoubleResponse.cs deleted file mode 100755 index efe27b62..00000000 --- a/MtApi/Responses/SymbolInfoDoubleResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class SymbolInfoDoubleResponse: ResponseBase - { - public double Value { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/Responses/SymbolInfoTickResponse.cs b/MtApi/Responses/SymbolInfoTickResponse.cs deleted file mode 100755 index e22af346..00000000 --- a/MtApi/Responses/SymbolInfoTickResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MtApi.Responses -{ - internal class SymbolInfoTickResponse: ResponseBase - { - public MqlTick Tick { get; set; } - } -} \ No newline at end of file diff --git a/MtApi/SeriesIdentifier.cs b/MtApi/SeriesIdentifier.cs index 849c99d0..26c8f7bb 100755 --- a/MtApi/SeriesIdentifier.cs +++ b/MtApi/SeriesIdentifier.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { public enum SeriesIdentifier { diff --git a/MtApi/TimeBarArgs.cs b/MtApi/TimeBarArgs.cs index 93ddad01..f20dbe36 100644 --- a/MtApi/TimeBarArgs.cs +++ b/MtApi/TimeBarArgs.cs @@ -1,6 +1,4 @@ -using System; - -namespace MtApi +namespace MtApi { public class TimeBarArgs: EventArgs { diff --git a/MtApi/packages.config b/MtApi/packages.config old mode 100644 new mode 100755 diff --git a/MtApiInstaller/CustomActions.wxs b/MtApiInstaller/CustomActions.wxs index 9b80d889..8349c440 100644 --- a/MtApiInstaller/CustomActions.wxs +++ b/MtApiInstaller/CustomActions.wxs @@ -1,13 +1,7 @@ - - + + - - - - - - + \ No newline at end of file diff --git a/MtApiInstaller/MtApiInstaller.wixproj b/MtApiInstaller/MtApiInstaller.wixproj index cc59a57a..52fc2a17 100755 --- a/MtApiInstaller/MtApiInstaller.wixproj +++ b/MtApiInstaller/MtApiInstaller.wixproj @@ -1,52 +1,16 @@ - - + - Debug - x86 3.6 - {78b94552-db17-40ec-b7c6-23d32db85dc1} - 2.0 - MtApiInstaller - Package - $(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets - $(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets + true ..\build\installers\$(Configuration)\ - obj\$(Configuration)\ Debug ..\build\installers\$(Configuration)\ - obj\$(Configuration)\ - - + - - - $(WixExtDir)\WixUIExtension.dll - WixUIExtension - - - - - MtApiSetupActions - {10800f37-f71b-4818-8351-8cf744295f80} - True - True - Binaries;Content;Satellites - INSTALLFOLDER - - - - \ No newline at end of file diff --git a/MtApiInstaller/Product.wxs b/MtApiInstaller/Product.wxs index 1eccf69d..08a022ce 100755 --- a/MtApiInstaller/Product.wxs +++ b/MtApiInstaller/Product.wxs @@ -1,17 +1,12 @@ - - + - + + - - + + @@ -19,105 +14,86 @@ - + - + - INSTALLFOLDER + - + - NOT Installed + + - + - - + - - - - + - - + + - + - + - - + - + - - + + - + + + - + - + - - - + + + - - - - + + + + - - - - - + diff --git a/MtApiSetupActions/CustomAction.cs b/MtApiSetupActions/CustomAction.cs index 1da80fb1..a1a3d9f0 100644 --- a/MtApiSetupActions/CustomAction.cs +++ b/MtApiSetupActions/CustomAction.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Windows.Forms; -using Microsoft.Deployment.WindowsInstaller; +using WixToolset.Dtf.WindowsInstaller; namespace MtApiSetupActions { @@ -20,38 +15,40 @@ namespace MtApiSetupActions { session.Log("Begin action InstallEx4File..."); - var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + //Directory.CreateDirectory("c:\\dw"); - var metaquotesFolder = appDataFolder + TerminalFolder; + //var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - if (Directory.Exists(metaquotesFolder)) - { - var foldersFound = Directory.GetDirectories(metaquotesFolder, Mql4Folder, SearchOption.AllDirectories); - Console.WriteLine(string.Join("\n", foldersFound)); + //var metaquotesFolder = appDataFolder + TerminalFolder; - foreach (var folder in foldersFound) - { - var srcFile = session[InstalledExpertFolderProperty] + MtApiFile; - var destFile = folder + DestinationExpertFolder + MtApiFile; + //if (Directory.Exists(metaquotesFolder)) + //{ + // var foldersFound = Directory.GetDirectories(metaquotesFolder, Mql4Folder, SearchOption.AllDirectories); + // Console.WriteLine(string.Join("\n", foldersFound)); - session.Log(string.Format("Try to copy from {0} to {1}", srcFile, destFile)); + // foreach (var folder in foldersFound) + // { + // var srcFile = session[InstalledExpertFolderProperty] + MtApiFile; + // var destFile = folder + DestinationExpertFolder + MtApiFile; - try - { - File.Copy(srcFile, destFile, true); - } - catch (Exception e) - { - session.Log(string.Format("Failed to copy MtApi4.ex4. {0}", e.Message)); - } + // session.Log(string.Format("Try to copy from {0} to {1}", srcFile, destFile)); - session.Log(string.Format("MtApi.ex4 has been coppied to {0}", destFile)); - } - } - else - { - session.Log("MetaTrader is not installed"); - } + // try + // { + // File.Copy(srcFile, destFile, true); + // } + // catch (Exception e) + // { + // session.Log(string.Format("Failed to copy MtApi4.ex4. {0}", e.Message)); + // } + + // session.Log(string.Format("MtApi.ex4 has been coppied to {0}", destFile)); + // } + //} + //else + //{ + // session.Log("MetaTrader is not installed"); + //} return ActionResult.Success; } diff --git a/MtApiSetupActions/MtApiSetupActions.csproj b/MtApiSetupActions/MtApiSetupActions.csproj index 7f4f472a..61ade67d 100644 --- a/MtApiSetupActions/MtApiSetupActions.csproj +++ b/MtApiSetupActions/MtApiSetupActions.csproj @@ -1,52 +1,12 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {10800F37-F71B-4818-8351-8CF744295F80} - Library - Properties - MtApiSetupActions - MtApiSetupActions - v4.5 - 512 - $(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.CA.targets - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - True - - - - - - - - - + + + net8.0 + enable + enable + $(SolutionDir)build\products + true + + + + \ No newline at end of file diff --git a/MtApiSetupActions/Properties/AssemblyInfo.cs b/MtApiSetupActions/Properties/AssemblyInfo.cs deleted file mode 100644 index 0de156f6..00000000 --- a/MtApiSetupActions/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +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("MtApiSetupActions")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MtApiSetupActions")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[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("c0ee9849-c0cd-4f67-8423-fe334565b863")] - -// 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.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MtClient/MtRpcClient.cs b/MtClient/MtRpcClient.cs index 1239fb80..a83e5845 100755 --- a/MtClient/MtRpcClient.cs +++ b/MtClient/MtRpcClient.cs @@ -1,4 +1,5 @@ -using System.Net.WebSockets; +using System.Diagnostics; +using System.Net.WebSockets; using System.Text; namespace MtClient @@ -137,22 +138,58 @@ namespace MtClient { try { - byte[] recvBuffer = new byte[64 * 1024]; - while (ws_.State == WebSocketState.Open) + using (var ms = new MemoryStream()) { - var result = await ws_.ReceiveAsync(new ArraySegment(recvBuffer), CancellationToken.None); - if (result.MessageType == WebSocketMessageType.Close) + var messageBuffer = WebSocket.CreateClientBuffer(1024, 64); + while (ws_.State == WebSocketState.Open) { - logger_.Info($"MtRpcClient.DoReceive: close signal {result.CloseStatusDescription}"); - Disconnected?.Invoke(this, EventArgs.Empty); - break; - } - else - { - var msg = Encoding.ASCII.GetString(recvBuffer, 0, result.Count); - OnReceive(msg); + int recvCount = 0; + WebSocketReceiveResult result; + do + { + result = await ws_.ReceiveAsync(messageBuffer, CancellationToken.None); + var byteArray = messageBuffer.Array; + if (byteArray != null) + { + ms.Write(byteArray, messageBuffer.Offset, result.Count); + recvCount += result.Count; + } + } + while (!result.EndOfMessage); + + if (result.MessageType == WebSocketMessageType.Close) + { + logger_.Info($"MtRpcClient.DoReceive: close signal {result.CloseStatusDescription}"); + Disconnected?.Invoke(this, EventArgs.Empty); + break; + } + else if (result.MessageType == WebSocketMessageType.Text) + { + var msg = Encoding.UTF8.GetString(ms.ToArray(), 0, recvCount); + //var msg = Encoding.ASCII.GetString(recvBuffer, 0, result.Count); + OnReceive(msg); + } + ms.Seek(0, SeekOrigin.Begin); + ms.Position = 0; } } + + //byte[] recvBuffer = new byte[64 * 1024]; + //while (ws_.State == WebSocketState.Open) + //{ + // var result = await ws_.ReceiveAsync(new ArraySegment(recvBuffer), CancellationToken.None); + // if (result.MessageType == WebSocketMessageType.Close) + // { + // logger_.Info($"MtRpcClient.DoReceive: close signal {result.CloseStatusDescription}"); + // Disconnected?.Invoke(this, EventArgs.Empty); + // break; + // } + // else + // { + // var msg = Encoding.ASCII.GetString(recvBuffer, 0, result.Count); + // OnReceive(msg); + // } + //} } catch (Exception ex) { diff --git a/MtService/MtService.vcxproj b/MtService/MtService.vcxproj index 96272c3b..589d4582 100755 --- a/MtService/MtService.vcxproj +++ b/MtService/MtService.vcxproj @@ -70,6 +70,18 @@ + + $(SolutionDir)\build\products\$(Configuration)\$(Platform)\ + + + $(SolutionDir)\build\products\$(Configuration)\x86\ + + + $(SolutionDir)\build\products\$(Configuration)\$(Platform)\ + + + $(SolutionDir)\build\products\$(Configuration)\x86\ + Level3 @@ -78,6 +90,7 @@ true Use pch.h + $(SolutionDir)thirdparty\include;%(AdditionalIncludeDirectories) @@ -95,6 +108,7 @@ true Use pch.h + $(SolutionDir)thirdparty\include;%(AdditionalIncludeDirectories) @@ -131,6 +145,7 @@ true Use pch.h + $(SolutionDir)thirdparty\include;%(AdditionalIncludeDirectories) diff --git a/TestClients/TestApiClientUI/Form1.cs b/TestClients/TestApiClientUI/Form1.cs index a2ef3000..a7848e8c 100644 --- a/TestClients/TestApiClientUI/Form1.cs +++ b/TestClients/TestApiClientUI/Form1.cs @@ -2,20 +2,50 @@ using System.Collections.Generic; using System.Drawing; using System.Globalization; -using System.Windows.Forms; using MtApi; -using System.Threading.Tasks; -using System.Linq; using MtApi.Monitors; +using System.Runtime.InteropServices; namespace TestApiClientUI { + class MtLogger : IMtLogger + { + public void Debug(object message) + { + Write("DEBUG", message); + } + + public void Error(object message) + { + Write("ERROR", message); + } + + public void Fatal(object message) + { + Write("FATAL", message); + } + + public void Info(object message) + { + Write("INFO", message); + } + + public void Warn(object message) + { + Write("WARN", message); + } + private void Write(string level, object message) + { + Console.WriteLine($"[{Environment.CurrentManagedThreadId}] [{level}] {message}"); + } + } + public partial class Form1 : Form { #region Fields - private readonly List _groupOrderCommands = new List(); - private readonly MtApiClient _apiClient = new MtApiClient(); + private readonly List _groupOrderCommands = []; + private readonly MtApiClient _apiClient = new (new MtLogger()); private readonly TimerTradeMonitor _timerTradeMonitor; private readonly TimeframeTradeMonitor _timeframeTradeMonitor; @@ -61,8 +91,14 @@ namespace TestApiClientUI _timeframeTradeMonitor = new TimeframeTradeMonitor(_apiClient); _timeframeTradeMonitor.AvailabilityOrdersChanged += _tradeMonitor_AvailabilityOrdersChanged; + + AllocConsole(); } + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool AllocConsole(); + private void InitOrderCommandsGroup() { _groupOrderCommands.Add(CloseOrders); diff --git a/TestClients/TestApiClientUI/Properties/AssemblyInfo.cs b/TestClients/TestApiClientUI/Properties/AssemblyInfo.cs deleted file mode 100644 index 599df16d..00000000 --- a/TestClients/TestApiClientUI/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("TestApiClientUI")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("DW")] -[assembly: AssemblyProduct("TestApiClientUI")] -[assembly: AssemblyCopyright("Copyright © DW 2012")] -[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("b8a613a1-ac11-4582-a67d-33bfd80fc490")] - -// 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.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestClients/TestApiClientUI/Properties/Resources.Designer.cs b/TestClients/TestApiClientUI/Properties/Resources.Designer.cs deleted file mode 100644 index 06f334dc..00000000 --- a/TestClients/TestApiClientUI/Properties/Resources.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace TestApiClientUI.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestApiClientUI.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } -} diff --git a/TestClients/TestApiClientUI/Properties/Resources.resx b/TestClients/TestApiClientUI/Properties/Resources.resx deleted file mode 100644 index ffecec85..00000000 --- a/TestClients/TestApiClientUI/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/TestClients/TestApiClientUI/Properties/Settings.Designer.cs b/TestClients/TestApiClientUI/Properties/Settings.Designer.cs deleted file mode 100644 index 2bace71a..00000000 --- a/TestClients/TestApiClientUI/Properties/Settings.Designer.cs +++ /dev/null @@ -1,26 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace TestApiClientUI.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } -} diff --git a/TestClients/TestApiClientUI/Properties/Settings.settings b/TestClients/TestApiClientUI/Properties/Settings.settings deleted file mode 100644 index abf36c5d..00000000 --- a/TestClients/TestApiClientUI/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/TestClients/TestApiClientUI/TestApiClientUI.csproj b/TestClients/TestApiClientUI/TestApiClientUI.csproj index 87f2e752..e782cf69 100644 --- a/TestClients/TestApiClientUI/TestApiClientUI.csproj +++ b/TestClients/TestApiClientUI/TestApiClientUI.csproj @@ -1,169 +1,15 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {663CC515-EAAE-47D4-8933-5008C2DA1160} - WinExe - Properties - TestApiClientUI - TestApiClientUI - v4.5 - - - 512 - false - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - true - bin\Debug\ - DEBUG;TRACE - full - AnyCPU - bin\Debug\TestApiClientUI.exe.CodeAnalysisLog.xml - true - GlobalSuppressions.cs - prompt - MinimumRecommendedRules.ruleset - ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets - true - ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules - true - false - - - bin\Release\ - TRACE - true - pdbonly - AnyCPU - bin\Release\TestApiClientUI.exe.CodeAnalysisLog.xml - true - GlobalSuppressions.cs - prompt - MinimumRecommendedRules.ruleset - ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets - true - ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules - true - false - - - - - - - - - - - - - - - - Form - - - Form1.cs - - - - - Form1.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 3.1 - true - - - - - {7a76c388-a8fb-4949-8170-24d4742e934e} - MtApi - - - - + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + \ No newline at end of file diff --git a/TestClients/TestApiClientUI/app.config b/TestClients/TestApiClientUI/app.config index b7a7ef16..99dca759 100644 --- a/TestClients/TestApiClientUI/app.config +++ b/TestClients/TestApiClientUI/app.config @@ -1,3 +1,3 @@ - +