mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 11:07:48 +00:00
Added project Mt5Api to VS_2022 solution and disable some code for compilable
This commit is contained in:
@@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MtService", "MtService\MtSe
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MT5Connector", "MT5Connector\MT5Connector.vcxproj", "{CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MtApi5", "MtApi5\MtApi5.csproj", "{AC8B5010-DA75-477E-9CA5-547C649E12D8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -55,6 +57,18 @@ Global
|
||||
{CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x64.Build.0 = Release|x64
|
||||
{CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x86.ActiveCfg = Release|Win32
|
||||
{CB6D4A3E-2F2E-4C67-929D-3C2A8FD1C556}.Release|x86.Build.0 = Release|Win32
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AC8B5010-DA75-477E-9CA5-547C649E12D8}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
{
|
||||
internal class OnBookEvent
|
||||
{
|
||||
public string Symbol { get; set; }
|
||||
public string? Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
{
|
||||
public class OnLastTimeBarEvent
|
||||
{
|
||||
public MqlRates Rates { get; set; }
|
||||
public string Instrument { get; set; }
|
||||
public MqlRates? Rates { get; set; }
|
||||
public string? Instrument { get; set; }
|
||||
public int ExpertHandle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
{
|
||||
internal class OnLockTicksEvent
|
||||
{
|
||||
public string Instrument { get; set; }
|
||||
public string? Instrument { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
{
|
||||
internal class OnTickEvent
|
||||
{
|
||||
public MqlTick Tick { get; set; }
|
||||
public string Instrument { get; set; }
|
||||
public MqlTick? Tick { get; set; }
|
||||
public string? Instrument { get; set; }
|
||||
public int ExpertHandle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
{
|
||||
internal class OnTradeTransactionEvent
|
||||
{
|
||||
public MqlTradeTransaction Trans { get; set; }
|
||||
public MqlTradeRequest Request { get; set; }
|
||||
public MqlTradeResult Result { get; set; }
|
||||
public MqlTradeTransaction? Trans { get; set; }
|
||||
public MqlTradeRequest? Request { get; set; }
|
||||
public MqlTradeResult? Result { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
namespace MtApi5
|
||||
{
|
||||
public class ExecutionException: Exception
|
||||
{
|
||||
public ExecutionException(ErrorCode errorCode, string message)
|
||||
public ExecutionException(ErrorCode errorCode, string? message)
|
||||
:base(message)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
|
||||
Executable
+133
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
//using log4net;
|
||||
//using log4net.Appender;
|
||||
//using log4net.Core;
|
||||
//using log4net.Layout;
|
||||
//using log4net.Repository.Hierarchy;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MtLog
|
||||
{
|
||||
#region ctor
|
||||
internal MtLog(Type type)
|
||||
{
|
||||
// _log = LogManager.GetLogger(type);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
|
||||
public void Debug(object message)
|
||||
{
|
||||
// _log.Debug(message);
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
// _log.Error(message);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
// _log.Fatal(message);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
// _log.Info(message);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
// _log.Warn(message);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
|
||||
//private readonly ILog _log;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
Off,
|
||||
Debug,
|
||||
Info
|
||||
}
|
||||
|
||||
public class LogConfigurator
|
||||
{
|
||||
private const string LogFileNameExtension = "log";
|
||||
|
||||
public static void Setup(string profileName)
|
||||
{
|
||||
#if (DEBUG)
|
||||
const LogLevel logLevel = LogLevel.Debug;
|
||||
#else
|
||||
const LogLevel logLevel = LogLevel.Info;
|
||||
#endif
|
||||
Setup(profileName, logLevel);
|
||||
}
|
||||
|
||||
public static void Setup(string profileName, LogLevel logLevel)
|
||||
{
|
||||
if (string.IsNullOrEmpty(profileName))
|
||||
throw new ArgumentNullException();
|
||||
|
||||
//var hierarchy = (Hierarchy) LogManager.GetRepository();
|
||||
|
||||
////check if logger is already configurated to avoid creation many empty logs files
|
||||
//if (hierarchy.Configured)
|
||||
// return;
|
||||
|
||||
//var patternLayout = new PatternLayout
|
||||
//{
|
||||
// ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
|
||||
//};
|
||||
//patternLayout.ActivateOptions();
|
||||
|
||||
////var filename = $"{DateTime.Now:yyyy-dd-M--HH-mm-ss}-{Process.GetCurrentProcess().Id}.{LogFileNameExtension}"; // This filename format keeps generating tons of log files with same content but different per-second/thread filenames until the harddisk have 0KB space left
|
||||
//var filename = $"{DateTime.Now:yyyy-MM-dd}.{LogFileNameExtension}";
|
||||
|
||||
//var roller = new RollingFileAppender
|
||||
//{
|
||||
// AppendToFile = true,
|
||||
// File = $@"{System.IO.Path.GetTempPath()}{profileName}\Logs\{filename}",
|
||||
// Layout = patternLayout,
|
||||
// PreserveLogFileNameExtension = true,
|
||||
// MaxSizeRollBackups = 5,
|
||||
// MaximumFileSize = "1GB",
|
||||
// RollingStyle = RollingFileAppender.RollingMode.Size,
|
||||
// StaticLogFileName = false
|
||||
//};
|
||||
//roller.ActivateOptions();
|
||||
//hierarchy.Root.AddAppender(roller);
|
||||
//hierarchy.Root.Level = ConvertLogLevel(logLevel);
|
||||
//hierarchy.Configured = true;
|
||||
}
|
||||
|
||||
public static MtLog GetLogger(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
|
||||
return new MtLog(type);
|
||||
}
|
||||
|
||||
//private static Level ConvertLogLevel(LogLevel logLevel)
|
||||
//{
|
||||
// switch (logLevel)
|
||||
// {
|
||||
// case LogLevel.Debug: return Level.Debug;
|
||||
// case LogLevel.Info: return Level.Info;
|
||||
// case LogLevel.Off: return Level.Off;
|
||||
// default:
|
||||
// throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@
|
||||
public ENUM_DATATYPE DataType { get; set; }
|
||||
public long? IntegerValue { get; set; }
|
||||
public double? DoubleValue { get; set; }
|
||||
public string StringValue { get; set; }
|
||||
public string? StringValue { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeCheckResult
|
||||
{
|
||||
@@ -11,7 +9,7 @@ namespace MtApi5
|
||||
public double Margin { get; set; } // Margin requirements
|
||||
public double Margin_free { get; set; } // Free margin
|
||||
public double Margin_level { get; set; } // Margin level
|
||||
public string Comment { get; set; } // Comment to the reply code (description of the error)
|
||||
public string? Comment { get; set; } // Comment to the reply code (description of the error)
|
||||
|
||||
public MqlTradeCheckResult(uint retcode
|
||||
, double balance
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -9,7 +7,7 @@ namespace MtApi5
|
||||
public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type
|
||||
public ulong Magic { get; set; } // Expert Advisor ID (magic number)
|
||||
public ulong Order { get; set; } // Order ticket
|
||||
public string Symbol { get; set; } // Trade symbol
|
||||
public string? Symbol { get; set; } // Trade symbol
|
||||
public double Volume { get; set; } // Requested volume for a deal in lots
|
||||
public double Price { get; set; } // Price
|
||||
public double Stoplimit { get; set; } // StopLimit level of the order
|
||||
@@ -27,7 +25,7 @@ namespace MtApi5
|
||||
set { MtExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||
}
|
||||
|
||||
public string Comment { get; set; } // Order comment
|
||||
public string? Comment { get; set; } // Order comment
|
||||
public ulong Position { get; set; } // Position ticket
|
||||
public ulong PositionBy { get; set; } // The ticket of an opposite position
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MtApi5
|
||||
{
|
||||
public ulong Deal { get; set; } // Deal ticket
|
||||
public ulong Order { get; set; } // Order ticket
|
||||
public string Symbol { get; set; } // Trade symbol name
|
||||
public string? Symbol { get; set; } // Trade symbol name
|
||||
public ENUM_TRADE_TRANSACTION_TYPE Type { get; set; } // Trade transaction type
|
||||
public ENUM_ORDER_TYPE OrderType { get; set; } // Order type
|
||||
public ENUM_ORDER_STATE OrderState { get; set; } // Order state
|
||||
|
||||
@@ -5,6 +5,6 @@ namespace MtApi5
|
||||
public class Mt5BookEventArgs : EventArgs
|
||||
{
|
||||
public int ExpertHandle { get; set; }
|
||||
public string Symbol { get; set; } //Symbol of OnBookEvent event.
|
||||
public string? Symbol { get; set; } //Symbol of OnBookEvent event.
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using MTApiService;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -22,10 +21,10 @@ namespace MtApi5
|
||||
Ask = ask;
|
||||
}
|
||||
|
||||
internal Mt5Quote(MtQuote quote)
|
||||
:this(quote.Instrument, quote.Bid, quote.Ask)
|
||||
{
|
||||
ExpertHandle = quote.ExpertHandle;
|
||||
}
|
||||
//internal Mt5Quote(MtQuote quote)
|
||||
// :this(quote.Instrument, quote.Bid, quote.Ask)
|
||||
//{
|
||||
// ExpertHandle = quote.ExpertHandle;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace MtApi5
|
||||
public class Mt5TradeTransactionEventArgs : EventArgs
|
||||
{
|
||||
public int ExpertHandle { get; set; }
|
||||
public MqlTradeTransaction Trans { get; set; } // trade transaction structure
|
||||
public MqlTradeRequest Request { get; set; } // request structure
|
||||
public MqlTradeResult Result { get; set; } // result structure
|
||||
public MqlTradeTransaction? Trans { get; set; } // trade transaction structure
|
||||
public MqlTradeRequest? Request { get; set; } // request structure
|
||||
public MqlTradeResult? Result { get; set; } // result structure
|
||||
}
|
||||
}
|
||||
+14
-122
@@ -1,123 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{AC8B5010-DA75-477E-9CA5-547C649E12D8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MtApi5</RootNamespace>
|
||||
<AssemblyName>MtApi5</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\build\products\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\build\products\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CopyTicksFlag.cs" />
|
||||
<Compile Include="Events\OnBookEvent.cs" />
|
||||
<Compile Include="Events\OnLastTimeBarEvent.cs" />
|
||||
<Compile Include="Events\OnLockTicksEvent.cs" />
|
||||
<Compile Include="Events\OnTickEvent.cs" />
|
||||
<Compile Include="Events\OnTradeTransactionEvent.cs" />
|
||||
<Compile Include="Mt5LockTicksEventArgs.cs" />
|
||||
<Compile Include="Mt5TimeBarArgs.cs" />
|
||||
<Compile Include="MqlBookInfo.cs" />
|
||||
<Compile Include="MqlParam.cs" />
|
||||
<Compile Include="MqlRates.cs" />
|
||||
<Compile Include="MqlTick.cs" />
|
||||
<Compile Include="MqlTradeCheckResult.cs" />
|
||||
<Compile Include="MqlTradeTransaction.cs" />
|
||||
<Compile Include="Mt5BookEventArgs.cs" />
|
||||
<Compile Include="Mt5TimeConverter.cs" />
|
||||
<Compile Include="Mt5Enums.cs" />
|
||||
<Compile Include="Mt5ConnectionEventArgs.cs" />
|
||||
<Compile Include="Mt5ConnectionState.cs" />
|
||||
<Compile Include="MqlTradeRequest.cs" />
|
||||
<Compile Include="MqlTradeResult.cs" />
|
||||
<Compile Include="Mt5QuoteEventArgs.cs" />
|
||||
<Compile Include="Mt5TradeTransactionEventArgs.cs" />
|
||||
<Compile Include="MtApi5Client.cs" />
|
||||
<Compile Include="Mt5CommandType.cs" />
|
||||
<Compile Include="MtConverters.cs" />
|
||||
<Compile Include="ErrorCode.cs" />
|
||||
<Compile Include="ExecutionException.cs" />
|
||||
<Compile Include="Events\Mt5EventTypes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Mt5Quote.cs" />
|
||||
<Compile Include="Requests\BuyRequest.cs" />
|
||||
<Compile Include="Requests\ChartTimePriceToXyRequest.cs" />
|
||||
<Compile Include="Requests\ChartTimePriceToXyResult.cs" />
|
||||
<Compile Include="Requests\ChartXyToTimePriceRequest.cs" />
|
||||
<Compile Include="Requests\ChartXyToTimePriceResult.cs" />
|
||||
<Compile Include="Requests\CopyTicksRequest.cs" />
|
||||
<Compile Include="Requests\ICustomRequest.cs" />
|
||||
<Compile Include="Requests\IndicatorCreateRequest.cs" />
|
||||
<Compile Include="Requests\MarketBookGetRequest.cs" />
|
||||
<Compile Include="Requests\OrderCheckRequest.cs" />
|
||||
<Compile Include="Requests\OrderCheckResult.cs" />
|
||||
<Compile Include="Requests\OrderSendAsyncRequest.cs" />
|
||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||
<Compile Include="Requests\PositionCloseRequest.cs" />
|
||||
<Compile Include="Requests\PositionCloseResult.cs" />
|
||||
<Compile Include="Requests\PositionOpenRequest.cs" />
|
||||
<Compile Include="Requests\RequestBase.cs" />
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Requests\OrderSendResult.cs" />
|
||||
<Compile Include="Requests\Response.cs" />
|
||||
<Compile Include="Requests\SellRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringResult.cs" />
|
||||
<Compile Include="Requests\SymbolInfoTickRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||
<Project>{DE76D5C7-B99C-4467-8408-78173BDD84E0}</Project>
|
||||
<Name>MTApiService</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<VersionPrefix>2.0.0</VersionPrefix>
|
||||
<BaseOutputPath>$(SolutionDir)build\products</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MtClient\MtClient.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+240
-230
@@ -1,13 +1,7 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MTApiService;
|
||||
using System.Collections;
|
||||
using System.ServiceModel;
|
||||
using MtApi5.Requests;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
using MtApi5.Events;
|
||||
|
||||
namespace MtApi5
|
||||
@@ -35,7 +29,7 @@ namespace MtApi5
|
||||
#region Private Fields
|
||||
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApi5Client));
|
||||
|
||||
private MtClient _client;
|
||||
//private MtClient _client;
|
||||
private readonly object _locker = new object();
|
||||
private volatile bool _isBacktestingMode;
|
||||
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
|
||||
@@ -95,11 +89,13 @@ namespace MtApi5
|
||||
///<summary>
|
||||
///Load quotes connected into MetaTrader API.
|
||||
///</summary>
|
||||
public IEnumerable<Mt5Quote> GetQuotes()
|
||||
public IEnumerable<Mt5Quote>? GetQuotes()
|
||||
{
|
||||
var client = Client;
|
||||
var quotes = client?.GetQuotes();
|
||||
return quotes?.Select(q => new Mt5Quote(q));
|
||||
//TODO: !!!
|
||||
//var client = Client;
|
||||
//var quotes = client?.GetQuotes();
|
||||
//return quotes?.Select(q => new Mt5Quote(q));
|
||||
return null;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -122,7 +118,7 @@ namespace MtApi5
|
||||
/// However, this is not a sign of successful execution of a trade operation.
|
||||
/// For a more detailed description of the function execution result, analyze the fields of result structure.
|
||||
/// </returns>
|
||||
public bool OrderSend(MqlTradeRequest request, out MqlTradeResult result)
|
||||
public bool OrderSend(MqlTradeRequest request, out MqlTradeResult? result)
|
||||
{
|
||||
Log.Debug($"OrderSend: request = {request}");
|
||||
|
||||
@@ -154,7 +150,7 @@ namespace MtApi5
|
||||
/// When processing the received request, a trade server sends a reply to a client terminal notifying of change in the current state of positions,
|
||||
/// orders and deals, which leads to the generation of the Trade event.
|
||||
/// </returns>
|
||||
public bool OrderSendAsync(MqlTradeRequest request, out MqlTradeResult result)
|
||||
public bool OrderSendAsync(MqlTradeRequest request, out MqlTradeResult? result)
|
||||
{
|
||||
Log.Debug($"OrderSend: request = {request}");
|
||||
|
||||
@@ -235,7 +231,7 @@ namespace MtApi5
|
||||
/// However, this is not an indication that the requested trade operation is sure to be successfully executed.
|
||||
/// For a more detailed description of the function execution result, analyze the fields of the result structure.
|
||||
/// </returns>
|
||||
public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult result)
|
||||
public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult? result)
|
||||
{
|
||||
Log.Debug($"OrderCheck: request = {request}");
|
||||
|
||||
@@ -607,7 +603,7 @@ namespace MtApi5
|
||||
///<param name="ticket">Ticket of the closed position.</param>
|
||||
///<param name="deviation">Maximal deviation from the current price (in points).</param>
|
||||
/// <param name="result">output result</param>
|
||||
public bool PositionClose(ulong ticket, ulong deviation, out MqlTradeResult result)
|
||||
public bool PositionClose(ulong ticket, ulong deviation, out MqlTradeResult? result)
|
||||
{
|
||||
Log.Debug($"PositionClose: ticket = {ticket}, deviation = {deviation}");
|
||||
|
||||
@@ -626,7 +622,7 @@ namespace MtApi5
|
||||
///</summary>
|
||||
///<param name="ticket">Ticket of the closed position.</param>
|
||||
/// <param name="result">output result</param>
|
||||
public bool PositionClose(ulong ticket, out MqlTradeResult result)
|
||||
public bool PositionClose(ulong ticket, out MqlTradeResult? result)
|
||||
{
|
||||
return PositionClose(ticket, ulong.MaxValue, out result);
|
||||
}
|
||||
@@ -661,7 +657,7 @@ namespace MtApi5
|
||||
/// <param name="comment">comment</param>
|
||||
/// <param name="result">output result</param>
|
||||
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment, out MqlTradeResult result)
|
||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment, out MqlTradeResult? result)
|
||||
{
|
||||
Log.Debug($"PositionOpen: symbol = {symbol}, orderType = {orderType}, volume = {volume}, price = {price}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||
|
||||
@@ -691,7 +687,7 @@ namespace MtApi5
|
||||
/// <param name="tp">Take Profit price</param>
|
||||
/// <param name="result">output result</param>
|
||||
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, out MqlTradeResult result)
|
||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, out MqlTradeResult? result)
|
||||
{
|
||||
return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result);
|
||||
}
|
||||
@@ -735,7 +731,7 @@ namespace MtApi5
|
||||
/// <param name="tp">Take Profit price.</param>
|
||||
/// <param name="comment">Comment.</param>
|
||||
/// <returns>true - successful check of the structures, otherwise - false.</returns>
|
||||
public bool Buy(out MqlTradeResult result, double volume, string symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string comment = null)
|
||||
public bool Buy(out MqlTradeResult? result, double volume, string? symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string? comment = null)
|
||||
{
|
||||
Log.Debug($"Buy: volume = {volume}, symbol = {symbol}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||
|
||||
@@ -764,7 +760,7 @@ namespace MtApi5
|
||||
/// <param name="tp">Take Profit price.</param>
|
||||
/// <param name="comment">Comment.</param>
|
||||
/// <returns>true - successful check of the structures, otherwise - false.</returns>
|
||||
public bool Sell(out MqlTradeResult result, double volume, string symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string comment = null)
|
||||
public bool Sell(out MqlTradeResult? result, double volume, string? symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string? comment = null)
|
||||
{
|
||||
Log.Debug($"Sell: volume = {volume}, symbol = {symbol}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||
|
||||
@@ -926,28 +922,30 @@ namespace MtApi5
|
||||
///<param name="startPos">The start position for the first element to copy.</param>
|
||||
///<param name="count">Data count to copy.</param>
|
||||
///<param name="ratesArray">Array of MqlRates type.</param>
|
||||
public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out MqlRates[] ratesArray)
|
||||
public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out MqlRates[]? ratesArray)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
|
||||
|
||||
ratesArray = null;
|
||||
|
||||
var retVal = SendCommand<MtMqlRates[]>(Mt5CommandType.CopyRates, commandParameters);
|
||||
if (retVal != null)
|
||||
{
|
||||
ratesArray = new MqlRates[retVal.Length];
|
||||
for(var i = 0; i < retVal.Length; i++)
|
||||
{
|
||||
ratesArray[i] = new MqlRates(retVal[i].time
|
||||
, retVal[i].open
|
||||
, retVal[i].high
|
||||
, retVal[i].low
|
||||
, retVal[i].close
|
||||
, retVal[i].tick_volume
|
||||
, retVal[i].spread
|
||||
, retVal[i].real_volume);
|
||||
}
|
||||
}
|
||||
//TODO: !!!
|
||||
|
||||
//var retVal = SendCommand<MtMqlRates[]>(Mt5CommandType.CopyRates, commandParameters);
|
||||
//if (retVal != null)
|
||||
//{
|
||||
// ratesArray = new MqlRates[retVal.Length];
|
||||
// for(var i = 0; i < retVal.Length; i++)
|
||||
// {
|
||||
// ratesArray[i] = new MqlRates(retVal[i].time
|
||||
// , retVal[i].open
|
||||
// , retVal[i].high
|
||||
// , retVal[i].low
|
||||
// , retVal[i].close
|
||||
// , retVal[i].tick_volume
|
||||
// , retVal[i].spread
|
||||
// , retVal[i].real_volume);
|
||||
// }
|
||||
//}
|
||||
|
||||
return ratesArray?.Length ?? 0;
|
||||
}
|
||||
@@ -960,28 +958,28 @@ namespace MtApi5
|
||||
///<param name="startTime">The start time for the first element to copy.</param>
|
||||
///<param name="count">Data count to copy.</param>
|
||||
///<param name="ratesArray">Array of MqlRates type.</param>
|
||||
public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out MqlRates[] ratesArray)
|
||||
public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out MqlRates[]? ratesArray)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
|
||||
|
||||
ratesArray = null;
|
||||
|
||||
var retVal = SendCommand<MtMqlRates[]>(Mt5CommandType.CopyRates1, commandParameters);
|
||||
if (retVal != null)
|
||||
{
|
||||
ratesArray = new MqlRates[retVal.Length];
|
||||
for (var i = 0; i < retVal.Length; i++)
|
||||
{
|
||||
ratesArray[i] = new MqlRates(retVal[i].time
|
||||
, retVal[i].open
|
||||
, retVal[i].high
|
||||
, retVal[i].low
|
||||
, retVal[i].close
|
||||
, retVal[i].tick_volume
|
||||
, retVal[i].spread
|
||||
, retVal[i].real_volume);
|
||||
}
|
||||
}
|
||||
//var retVal = SendCommand<MtMqlRates[]>(Mt5CommandType.CopyRates1, commandParameters);
|
||||
//if (retVal != null)
|
||||
//{
|
||||
// ratesArray = new MqlRates[retVal.Length];
|
||||
// for (var i = 0; i < retVal.Length; i++)
|
||||
// {
|
||||
// ratesArray[i] = new MqlRates(retVal[i].time
|
||||
// , retVal[i].open
|
||||
// , retVal[i].high
|
||||
// , retVal[i].low
|
||||
// , retVal[i].close
|
||||
// , retVal[i].tick_volume
|
||||
// , retVal[i].spread
|
||||
// , retVal[i].real_volume);
|
||||
// }
|
||||
//}
|
||||
|
||||
return ratesArray?.Length ?? 0;
|
||||
}
|
||||
@@ -994,28 +992,28 @@ namespace MtApi5
|
||||
///<param name="startTime">The start time for the first element to copy.</param>
|
||||
///<param name="stopTime">Bar time, corresponding to the last element to copy.</param>
|
||||
///<param name="ratesArray">Array of MqlRates type.</param>
|
||||
public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out MqlRates[] ratesArray)
|
||||
public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out MqlRates[]? ratesArray)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
|
||||
|
||||
ratesArray = null;
|
||||
|
||||
var retVal = SendCommand<MtMqlRates[]>(Mt5CommandType.CopyRates2, commandParameters);
|
||||
if (retVal != null)
|
||||
{
|
||||
ratesArray = new MqlRates[retVal.Length];
|
||||
for (var i = 0; i < retVal.Length; i++)
|
||||
{
|
||||
ratesArray[i] = new MqlRates(retVal[i].time
|
||||
, retVal[i].open
|
||||
, retVal[i].high
|
||||
, retVal[i].low
|
||||
, retVal[i].close
|
||||
, retVal[i].tick_volume
|
||||
, retVal[i].spread
|
||||
, retVal[i].real_volume);
|
||||
}
|
||||
}
|
||||
//var retVal = SendCommand<MtMqlRates[]>(Mt5CommandType.CopyRates2, commandParameters);
|
||||
//if (retVal != null)
|
||||
//{
|
||||
// ratesArray = new MqlRates[retVal.Length];
|
||||
// for (var i = 0; i < retVal.Length; i++)
|
||||
// {
|
||||
// ratesArray[i] = new MqlRates(retVal[i].time
|
||||
// , retVal[i].open
|
||||
// , retVal[i].high
|
||||
// , retVal[i].low
|
||||
// , retVal[i].close
|
||||
// , retVal[i].tick_volume
|
||||
// , retVal[i].spread
|
||||
// , retVal[i].real_volume);
|
||||
// }
|
||||
//}
|
||||
|
||||
return ratesArray?.Length ?? 0;
|
||||
}
|
||||
@@ -1028,7 +1026,7 @@ namespace MtApi5
|
||||
///<param name="startPos">The start position for the first element to copy.</param>
|
||||
///<param name="count">Data count to copy.</param>
|
||||
///<param name="timeArray">Array of DatetTme type.</param>
|
||||
public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out DateTime[] timeArray)
|
||||
public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out DateTime[]? timeArray)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
|
||||
|
||||
@@ -1055,7 +1053,7 @@ namespace MtApi5
|
||||
///<param name="startTime">The start time for the first element to copy.</param>
|
||||
///<param name="count">Data count to copy.</param>
|
||||
///<param name="timeArray">Array of DatetTme type.</param>
|
||||
public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out DateTime[] timeArray)
|
||||
public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out DateTime[]? timeArray)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
|
||||
|
||||
@@ -1082,7 +1080,7 @@ namespace MtApi5
|
||||
///<param name="startTime">The start time for the first element to copy.</param>
|
||||
///<param name="stopTime">Bar time corresponding to the last element to copy.</param>
|
||||
///<param name="timeArray">Array of DatetTme type.</param>
|
||||
public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out DateTime[] timeArray)
|
||||
public int CopyTime(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out DateTime[]? timeArray)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
|
||||
|
||||
@@ -1486,7 +1484,7 @@ namespace MtApi5
|
||||
///<param name="period">The value of the timeframe can be one of values of the ENUM_TIMEFRAMES enumeration, 0 means the current timeframe.</param>
|
||||
///<param name="indicatorType">Indicator type, can be one of values of the ENUM_INDICATOR enumeration.</param>
|
||||
///<param name="parameters">An array of MqlParam type, whose elements contain the type and value of each input parameter of a technical indicator.</param>
|
||||
public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List<MqlParam> parameters = null)
|
||||
public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List<MqlParam>? parameters = null)
|
||||
{
|
||||
var response = SendRequest<int>(new IndicatorCreateRequest
|
||||
{
|
||||
@@ -1596,7 +1594,7 @@ namespace MtApi5
|
||||
///<param name="symbolName">Symbol name.</param>
|
||||
///<param name="propId">Identifier of a symbol property.</param>
|
||||
///<param name="value">Variable of the string type receiving the value of the requested property.</param>
|
||||
public bool SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId, out string value)
|
||||
public bool SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId, out string? value)
|
||||
{
|
||||
var response = SendRequest<SymbolInfoStringResult>(new SymbolInfoStringRequest
|
||||
{
|
||||
@@ -1699,7 +1697,7 @@ namespace MtApi5
|
||||
///</summary>
|
||||
///<param name="symbol">Symbol name.</param>
|
||||
///<param name="book">Reference to an array of Depth of Market records.</param>
|
||||
public bool MarketBookGet(string symbol, out MqlBookInfo[] book)
|
||||
public bool MarketBookGet(string symbol, out MqlBookInfo[]? book)
|
||||
{
|
||||
var response = SendRequest<List<MqlBookInfo>>(new MarketBookGetRequest
|
||||
{
|
||||
@@ -2255,7 +2253,7 @@ namespace MtApi5
|
||||
///<param name="time">The time coordinate of the first anchor.</param>
|
||||
///<param name="price">The price coordinate of the first anchor point.</param>
|
||||
///<param name="listOfCoordinates">List of further anchor points (tuple of time and price).</param>
|
||||
public bool ObjectCreate(long chartId, string name, ENUM_OBJECT type, int nwin, DateTime time, double price, List<Tuple<DateTime, double>> listOfCoordinates = null)
|
||||
public bool ObjectCreate(long chartId, string name, ENUM_OBJECT type, int nwin, DateTime time, double price, List<Tuple<DateTime, double>>? listOfCoordinates = null)
|
||||
{
|
||||
//Count the additional coordinates
|
||||
int iAdditionalCoordinates = (listOfCoordinates != null) ? listOfCoordinates.Count() : 0;
|
||||
@@ -2267,7 +2265,7 @@ namespace MtApi5
|
||||
int nParameter = 6 + iAdditionalCoordinates * 2;
|
||||
var commandParameters = new ArrayList { nParameter, chartId, name, (int)type, nwin, Mt5TimeConverter.ConvertToMtTime(time), price };
|
||||
|
||||
if (iAdditionalCoordinates > 0)
|
||||
if (iAdditionalCoordinates > 0 && listOfCoordinates != null)
|
||||
{
|
||||
foreach (Tuple<DateTime, double> coordinateTuple in listOfCoordinates)
|
||||
{
|
||||
@@ -3307,97 +3305,99 @@ namespace MtApi5
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
public event QuoteHandler QuoteUpdated;
|
||||
public event EventHandler<Mt5QuoteEventArgs> QuoteUpdate;
|
||||
public event EventHandler<Mt5QuoteEventArgs> QuoteAdded;
|
||||
public event EventHandler<Mt5QuoteEventArgs> QuoteRemoved;
|
||||
public event EventHandler<Mt5ConnectionEventArgs> ConnectionStateChanged;
|
||||
public event EventHandler<Mt5TradeTransactionEventArgs> OnTradeTransaction;
|
||||
public event EventHandler<Mt5BookEventArgs> OnBookEvent;
|
||||
public event EventHandler<Mt5TimeBarArgs> OnLastTimeBar;
|
||||
public event EventHandler<Mt5LockTicksEventArgs> OnLockTicks;
|
||||
public event QuoteHandler? QuoteUpdated;
|
||||
public event EventHandler<Mt5QuoteEventArgs>? QuoteUpdate;
|
||||
public event EventHandler<Mt5QuoteEventArgs>? QuoteAdded;
|
||||
public event EventHandler<Mt5QuoteEventArgs>? QuoteRemoved;
|
||||
public event EventHandler<Mt5ConnectionEventArgs>? ConnectionStateChanged;
|
||||
public event EventHandler<Mt5TradeTransactionEventArgs>? OnTradeTransaction;
|
||||
public event EventHandler<Mt5BookEventArgs>? OnBookEvent;
|
||||
public event EventHandler<Mt5TimeBarArgs>? OnLastTimeBar;
|
||||
public event EventHandler<Mt5LockTicksEventArgs>? OnLockTicks;
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private MtClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
}
|
||||
}
|
||||
//private MtClient Client
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// lock (_locker)
|
||||
// {
|
||||
// return _client;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
private void Connect(MtClient client)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (_connectionState == Mt5ConnectionState.Connected
|
||||
|| _connectionState == Mt5ConnectionState.Connecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//private void Connect(MtClient client)
|
||||
//{
|
||||
// lock (_locker)
|
||||
// {
|
||||
// if (_connectionState == Mt5ConnectionState.Connected
|
||||
// || _connectionState == Mt5ConnectionState.Connecting)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
_connectionState = Mt5ConnectionState.Connecting;
|
||||
}
|
||||
// _connectionState = Mt5ConnectionState.Connecting;
|
||||
// }
|
||||
|
||||
string message = string.IsNullOrEmpty(client.Host) ? $"Connecting to localhost:{client.Port}" : $"Connecting to {client.Host}:{client.Port}";
|
||||
ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Connecting, message));
|
||||
// string message = string.IsNullOrEmpty(client.Host) ? $"Connecting to localhost:{client.Port}" : $"Connecting to {client.Host}:{client.Port}";
|
||||
// ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Connecting, message));
|
||||
|
||||
var state = Mt5ConnectionState.Failed;
|
||||
// var state = Mt5ConnectionState.Failed;
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
try
|
||||
{
|
||||
client.Connect();
|
||||
state = Mt5ConnectionState.Connected;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
client.Dispose();
|
||||
message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}";
|
||||
// lock (_locker)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// client.Connect();
|
||||
// state = Mt5ConnectionState.Connected;
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// client.Dispose();
|
||||
// message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}";
|
||||
|
||||
Log.Warn(message);
|
||||
}
|
||||
// Log.Warn(message);
|
||||
// }
|
||||
|
||||
if (state == Mt5ConnectionState.Connected)
|
||||
{
|
||||
_client = client;
|
||||
_client.QuoteAdded += _client_QuoteAdded;
|
||||
_client.QuoteRemoved += _client_QuoteRemoved;
|
||||
_client.QuoteUpdated += _client_QuoteUpdated;
|
||||
_client.ServerDisconnected += _client_ServerDisconnected;
|
||||
_client.ServerFailed += _client_ServerFailed;
|
||||
_client.MtEventReceived += _client_MtEventReceived;
|
||||
message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}";
|
||||
// if (state == Mt5ConnectionState.Connected)
|
||||
// {
|
||||
// _client = client;
|
||||
// _client.QuoteAdded += _client_QuoteAdded;
|
||||
// _client.QuoteRemoved += _client_QuoteRemoved;
|
||||
// _client.QuoteUpdated += _client_QuoteUpdated;
|
||||
// _client.ServerDisconnected += _client_ServerDisconnected;
|
||||
// _client.ServerFailed += _client_ServerFailed;
|
||||
// _client.MtEventReceived += _client_MtEventReceived;
|
||||
// message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}";
|
||||
|
||||
Log.Info(message);
|
||||
}
|
||||
// Log.Info(message);
|
||||
// }
|
||||
|
||||
_connectionState = state;
|
||||
}
|
||||
// _connectionState = state;
|
||||
// }
|
||||
|
||||
ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message));
|
||||
// ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message));
|
||||
|
||||
if (state == Mt5ConnectionState.Connected)
|
||||
{
|
||||
OnConnected();
|
||||
}
|
||||
}
|
||||
// if (state == Mt5ConnectionState.Connected)
|
||||
// {
|
||||
// OnConnected();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
private void _client_MtEventReceived(MtEvent e)
|
||||
{
|
||||
var eventType = (Mt5EventTypes)e.EventType;
|
||||
_mtEventHandlers[eventType](e.ExpertHandle, e.Payload);
|
||||
}
|
||||
//private void _client_MtEventReceived(MtEvent e)
|
||||
//{
|
||||
// var eventType = (Mt5EventTypes)e.EventType;
|
||||
// _mtEventHandlers[eventType](e.ExpertHandle, e.Payload);
|
||||
//}
|
||||
|
||||
private void ReceivedOnTradeTransactionEvent(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnTradeTransactionEvent>(payload);
|
||||
if (e == null)
|
||||
return;
|
||||
OnTradeTransaction?.Invoke(this, new Mt5TradeTransactionEventArgs
|
||||
{
|
||||
ExpertHandle = expertHandler,
|
||||
@@ -3410,6 +3410,8 @@ namespace MtApi5
|
||||
private void ReceivedOnBookEvent(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnBookEvent>(payload);
|
||||
if (e == null || string.IsNullOrEmpty(e.Symbol))
|
||||
return;
|
||||
OnBookEvent?.Invoke(this, new Mt5BookEventArgs
|
||||
{
|
||||
ExpertHandle = expertHandler,
|
||||
@@ -3420,6 +3422,8 @@ namespace MtApi5
|
||||
private void ReceivedOnTickEvent(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnTickEvent>(payload);
|
||||
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null)
|
||||
return;
|
||||
var quote = new Mt5Quote(e.Instrument, e.Tick.bid, e.Tick.ask)
|
||||
{
|
||||
ExpertHandle = expertHandler,
|
||||
@@ -3435,100 +3439,106 @@ namespace MtApi5
|
||||
private void ReceivedOnLastTimeBarEvent(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnLastTimeBarEvent>(payload);
|
||||
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Rates == null)
|
||||
return;
|
||||
OnLastTimeBar?.Invoke(this, new Mt5TimeBarArgs(expertHandler, e.Instrument, e.Rates));
|
||||
}
|
||||
|
||||
private void ReceivedOnLockTicksEvent(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnLockTicksEvent>(payload);
|
||||
if (e == null || string.IsNullOrEmpty(e.Instrument))
|
||||
return;
|
||||
OnLockTicks?.Invoke(this, new Mt5LockTicksEventArgs(e.Instrument));
|
||||
}
|
||||
|
||||
private void Connect(string host, int port)
|
||||
{
|
||||
var client = new MtClient(host, port);
|
||||
Connect(client);
|
||||
//var client = new MtClient(host, port);
|
||||
//Connect(client);
|
||||
}
|
||||
|
||||
private void Connect(int port)
|
||||
{
|
||||
var client = new MtClient(port);
|
||||
Connect(client);
|
||||
//var client = new MtClient(port);
|
||||
//Connect(client);
|
||||
}
|
||||
|
||||
private void Disconnect(bool failed)
|
||||
{
|
||||
var state = failed ? Mt5ConnectionState.Failed : Mt5ConnectionState.Disconnected;
|
||||
var message = failed ? "Connection Failed" : "Disconnected";
|
||||
//var state = failed ? Mt5ConnectionState.Failed : Mt5ConnectionState.Disconnected;
|
||||
//var message = failed ? "Connection Failed" : "Disconnected";
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
if (_connectionState == Mt5ConnectionState.Disconnected
|
||||
|| _connectionState == Mt5ConnectionState.Failed)
|
||||
return;
|
||||
//lock (_locker)
|
||||
//{
|
||||
// if (_connectionState == Mt5ConnectionState.Disconnected
|
||||
// || _connectionState == Mt5ConnectionState.Failed)
|
||||
// return;
|
||||
|
||||
if (_client != null)
|
||||
{
|
||||
_client.QuoteAdded -= _client_QuoteAdded;
|
||||
_client.QuoteRemoved -= _client_QuoteRemoved;
|
||||
_client.QuoteUpdated -= _client_QuoteUpdated;
|
||||
_client.ServerDisconnected -= _client_ServerDisconnected;
|
||||
_client.ServerFailed -= _client_ServerFailed;
|
||||
_client.MtEventReceived -= _client_MtEventReceived;
|
||||
// if (_client != null)
|
||||
// {
|
||||
// _client.QuoteAdded -= _client_QuoteAdded;
|
||||
// _client.QuoteRemoved -= _client_QuoteRemoved;
|
||||
// _client.QuoteUpdated -= _client_QuoteUpdated;
|
||||
// _client.ServerDisconnected -= _client_ServerDisconnected;
|
||||
// _client.ServerFailed -= _client_ServerFailed;
|
||||
// _client.MtEventReceived -= _client_MtEventReceived;
|
||||
|
||||
if (!failed)
|
||||
{
|
||||
_client.Disconnect();
|
||||
}
|
||||
// if (!failed)
|
||||
// {
|
||||
// _client.Disconnect();
|
||||
// }
|
||||
|
||||
_client.Dispose();
|
||||
// _client.Dispose();
|
||||
|
||||
_client = null;
|
||||
}
|
||||
// _client = null;
|
||||
// }
|
||||
|
||||
_connectionState = state;
|
||||
}
|
||||
// _connectionState = state;
|
||||
//}
|
||||
|
||||
Log.Info(message);
|
||||
//Log.Info(message);
|
||||
|
||||
ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message));
|
||||
//ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message));
|
||||
}
|
||||
|
||||
private T SendCommand<T>(Mt5CommandType commandType, ArrayList commandParameters, Dictionary<string, object> namedParams = null, int? executor = null)
|
||||
private T SendCommand<T>(Mt5CommandType commandType, ArrayList? commandParameters, Dictionary<string, object>? namedParams = null, int? executor = null)
|
||||
{
|
||||
MtResponse response;
|
||||
T r;
|
||||
//MtResponse response;
|
||||
|
||||
var client = Client;
|
||||
if (client == null)
|
||||
{
|
||||
Log.Warn("SendCommand: No connection");
|
||||
throw new Exception("No connection");
|
||||
}
|
||||
//var client = Client;
|
||||
//if (client == null)
|
||||
//{
|
||||
// Log.Warn("SendCommand: No connection");
|
||||
// throw new Exception("No connection");
|
||||
//}
|
||||
|
||||
try
|
||||
{
|
||||
response = client.SendCommand((int)commandType, commandParameters, namedParams, executor ?? ExecutorHandle);
|
||||
}
|
||||
catch (CommunicationException ex)
|
||||
{
|
||||
Log.Warn($"SendCommand: {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
//try
|
||||
//{
|
||||
// response = client.SendCommand((int)commandType, commandParameters, namedParams, executor ?? ExecutorHandle);
|
||||
//}
|
||||
//catch (CommunicationException ex)
|
||||
//{
|
||||
// Log.Warn($"SendCommand: {ex.Message}");
|
||||
// throw new Exception(ex.Message, ex);
|
||||
//}
|
||||
|
||||
if (response == null)
|
||||
{
|
||||
Log.Warn("SendCommand: Response from MetaTrader is null");
|
||||
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||
}
|
||||
//if (response == null)
|
||||
//{
|
||||
// Log.Warn("SendCommand: Response from MetaTrader is null");
|
||||
// throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||
//}
|
||||
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}");
|
||||
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ToString());
|
||||
}
|
||||
//if (response.ErrorCode != 0)
|
||||
//{
|
||||
// Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}");
|
||||
// throw new ExecutionException((ErrorCode)response.ErrorCode, response.ToString());
|
||||
//}
|
||||
|
||||
var responseValue = response.GetValue();
|
||||
return (T) responseValue;
|
||||
//var responseValue = response.GetValue();
|
||||
//return (T) responseValue;
|
||||
return default(T);
|
||||
}
|
||||
|
||||
private T SendRequest<T>(RequestBase request)
|
||||
@@ -3551,7 +3561,7 @@ namespace MtApi5
|
||||
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||
}
|
||||
|
||||
var response = JsonConvert.DeserializeObject<Response<T>>(res);
|
||||
var response = JsonConvert.DeserializeObject<Response<T>>(res) ?? throw new Exception("Failed to deserialize response");
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Warn($"SendRequest: ErrorCode = {response.ErrorCode}. {response}");
|
||||
@@ -3562,12 +3572,12 @@ namespace MtApi5
|
||||
}
|
||||
|
||||
|
||||
private void _client_QuoteUpdated(MtQuote quote)
|
||||
{
|
||||
if (quote == null) return;
|
||||
QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote)));
|
||||
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||
}
|
||||
//private void _client_QuoteUpdated(MtQuote quote)
|
||||
//{
|
||||
// if (quote == null) return;
|
||||
// QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote)));
|
||||
// QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||
//}
|
||||
|
||||
private void _client_ServerDisconnected(object sender, EventArgs e)
|
||||
{
|
||||
@@ -3579,21 +3589,21 @@ namespace MtApi5
|
||||
Disconnect(true);
|
||||
}
|
||||
|
||||
private void _client_QuoteRemoved(MtQuote quote)
|
||||
{
|
||||
if (quote != null)
|
||||
{
|
||||
QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote)));
|
||||
}
|
||||
}
|
||||
//private void _client_QuoteRemoved(MtQuote quote)
|
||||
//{
|
||||
// if (quote != null)
|
||||
// {
|
||||
// QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote)));
|
||||
// }
|
||||
//}
|
||||
|
||||
private void _client_QuoteAdded(MtQuote quote)
|
||||
{
|
||||
if (quote != null)
|
||||
{
|
||||
QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote)));
|
||||
}
|
||||
}
|
||||
//private void _client_QuoteAdded(MtQuote quote)
|
||||
//{
|
||||
// if (quote != null)
|
||||
// {
|
||||
// QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote)));
|
||||
// }
|
||||
//}
|
||||
|
||||
private void OnConnected()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using MTApiService;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("MtApi5")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MtApi5")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f3256daf-a5c0-422d-9d79-f7156cccb910")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.24")]
|
||||
[assembly: AssemblyFileVersion("1.0.24")]
|
||||
@@ -5,10 +5,10 @@
|
||||
public override RequestType RequestType => RequestType.Buy;
|
||||
|
||||
public double Volume { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public string? Symbol { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.CopyTicks;
|
||||
|
||||
public string SymbolName { get; set; }
|
||||
public string? SymbolName { get; set; }
|
||||
public int Flags { get; set; }
|
||||
public ulong From { get; set; }
|
||||
public uint Count { get; set; }
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace MtApi5.Requests
|
||||
Boolean = 3
|
||||
}
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public required string Symbol { get; set; }
|
||||
public int Timeframe { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ArrayList Params { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public ArrayList? Params { get; set; }
|
||||
public ParametersType ParamsType { get; set; }
|
||||
|
||||
public override RequestType RequestType => RequestType.iCustom;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class IndicatorCreateRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.IndicatorCreate;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public string? Symbol { get; set; }
|
||||
public ENUM_TIMEFRAMES Period { get; set; }
|
||||
public ENUM_INDICATOR IndicatorType { get; set; }
|
||||
public List<MqlParam> Parameters { get; set; }
|
||||
public List<MqlParam>? Parameters { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.MarketBookGet;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public string? Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderCheck;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
public MqlTradeRequest? TradeRequest { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
public class OrderCheckResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeCheckResult TradeCheckResult { get; set; }
|
||||
public MqlTradeCheckResult? TradeCheckResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderSendAsync;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
public MqlTradeRequest? TradeRequest { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderSend;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
public MqlTradeRequest? TradeRequest { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
internal class OrderSendResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeResult TradeResult { get; set; }
|
||||
public MqlTradeResult? TradeResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
internal class PositionCloseResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeResult TradeResult { get; set; }
|
||||
public MqlTradeResult? TradeResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.PositionOpen;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public string? Symbol { get; set; }
|
||||
public ENUM_ORDER_TYPE OrderType { get; set; }
|
||||
public double Volume { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
internal class Response<T>
|
||||
{
|
||||
public int ErrorCode { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
public T Value { get; set; }
|
||||
public required T Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
public override RequestType RequestType => RequestType.Sell;
|
||||
|
||||
public double Volume { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public string? Symbol { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
public override RequestType RequestType => RequestType.SymbolInfoString;
|
||||
|
||||
public string SymbolName { get; set; }
|
||||
public string? SymbolName { get; set; }
|
||||
public ENUM_SYMBOL_INFO_STRING PropId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
internal class SymbolInfoStringResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public string StringVar { get; set; }
|
||||
public string? StringVar { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class SymbolInfoTickRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.SymbolInfoTick;
|
||||
|
||||
public string SymbolName { get; set; }
|
||||
public string? SymbolName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)build\products</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user