mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-02 05:27:47 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b4adfaa97 |
@@ -1,67 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<!-- -->
|
|
||||||
<!-- ILMerge project-specific settings. Almost never need to be set explicitly. -->
|
|
||||||
<!-- for details, see http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx -->
|
|
||||||
<!-- -->
|
|
||||||
<!-- *** set this file to Type=None, CopyToOutput=Never *** -->
|
|
||||||
|
|
||||||
<!-- If True, all copy local dependencies will also be merged from referenced projects whether they are referenced in the current project explicitly or not -->
|
|
||||||
<ILMergeTransitive>true</ILMergeTransitive>
|
|
||||||
|
|
||||||
<!-- Extra ILMerge library paths (semicolon-separated). Dont put your package dependencies here, they will be added automagically -->
|
|
||||||
<ILMergeLibraryPath></ILMergeLibraryPath>
|
|
||||||
|
|
||||||
<!-- The solution NuGet package directory if not standard 'SOLUTION\packages' -->
|
|
||||||
<ILMergePackagesPath></ILMergePackagesPath>
|
|
||||||
|
|
||||||
<!-- The merge order file name if differs from standard 'ILMergeOrder.txt' -->
|
|
||||||
<ILMergeOrderFile></ILMergeOrderFile>
|
|
||||||
|
|
||||||
<!-- The strong key file name if not specified in the project -->
|
|
||||||
<ILMergeKeyFile>MtApiKey.snk</ILMergeKeyFile>
|
|
||||||
|
|
||||||
<!-- The assembly version if differs for the version of the main assembly -->
|
|
||||||
<ILMergeAssemblyVersion></ILMergeAssemblyVersion>
|
|
||||||
|
|
||||||
<!-- added in Version 1.0.4 -->
|
|
||||||
<ILMergeFileAlignment></ILMergeFileAlignment>
|
|
||||||
|
|
||||||
<!-- added in Version 1.0.4, default=none -->
|
|
||||||
<ILMergeAllowDuplicateType></ILMergeAllowDuplicateType>
|
|
||||||
|
|
||||||
<!-- If the <see cref="CopyAttributes"/> is also set, any assembly-level attributes names that have the same type are copied over into the target assembly -->
|
|
||||||
<ILMergeAllowMultipleAssemblyLevelAttributes></ILMergeAllowMultipleAssemblyLevelAttributes>
|
|
||||||
|
|
||||||
<!-- See ILMerge documentation -->
|
|
||||||
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>
|
|
||||||
|
|
||||||
<!-- The assembly level attributes of each input assembly are copied over into the target assembly -->
|
|
||||||
<ILMergeCopyAttributes></ILMergeCopyAttributes>
|
|
||||||
|
|
||||||
<!-- Creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies, default=true -->
|
|
||||||
<ILMergeDebugInfo></ILMergeDebugInfo>
|
|
||||||
|
|
||||||
<!-- Target assembly will be delay signed -->
|
|
||||||
<ILMergeDelaySign></ILMergeDelaySign>
|
|
||||||
|
|
||||||
<!-- Types in assemblies other than the primary assembly have their visibility modified -->
|
|
||||||
<ILMergeInternalize></ILMergeInternalize>
|
|
||||||
|
|
||||||
<!-- The path name of the file that will be used to identify types that are not to have their visibility modified -->
|
|
||||||
<ILMergeInternalizeExcludeFile></ILMergeInternalizeExcludeFile>
|
|
||||||
|
|
||||||
<!-- XML documentation files are merged to produce an XML documentation file for the target assembly -->
|
|
||||||
<ILMergeXmlDocumentation></ILMergeXmlDocumentation>
|
|
||||||
|
|
||||||
<!-- External assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true, default value) -->
|
|
||||||
<ILMergePublicKeyTokens></ILMergePublicKeyTokens>
|
|
||||||
|
|
||||||
<!-- Types with the same name are all merged into a single type in the target assembly -->
|
|
||||||
<ILMergeUnionMerge></ILMergeUnionMerge>
|
|
||||||
|
|
||||||
<!-- The version of the target framework, default 40 (works for 45 too) -->
|
|
||||||
<ILTargetPlatform></ILTargetPlatform>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# this file contains the partial list of the merged assemblies in the merge order
|
|
||||||
# you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build
|
|
||||||
# and finetune merge order to your satisfaction
|
|
||||||
|
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
public interface IMtApiServer
|
public interface IMtApiServer
|
||||||
{
|
{
|
||||||
MtResponse SendCommand(MtCommand command);
|
MtResponse SendCommand(MtCommand command);
|
||||||
List<MtQuote> GetQuotes();
|
IEnumerable<MtQuote> GetQuotes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
using System;
|
|
||||||
using log4net;
|
|
||||||
using log4net.Appender;
|
|
||||||
using log4net.Core;
|
|
||||||
using log4net.Layout;
|
|
||||||
using log4net.Repository.Hierarchy;
|
|
||||||
|
|
||||||
namespace MTApiService
|
|
||||||
{
|
|
||||||
public class LogConfigurator
|
|
||||||
{
|
|
||||||
private const string LogFileNameExtension = "txt";
|
|
||||||
|
|
||||||
public static void Setup(string profileName)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(profileName))
|
|
||||||
throw new ArgumentNullException();
|
|
||||||
|
|
||||||
var hierarchy = (Hierarchy) LogManager.GetRepository();
|
|
||||||
|
|
||||||
var patternLayout = new PatternLayout
|
|
||||||
{
|
|
||||||
ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
|
|
||||||
};
|
|
||||||
patternLayout.ActivateOptions();
|
|
||||||
|
|
||||||
string filename = $"{DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}.{LogFileNameExtension}";
|
|
||||||
|
|
||||||
var roller = new RollingFileAppender
|
|
||||||
{
|
|
||||||
AppendToFile = false,
|
|
||||||
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);
|
|
||||||
|
|
||||||
var memory = new MemoryAppender();
|
|
||||||
memory.ActivateOptions();
|
|
||||||
hierarchy.Root.AddAppender(memory);
|
|
||||||
|
|
||||||
#if (DEBUG)
|
|
||||||
hierarchy.Root.Level = Level.Debug;
|
|
||||||
#else
|
|
||||||
hierarchy.Root.Level = Level.Info;
|
|
||||||
#endif
|
|
||||||
hierarchy.Configured = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.props" Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.props')" />
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
@@ -15,8 +14,6 @@
|
|||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<TargetFrameworkProfile>
|
<TargetFrameworkProfile>
|
||||||
</TargetFrameworkProfile>
|
</TargetFrameworkProfile>
|
||||||
<NuGetPackageImportStamp>
|
|
||||||
</NuGetPackageImportStamp>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -38,17 +35,12 @@
|
|||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SignAssembly>false</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>MtApiKey.pfx</AssemblyOriginatorKeyFile>
|
||||||
</AssemblyOriginatorKeyFile>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\log4net.2.0.5\lib\net40-full\log4net.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Runtime.Serialization" />
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
@@ -62,7 +54,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ICommandManager.cs" />
|
<Compile Include="ICommandManager.cs" />
|
||||||
<Compile Include="IMetaTraderHandler.cs" />
|
<Compile Include="IMetaTraderHandler.cs" />
|
||||||
<Compile Include="LogConfigurator.cs" />
|
|
||||||
<Compile Include="MtCommandEventArgs.cs" />
|
<Compile Include="MtCommandEventArgs.cs" />
|
||||||
<Compile Include="IDisposableChannel.cs" />
|
<Compile Include="IDisposableChannel.cs" />
|
||||||
<Compile Include="IMtApiServer.cs" />
|
<Compile Include="IMtApiServer.cs" />
|
||||||
@@ -87,28 +78,13 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="ILMerge.props">
|
<None Include="MtApiKey.pfx" />
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</None>
|
|
||||||
<None Include="MtApiKey.snk" />
|
|
||||||
<None Include="packages.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="ILMergeOrder.txt" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
|
||||||
<PropertyGroup>
|
|
||||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.props'))" />
|
|
||||||
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets'))" />
|
|
||||||
</Target>
|
|
||||||
<Import Project="..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" />
|
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
Binary file not shown.
+14
-11
@@ -1,17 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.ServiceModel.Channels;
|
using System.ServiceModel.Channels;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
internal class MtApiProxy : DuplexClientBase<IMtApi>, IMtApi, IDisposable
|
class MtApiProxy : DuplexClientBase<IMtApi>, IMtApi, IDisposable
|
||||||
{
|
{
|
||||||
public MtApiProxy(InstanceContext callbackContext, Binding binding, EndpointAddress remoteAddress)
|
public MtApiProxy(InstanceContext callbackContext, Binding binding,
|
||||||
|
EndpointAddress remoteAddress)
|
||||||
: base(callbackContext, binding, remoteAddress)
|
: base(callbackContext, binding, remoteAddress)
|
||||||
{
|
{
|
||||||
InnerDuplexChannel.Faulted += InnerDuplexChannel_Faulted;
|
base.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted);
|
||||||
InnerDuplexChannel.Open();
|
base.InnerDuplexChannel.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IMtApi Members
|
#region IMtApi Members
|
||||||
@@ -31,7 +34,7 @@ namespace MTApiService
|
|||||||
return Channel.SendCommand(command);
|
return Channel.SendCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MtQuote> GetQuotes()
|
public IEnumerable<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
return Channel.GetQuotes();
|
return Channel.GetQuotes();
|
||||||
}
|
}
|
||||||
@@ -44,19 +47,19 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
catch (CommunicationException)
|
catch (CommunicationException)
|
||||||
{
|
{
|
||||||
Abort();
|
this.Abort();
|
||||||
}
|
}
|
||||||
catch (TimeoutException)
|
catch (TimeoutException)
|
||||||
{
|
{
|
||||||
Abort();
|
this.Abort();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Abort();
|
this.Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,9 +68,9 @@ namespace MTApiService
|
|||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void InnerDuplexChannel_Faulted(object sender, EventArgs e)
|
private void InnerDuplexChannel_Faulted(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Faulted?.Invoke(this, e);
|
if (Faulted != null)
|
||||||
|
Faulted(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|||||||
+133
-171
@@ -1,208 +1,173 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
[CallbackBehavior(UseSynchronizationContext = false)]
|
[CallbackBehavior(UseSynchronizationContext = false)]
|
||||||
public class MtClient: IMtApiCallback, IDisposable
|
public class MtClient: IMtApiCallback, IDisposable
|
||||||
{
|
{
|
||||||
private const string ServiceName = "MtApiService";
|
private static string SERVICE_NAME = "MtApiService";
|
||||||
|
|
||||||
public delegate void MtQuoteHandler(MtQuote quote);
|
public delegate void MtQuoteHandler(MtQuote quote);
|
||||||
|
|
||||||
#region Fields
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtClient));
|
|
||||||
|
|
||||||
private MtApiProxy _proxy;
|
|
||||||
private bool _isConnected;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
public void Open(string host, int port)
|
public void Open(string host, int port)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Open: begin. host = {0}, port = {1}", host, port);
|
Debug.WriteLine("[INFO] MtClient::Open");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(host))
|
if (string.IsNullOrEmpty(host))
|
||||||
throw new ArgumentNullException(nameof(host), "host is null or empty");
|
throw new ArgumentNullException("host", "host is null or empty");
|
||||||
|
|
||||||
if (port < 0 || port > 65536)
|
if (port < 0 || port > 65536)
|
||||||
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");
|
throw new ArgumentOutOfRangeException("port", "port value is invalid");
|
||||||
|
|
||||||
var urlService = $"net.tcp://{host}:{port}/{ServiceName}";
|
var urlService = string.Format("net.tcp://{0}:{1}/{2}", host, port, SERVICE_NAME);
|
||||||
|
|
||||||
if (_proxy != null)
|
lock (mClientLocker)
|
||||||
{
|
{
|
||||||
Log.Warn("Open: end. _proxy is not null.");
|
if (mProxy != null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
var bind = new NetTcpBinding(SecurityMode.None)
|
var bind = new NetTcpBinding(SecurityMode.None)
|
||||||
{
|
|
||||||
MaxReceivedMessageSize = 2147483647,
|
|
||||||
MaxBufferSize = 2147483647,
|
|
||||||
MaxBufferPoolSize = 2147483647,
|
|
||||||
SendTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReceiveTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReaderQuotas =
|
|
||||||
{
|
{
|
||||||
MaxArrayLength = 2147483647,
|
MaxReceivedMessageSize = 2147483647,
|
||||||
MaxBytesPerRead = 2147483647,
|
MaxBufferSize = 2147483647,
|
||||||
MaxDepth = 2147483647,
|
MaxBufferPoolSize = 2147483647,
|
||||||
MaxStringContentLength = 2147483647,
|
ReaderQuotas =
|
||||||
MaxNameTableCharCount = 2147483647
|
{
|
||||||
}
|
MaxArrayLength = 2147483647,
|
||||||
};
|
MaxBytesPerRead = 2147483647,
|
||||||
// Commented next statement since it is not required
|
MaxDepth = 2147483647,
|
||||||
|
MaxStringContentLength = 2147483647,
|
||||||
|
MaxNameTableCharCount = 2147483647
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Commented next statement since it is not required
|
||||||
|
|
||||||
_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
||||||
_proxy.Faulted += ProxyFaulted;
|
mProxy.Faulted += mProxy_Faulted;
|
||||||
|
}
|
||||||
Log.Debug("Open: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open(int port)
|
public void Open(int port)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Open: begin. port = {0}", port);
|
|
||||||
|
|
||||||
if (port < 0 || port > 65536)
|
if (port < 0 || port > 65536)
|
||||||
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");
|
throw new ArgumentOutOfRangeException("port", "port value is invalid");
|
||||||
|
|
||||||
var urlService = $"net.pipe://localhost/{ServiceName}_{port}";
|
var urlService = string.Format("net.pipe://localhost/{0}_{1}", SERVICE_NAME, port);
|
||||||
|
|
||||||
if (_proxy != null)
|
lock (mClientLocker)
|
||||||
{
|
{
|
||||||
Log.Warn("Open: end. _proxy is not null.");
|
if (mProxy != null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
|
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
|
||||||
{
|
|
||||||
MaxReceivedMessageSize = 2147483647,
|
|
||||||
MaxBufferSize = 2147483647,
|
|
||||||
MaxBufferPoolSize = 2147483647,
|
|
||||||
SendTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReceiveTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReaderQuotas =
|
|
||||||
{
|
{
|
||||||
MaxArrayLength = 2147483647,
|
MaxReceivedMessageSize = 2147483647,
|
||||||
MaxBytesPerRead = 2147483647,
|
MaxBufferSize = 2147483647,
|
||||||
MaxDepth = 2147483647,
|
MaxBufferPoolSize = 2147483647,
|
||||||
MaxStringContentLength = 2147483647,
|
ReaderQuotas =
|
||||||
MaxNameTableCharCount = 2147483647
|
{
|
||||||
}
|
MaxArrayLength = 2147483647,
|
||||||
};
|
MaxBytesPerRead = 2147483647,
|
||||||
// Commented next statement since it is not required
|
MaxDepth = 2147483647,
|
||||||
|
MaxStringContentLength = 2147483647,
|
||||||
|
MaxNameTableCharCount = 2147483647
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Commented next statement since it is not required
|
||||||
|
|
||||||
_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
||||||
_proxy.Faulted += ProxyFaulted;
|
mProxy.Faulted += mProxy_Faulted;
|
||||||
|
}
|
||||||
Log.Debug("Open: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
Log.Debug("Close: begin.");
|
Debug.WriteLine("[INFO] MtClient::Close");
|
||||||
|
|
||||||
if (_proxy != null)
|
lock (mClientLocker)
|
||||||
{
|
{
|
||||||
_proxy.Faulted -= ProxyFaulted;
|
if (mProxy != null)
|
||||||
_proxy.Dispose();
|
{
|
||||||
_proxy = null;
|
mProxy.Faulted -= mProxy_Faulted;
|
||||||
|
mProxy.Dispose();
|
||||||
|
mProxy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
mIsConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_isConnected = false;
|
|
||||||
|
|
||||||
Log.Debug("Close: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
Log.Debug("Connect: begin.");
|
Debug.WriteLine("[INFO] MtClient::Connect");
|
||||||
|
|
||||||
if (_proxy == null)
|
|
||||||
{
|
|
||||||
Log.Error("Connect: _proxy is not defined.");
|
|
||||||
throw new CommunicationException("Connection failed to service. Proxy is not defined (needs to call Open)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_isConnected)
|
|
||||||
{
|
|
||||||
Log.Warn("Connected: end. Client is already connected.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_isConnected = _proxy.Connect();
|
lock (mClientLocker)
|
||||||
|
{
|
||||||
|
if (mProxy != null && mIsConnected == true)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mIsConnected = mProxy.Connect();
|
||||||
|
|
||||||
|
if (mIsConnected == false)
|
||||||
|
throw new Exception("Connected failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Connect: Exception - {0}", ex.Message);
|
Debug.WriteLine("[ERROR] MtClient::Connect: {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
throw new CommunicationException($"Connection failed to service. {ex.Message}");
|
throw new CommunicationException(string.Format("Connection failed to service"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_isConnected == false)
|
|
||||||
{
|
|
||||||
Log.Error("Connect: end. Connection failed.");
|
|
||||||
throw new CommunicationException("Connection failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("Connect: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
Log.Debug("Disconnect: begin.");
|
Debug.WriteLine("[INFO] MtClient::Disconnect");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_isConnected = false;
|
lock (mClientLocker)
|
||||||
|
{
|
||||||
|
mIsConnected = false;
|
||||||
|
|
||||||
_proxy?.Disconnect();
|
if (mProxy != null)
|
||||||
|
mProxy.Disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Disconnect: Exception - {0}", ex.Message);
|
Debug.WriteLine("[ERROR] MtClient::Disconnect: {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("Disconnect: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
public MtResponse SendCommand(int commandType, ArrayList commandParameters)
|
||||||
public MtResponse SendCommand(int commandType, ArrayList parameters)
|
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendCommand: begin. commandType = {0}, parameters count = {1}", commandType, parameters?.Count);
|
Debug.WriteLine("[INFO] MtClient::SendCommand: commandType = {0}", commandType);
|
||||||
|
|
||||||
MtResponse result;
|
MtResponse result = null;
|
||||||
|
|
||||||
if (_isConnected == false)
|
|
||||||
{
|
|
||||||
Log.Error("SendCommand: Client is not connected.");
|
|
||||||
throw new CommunicationException("Client is not connected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_proxy == null)
|
|
||||||
{
|
|
||||||
Log.Error("SendCommand: Proxy is not defined.");
|
|
||||||
throw new CommunicationException("Proxy is not defined.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = _proxy.SendCommand(new MtCommand(commandType, parameters));
|
lock (mClientLocker)
|
||||||
|
{
|
||||||
|
if (mProxy != null && mIsConnected == true)
|
||||||
|
result = mProxy.SendCommand(new MtCommand(commandType, commandParameters));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("SendCommand: Exception - {0}", ex.Message);
|
Debug.WriteLine("[ERROR] MtClient::SendCommand: {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
@@ -212,41 +177,30 @@ namespace MTApiService
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
|
||||||
public IEnumerable<MtQuote> GetQuotes()
|
public IEnumerable<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
Log.Debug("GetQuotes: begin.");
|
Debug.WriteLine("[INFO] MtClient::GetQuotes");
|
||||||
|
|
||||||
if (_isConnected == false)
|
IEnumerable<MtQuote> result = null;
|
||||||
{
|
|
||||||
Log.Warn("GetQuotes: end. Client is not connected.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_proxy == null)
|
|
||||||
{
|
|
||||||
Log.Warn("GetQuotes: end. _proxy is not defined.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MtQuote> result;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = _proxy.GetQuotes();
|
lock (mClientLocker)
|
||||||
|
{
|
||||||
|
if (mProxy != null && mIsConnected == true)
|
||||||
|
result = mProxy.GetQuotes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("GetQuotes: Exception - {0}", ex.Message);
|
Debug.WriteLine("[ERROR] MtClient::GetQuotes: {0}", ex.Message);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
throw new CommunicationException($"Service connection failed! {ex.Message}");
|
throw new CommunicationException("Service connection failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.DebugFormat("GetQuotes: end. quotes count = {0}", result?.Count);
|
return result;;
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -255,70 +209,74 @@ namespace MTApiService
|
|||||||
|
|
||||||
public void OnQuoteUpdate(MtQuote quote)
|
public void OnQuoteUpdate(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("OnQuoteUpdate: begin. quote = {0}", quote);
|
if (quote != null)
|
||||||
|
{
|
||||||
|
if (QuoteUpdated != null)
|
||||||
|
{
|
||||||
|
QuoteUpdated(quote);
|
||||||
|
}
|
||||||
|
|
||||||
if (quote == null) return;
|
Debug.WriteLine("[INFO] MtClient::OnQuoteUpdate: " + quote);
|
||||||
|
}
|
||||||
QuoteUpdated?.Invoke(quote);
|
|
||||||
|
|
||||||
Log.Debug("OnQuoteUpdate: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnQuoteAdded(MtQuote quote)
|
public void OnQuoteAdded(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("OnQuoteAdded: begin. quote = {0}", quote);
|
Debug.WriteLine("[INFO] MtClient::OnQuoteAdded");
|
||||||
|
|
||||||
QuoteAdded?.Invoke(quote);
|
QuoteAdded?.Invoke(quote);
|
||||||
|
|
||||||
Log.Debug("OnQuoteAdded: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnQuoteRemoved(MtQuote quote)
|
public void OnQuoteRemoved(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("OnQuoteRemoved: begin. quote = {0}", quote);
|
Debug.WriteLine("[INFO] MtClient::OnQuoteRemoved");
|
||||||
|
|
||||||
QuoteRemoved?.Invoke(quote);
|
QuoteRemoved?.Invoke(quote);
|
||||||
|
|
||||||
Log.Debug("OnQuoteRemoved: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnServerStopped()
|
public void OnServerStopped()
|
||||||
{
|
{
|
||||||
Log.Debug("OnServerStopped: begin.");
|
Debug.WriteLine("[INFO] MtClient::OnServerStopped");
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
ServerDisconnected?.Invoke(this, EventArgs.Empty);
|
|
||||||
|
|
||||||
Log.Debug("OnServerStopped: end.");
|
ServerDisconnected?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnMtEvent(MtEvent mtEvent)
|
public void OnMtEvent(MtEvent mtEvent)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("OnMtEvent: begin. event = {0}", mtEvent);
|
|
||||||
|
|
||||||
MtEventReceived?.Invoke(this, new MtEventArgs(mtEvent));
|
MtEventReceived?.Invoke(this, new MtEventArgs(mtEvent));
|
||||||
|
|
||||||
Log.Debug("OnMtEvent: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public bool IsConnected => _proxy.State == CommunicationState.Opened && _isConnected;
|
public bool IsConnected
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (mClientLocker)
|
||||||
|
{
|
||||||
|
return mProxy.State == CommunicationState.Opened && mIsConnected == true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
||||||
private void ProxyFaulted(object sender, EventArgs e)
|
void mProxy_Faulted(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Log.Debug("ProxyFaulted: begin.");
|
Debug.WriteLine("[INFO] MtClient::mProxy_Faulted");
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
ServerFailed?.Invoke(this, EventArgs.Empty);
|
|
||||||
|
|
||||||
Log.Debug("ProxyFaulted: end.");
|
if (ServerFailed != null)
|
||||||
|
{
|
||||||
|
ServerFailed(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -327,11 +285,9 @@ namespace MTApiService
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Log.Debug("Dispose: begin.");
|
Debug.WriteLine("[INFO] MtClient::Dispose");
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
Log.Debug("Dispose: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -344,5 +300,11 @@ namespace MTApiService
|
|||||||
public event EventHandler ServerFailed;
|
public event EventHandler ServerFailed;
|
||||||
public event EventHandler<MtEventArgs> MtEventReceived;
|
public event EventHandler<MtEventArgs> MtEventReceived;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Fields
|
||||||
|
private readonly object mClientLocker = new object();
|
||||||
|
private MtApiProxy mProxy = null;
|
||||||
|
private bool mIsConnected = false;
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
using System.Runtime.Serialization;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.ServiceModel;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
@@ -18,9 +22,5 @@ namespace MTApiService
|
|||||||
[DataMember]
|
[DataMember]
|
||||||
public ArrayList Parameters { get; private set; }
|
public ArrayList Parameters { get; private set; }
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"CommandType = {CommandType}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+1
-9
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Threading;
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
@@ -11,9 +10,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
public MtCommandTask(MtCommand command)
|
public MtCommandTask(MtCommand command)
|
||||||
{
|
{
|
||||||
if (command == null)
|
|
||||||
throw new ArgumentNullException(nameof(command));
|
|
||||||
|
|
||||||
Command = command;
|
Command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +33,5 @@ namespace MTApiService
|
|||||||
_responseWaiter.Set();
|
_responseWaiter.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"Command = {Command}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
public class MtConnectionProfile
|
public class MtConnectionProfile
|
||||||
|
|||||||
@@ -1,50 +1,31 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
internal class MtCommandExecutorManager : ICommandManager
|
internal class MtCommandExecutorManager : ICommandManager
|
||||||
{
|
{
|
||||||
#region Private Fields
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtCommandExecutorManager));
|
|
||||||
|
|
||||||
private readonly List<MtExpert> _commandExecutors = new List<MtExpert>();
|
|
||||||
private readonly Queue<MtCommandTask> _commandTasks = new Queue<MtCommandTask>();
|
|
||||||
|
|
||||||
private readonly object _locker = new object();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
Log.Debug("Stop: begin.");
|
|
||||||
|
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
_commandExecutors.Clear();
|
_commandExecutors.Clear();
|
||||||
_commandTasks.Clear();
|
_commandTasks.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("Stop: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCommandExecutor(MtExpert commandExecutor)
|
public void AddCommandExecutor(MtExpert commandExecutor)
|
||||||
{
|
{
|
||||||
if (commandExecutor == null)
|
if (commandExecutor == null)
|
||||||
throw new ArgumentNullException(nameof(commandExecutor));
|
return;
|
||||||
|
|
||||||
Log.DebugFormat("AddCommandExecutor: begin. commandExecutor = {0}", commandExecutor);
|
|
||||||
|
|
||||||
var notify = false;
|
var notify = false;
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
if (_commandExecutors.Contains(commandExecutor))
|
if (_commandExecutors.Contains(commandExecutor))
|
||||||
{
|
|
||||||
Log.Warn("AddCommandExecutor: end. Command executor already exist.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_commandExecutors.Add(commandExecutor);
|
_commandExecutors.Add(commandExecutor);
|
||||||
if (_commandTasks.Count > 0)
|
if (_commandTasks.Count > 0)
|
||||||
@@ -60,25 +41,18 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
NotifyCommandReady();
|
NotifyCommandReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("AddCommandExecutor: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveCommandExecutor(MtExpert commandExecutor)
|
public void RemoveCommandExecutor(MtExpert commandExecutor)
|
||||||
{
|
{
|
||||||
if (commandExecutor == null)
|
if (commandExecutor == null)
|
||||||
throw new ArgumentNullException(nameof(commandExecutor));
|
return;
|
||||||
|
|
||||||
Log.DebugFormat("RemoveCommandExecutor: begin. commandExecutor = {0}", commandExecutor);
|
|
||||||
|
|
||||||
var notify = false;
|
var notify = false;
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
if (_commandExecutors.Contains(commandExecutor) == false)
|
if (_commandExecutors.Contains(commandExecutor) == false)
|
||||||
{
|
|
||||||
Log.Warn("RemoveCommandExecutor: end. Command executor is not exist in collection.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_commandExecutors.Remove(commandExecutor);
|
_commandExecutors.Remove(commandExecutor);
|
||||||
if (_commandTasks.Count > 0)
|
if (_commandTasks.Count > 0)
|
||||||
@@ -94,16 +68,12 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
NotifyCommandReady();
|
NotifyCommandReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("RemoveCommandExecutor: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnqueueCommandTask(MtCommandTask task)
|
public void EnqueueCommandTask(MtCommandTask task)
|
||||||
{
|
{
|
||||||
if (task == null)
|
if (task == null)
|
||||||
throw new ArgumentNullException(nameof(task));
|
return;
|
||||||
|
|
||||||
Log.DebugFormat("EnqueueCommandTask: begin. task = {0}", task);
|
|
||||||
|
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
@@ -111,14 +81,10 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
|
|
||||||
NotifyCommandReady();
|
NotifyCommandReady();
|
||||||
|
|
||||||
Log.Debug("EnqueueCommandTask: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtCommandTask DequeueCommandTask()
|
public MtCommandTask DequeueCommandTask()
|
||||||
{
|
{
|
||||||
Log.Debug("DequeueCommandTask: called.");
|
|
||||||
|
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
return _commandTasks.Count > 0 ? _commandTasks.Dequeue() : null;
|
return _commandTasks.Count > 0 ? _commandTasks.Dequeue() : null;
|
||||||
@@ -130,8 +96,6 @@ namespace MTApiService
|
|||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void NotifyCommandReady()
|
private void NotifyCommandReady()
|
||||||
{
|
{
|
||||||
Log.Debug("NotifyCommandReady: begin.");
|
|
||||||
|
|
||||||
var commandExecutors = new List<MtExpert>();
|
var commandExecutors = new List<MtExpert>();
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
@@ -142,14 +106,10 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
executor.NotifyCommandReady();
|
executor.NotifyCommandReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.DebugFormat("NotifyCommandReady: end. Notified executor count = {0}", commandExecutors.Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CommandExecutor_CommandExecuted(object sender, EventArgs e)
|
private void CommandExecutor_CommandExecuted(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Log.Debug("CommandExecutor_CommandExecuted: begin.");
|
|
||||||
|
|
||||||
var notify = false;
|
var notify = false;
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
@@ -164,8 +124,14 @@ namespace MTApiService
|
|||||||
NotifyCommandReady();
|
NotifyCommandReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("CommandExecutor_CommandExecuted: end.");
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private Fields
|
||||||
|
private readonly List<MtExpert> _commandExecutors = new List<MtExpert>();
|
||||||
|
private readonly Queue<MtCommandTask> _commandTasks = new Queue<MtCommandTask>();
|
||||||
|
|
||||||
|
private readonly object _locker = new object();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+66
-91
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
@@ -7,89 +6,6 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
|
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
|
||||||
|
|
||||||
#region Private Fields
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert));
|
|
||||||
|
|
||||||
private readonly IMetaTraderHandler _mtHadler;
|
|
||||||
private MtCommandTask _commandTask;
|
|
||||||
private ICommandManager _commandManager;
|
|
||||||
private readonly object _locker = new object();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Methods
|
|
||||||
public MtExpert(int handle, MtQuote quote, IMetaTraderHandler mtHandler)
|
|
||||||
{
|
|
||||||
if (mtHandler == null)
|
|
||||||
throw new ArgumentNullException(nameof(mtHandler));
|
|
||||||
|
|
||||||
Quote = quote;
|
|
||||||
Handle = handle;
|
|
||||||
_mtHadler = mtHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Deinit()
|
|
||||||
{
|
|
||||||
Log.Debug("Deinit: begin.");
|
|
||||||
|
|
||||||
IsEnable = false;
|
|
||||||
FireOnDeinited();
|
|
||||||
|
|
||||||
Log.Debug("Deinit: end.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendResponse(MtResponse response)
|
|
||||||
{
|
|
||||||
Log.DebugFormat("SendResponse: begin. response = {0}", response);
|
|
||||||
|
|
||||||
_commandTask.SetResult(response);
|
|
||||||
_commandTask = null;
|
|
||||||
FireOnCommandExecuted();
|
|
||||||
|
|
||||||
Log.Debug("SendResponse: end.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetCommandType()
|
|
||||||
{
|
|
||||||
Log.Debug("GetCommandType: called.");
|
|
||||||
|
|
||||||
var commandManager = CommandManager;
|
|
||||||
if (commandManager != null)
|
|
||||||
{
|
|
||||||
_commandTask = commandManager.DequeueCommandTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _commandTask?.Command?.CommandType ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object GetCommandParameter(int index)
|
|
||||||
{
|
|
||||||
Log.DebugFormat("GetCommandType: called. index = {0}", index);
|
|
||||||
|
|
||||||
var command = _commandTask?.Command;
|
|
||||||
if (command?.Parameters != null && index >= 0 && index < command.Parameters.Count)
|
|
||||||
{
|
|
||||||
return command.Parameters[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendEvent(MtEvent mtEvent)
|
|
||||||
{
|
|
||||||
Log.DebugFormat("SendEvent: begin. event = {0}", mtEvent);
|
|
||||||
|
|
||||||
FireOnMtEvent(mtEvent);
|
|
||||||
|
|
||||||
Log.Debug("SendEvent: end.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"ExpertHandle = {Handle}";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
private MtQuote _quote;
|
private MtQuote _quote;
|
||||||
public MtQuote Quote
|
public MtQuote Quote
|
||||||
@@ -103,7 +19,7 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
lock (_locker)
|
lock(_locker)
|
||||||
{
|
{
|
||||||
_quote = value;
|
_quote = value;
|
||||||
}
|
}
|
||||||
@@ -112,7 +28,7 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Handle { get; }
|
public int Handle { get; private set; }
|
||||||
|
|
||||||
private bool _isEnable = true;
|
private bool _isEnable = true;
|
||||||
public bool IsEnable
|
public bool IsEnable
|
||||||
@@ -153,21 +69,73 @@ namespace MTApiService
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
public MtExpert(int handle, MtQuote quote, IMetaTraderHandler mtHandler)
|
||||||
|
{
|
||||||
|
Quote = quote;
|
||||||
|
Handle = handle;
|
||||||
|
_mtHadler = mtHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deinit()
|
||||||
|
{
|
||||||
|
IsEnable = false;
|
||||||
|
FireOnDeinited();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendResponse(MtResponse response)
|
||||||
|
{
|
||||||
|
_commandTask.SetResult(response);
|
||||||
|
_commandTask = null;
|
||||||
|
FireOnCommandExecuted();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetCommandType()
|
||||||
|
{
|
||||||
|
var commandManager = CommandManager;
|
||||||
|
if (commandManager != null)
|
||||||
|
{
|
||||||
|
_commandTask = commandManager.DequeueCommandTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _commandTask != null && _commandTask.Command != null ? _commandTask.Command.CommandType : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetCommandParameter(int index)
|
||||||
|
{
|
||||||
|
if (_commandTask != null)
|
||||||
|
{
|
||||||
|
var command = _commandTask.Command;
|
||||||
|
if (command != null && command.Parameters != null
|
||||||
|
&& index >= 0 && index < command.Parameters.Count)
|
||||||
|
{
|
||||||
|
return command.Parameters[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendEvent(MtEvent mtEvent)
|
||||||
|
{
|
||||||
|
FireOnMtEvent(mtEvent);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IMtCommandExecutor
|
#region IMtCommandExecutor
|
||||||
public void NotifyCommandReady()
|
public void NotifyCommandReady()
|
||||||
{
|
{
|
||||||
Log.Debug("NotifyCommandReady: begin.");
|
|
||||||
|
|
||||||
SendTickToMetaTrader();
|
SendTickToMetaTrader();
|
||||||
|
|
||||||
Log.Debug("NotifyCommandReady: end.");
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void SendTickToMetaTrader()
|
private void SendTickToMetaTrader()
|
||||||
{
|
{
|
||||||
_mtHadler.SendTickToMetaTrader(Handle);
|
if (_mtHadler != null)
|
||||||
|
{
|
||||||
|
_mtHadler.SendTickToMetaTrader(Handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FireOnQuoteChanged(MtQuote quote)
|
private void FireOnQuoteChanged(MtQuote quote)
|
||||||
@@ -197,5 +165,12 @@ namespace MTApiService
|
|||||||
public event EventHandler CommandExecuted;
|
public event EventHandler CommandExecuted;
|
||||||
public event EventHandler<MtEventArgs> OnMtEvent;
|
public event EventHandler<MtEventArgs> OnMtEvent;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private Fields
|
||||||
|
private readonly IMetaTraderHandler _mtHadler;
|
||||||
|
private MtCommandTask _commandTask;
|
||||||
|
private ICommandManager _commandManager;
|
||||||
|
private readonly object _locker = new object();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
using System.Runtime.Serialization;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
using System.Runtime.Serialization;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
using System.Runtime.Serialization;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
using System.Runtime.Serialization;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
@@ -7,12 +9,12 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
public class MtRegistryManager
|
public class MtRegistryManager
|
||||||
{
|
{
|
||||||
private const string Software = "Software";
|
private const string SOFTWARE = "Software";
|
||||||
private const string AppName = "MtApi";
|
private const string APP_NAME = "MtApi";
|
||||||
private const string ProfilesRegkey = "ConnectionProfiles";
|
private const string PROFILES_REGKEY = "ConnectionProfiles";
|
||||||
private const string HostRegvalueName = "Host";
|
private const string HOST_REGVALUE_NAME = "Host";
|
||||||
private const string PortRegvalueName = "Port";
|
private const string PORT_REGVALUE_NAME = "Port";
|
||||||
private const string SignatureRegvalueName = "MtSignature";
|
private const string SIGNATURE_REGVALUE_NAME = "MtSignature";
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
public static IEnumerable<MtConnectionProfile> LoadConnectionProfiles()
|
public static IEnumerable<MtConnectionProfile> LoadConnectionProfiles()
|
||||||
@@ -51,12 +53,12 @@ namespace MTApiService
|
|||||||
|
|
||||||
string signature = null;
|
string signature = null;
|
||||||
|
|
||||||
var softwareRegKey = Registry.CurrentUser.OpenSubKey(Software, true);
|
var softwareRegKey = Registry.CurrentUser.OpenSubKey(SOFTWARE, true);
|
||||||
if (softwareRegKey != null)
|
if (softwareRegKey != null)
|
||||||
{
|
{
|
||||||
using (softwareRegKey)
|
using (softwareRegKey)
|
||||||
{
|
{
|
||||||
var appRegKey = softwareRegKey.OpenSubKey(AppName, true);
|
var appRegKey = softwareRegKey.OpenSubKey(APP_NAME, true);
|
||||||
if (appRegKey != null)
|
if (appRegKey != null)
|
||||||
{
|
{
|
||||||
using (appRegKey)
|
using (appRegKey)
|
||||||
@@ -71,7 +73,7 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
using (numberKey)
|
using (numberKey)
|
||||||
{
|
{
|
||||||
signature = numberKey.GetValue(SignatureRegvalueName).ToString();
|
signature = numberKey.GetValue(SIGNATURE_REGVALUE_NAME).ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,7 @@ namespace MTApiService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var softwareRgKey = Registry.CurrentUser.OpenSubKey(Software, true);
|
RegistryKey softwareRgKey = Registry.CurrentUser.OpenSubKey(SOFTWARE, true);
|
||||||
|
|
||||||
if (softwareRgKey == null)
|
if (softwareRgKey == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -103,33 +105,35 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
|
|
||||||
//app name
|
//app name
|
||||||
var appRegKey = softwareRgKey.OpenSubKey(AppName, true) ?? softwareRgKey.CreateSubKey(AppName);
|
var appRegKey = softwareRgKey.OpenSubKey(APP_NAME, true);
|
||||||
|
if (appRegKey == null)
|
||||||
if (appRegKey != null)
|
|
||||||
{
|
{
|
||||||
using (appRegKey)
|
appRegKey = softwareRgKey.CreateSubKey(APP_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (appRegKey)
|
||||||
|
{
|
||||||
|
//account name
|
||||||
|
var accountKey = appRegKey.OpenSubKey(accountName, true);
|
||||||
|
if (accountKey == null)
|
||||||
{
|
{
|
||||||
//account name
|
accountKey = appRegKey.CreateSubKey(accountName);
|
||||||
var accountKey = appRegKey.OpenSubKey(accountName, true) ?? appRegKey.CreateSubKey(accountName);
|
}
|
||||||
|
|
||||||
if (accountKey != null)
|
using (accountKey)
|
||||||
|
{
|
||||||
|
//account number
|
||||||
|
var numberKey = accountKey.OpenSubKey(accountNumber, true);
|
||||||
|
if (numberKey == null)
|
||||||
{
|
{
|
||||||
using (accountKey)
|
numberKey = accountKey.CreateSubKey(accountNumber);
|
||||||
{
|
}
|
||||||
//account number
|
|
||||||
var numberKey = accountKey.OpenSubKey(accountNumber, true) ??
|
|
||||||
accountKey.CreateSubKey(accountNumber);
|
|
||||||
|
|
||||||
if (numberKey != null)
|
using (numberKey)
|
||||||
{
|
{
|
||||||
using (numberKey)
|
numberKey.SetValue(SIGNATURE_REGVALUE_NAME, signature);
|
||||||
{
|
|
||||||
numberKey.SetValue(SignatureRegvalueName, signature);
|
|
||||||
|
|
||||||
retVal = numberKey.ToString();
|
retVal = numberKey.ToString();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,19 +142,20 @@ namespace MTApiService
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ExportKey(string regKey, string savePath)
|
public static bool ExportKey(string RegKey, string SavePath)
|
||||||
{
|
{
|
||||||
var path = $"\"{savePath}\"";
|
string path = "\"" + SavePath + "\"";
|
||||||
var key = $"\"{regKey}\"";
|
string key = "\"" + RegKey + "\"";
|
||||||
|
|
||||||
var proc = new Process();
|
Process proc = new Process();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
proc.StartInfo.FileName = "regedit.exe";
|
proc.StartInfo.FileName = "regedit.exe";
|
||||||
proc.StartInfo.UseShellExecute = false;
|
proc.StartInfo.UseShellExecute = false;
|
||||||
proc = Process.Start("regedit.exe", "/e " + path + " " + key + "");
|
proc = Process.Start("regedit.exe", "/e " + path + " " + key + "");
|
||||||
|
|
||||||
proc?.WaitForExit();
|
if (proc != null)
|
||||||
|
proc.WaitForExit();
|
||||||
}
|
}
|
||||||
catch(Exception)
|
catch(Exception)
|
||||||
{
|
{
|
||||||
@@ -158,7 +163,8 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
proc?.Dispose();
|
if (proc != null)
|
||||||
|
proc.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -171,38 +177,33 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
List<MtConnectionProfile> profiles = null;
|
List<MtConnectionProfile> profiles = null;
|
||||||
|
|
||||||
var softwareRegKey = Registry.CurrentUser.OpenSubKey(Software, true);
|
var softwareRegKey = Registry.CurrentUser.OpenSubKey(SOFTWARE, true);
|
||||||
if (softwareRegKey != null)
|
if (softwareRegKey != null)
|
||||||
{
|
{
|
||||||
using (softwareRegKey)
|
using (softwareRegKey)
|
||||||
{
|
{
|
||||||
var appRegKey = softwareRegKey.OpenSubKey(AppName, true);
|
var appRegKey = softwareRegKey.OpenSubKey(APP_NAME, true);
|
||||||
if (appRegKey != null)
|
if (appRegKey != null)
|
||||||
{
|
{
|
||||||
using (appRegKey)
|
using (appRegKey)
|
||||||
{
|
{
|
||||||
var profilesRegKey = appRegKey.OpenSubKey(ProfilesRegkey, true);
|
var profilesRegKey = appRegKey.OpenSubKey(PROFILES_REGKEY, true);
|
||||||
if (profilesRegKey != null)
|
if (profilesRegKey != null)
|
||||||
{
|
{
|
||||||
using (profilesRegKey)
|
using (profilesRegKey)
|
||||||
{
|
{
|
||||||
profiles = new List<MtConnectionProfile>();
|
profiles = new List<MtConnectionProfile>();
|
||||||
|
|
||||||
foreach (var profileNameKey in profilesRegKey.GetSubKeyNames())
|
foreach (string profileNameKey in profilesRegKey.GetSubKeyNames())
|
||||||
{
|
{
|
||||||
var tempKey = profilesRegKey.OpenSubKey(profileNameKey);
|
using (RegistryKey tempKey = profilesRegKey.OpenSubKey(profileNameKey))
|
||||||
if (tempKey != null)
|
|
||||||
{
|
{
|
||||||
using (tempKey)
|
var profile = new MtConnectionProfile(profileNameKey);
|
||||||
{
|
|
||||||
var profile = new MtConnectionProfile(profileNameKey)
|
|
||||||
{
|
|
||||||
Host = tempKey.GetValue(HostRegvalueName).ToString(),
|
|
||||||
Port = (int) tempKey.GetValue(PortRegvalueName)
|
|
||||||
};
|
|
||||||
|
|
||||||
profiles.Add(profile);
|
profile.Host = tempKey.GetValue(HOST_REGVALUE_NAME).ToString();
|
||||||
}
|
profile.Port = (int)tempKey.GetValue(PORT_REGVALUE_NAME);
|
||||||
|
|
||||||
|
profiles.Add(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,33 +220,27 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
MtConnectionProfile profile = null;
|
MtConnectionProfile profile = null;
|
||||||
|
|
||||||
var softwareRegKey = Registry.CurrentUser.OpenSubKey(Software, true);
|
var softwareRegKey = Registry.CurrentUser.OpenSubKey(SOFTWARE, true);
|
||||||
if (softwareRegKey != null)
|
if (softwareRegKey != null)
|
||||||
{
|
{
|
||||||
using (softwareRegKey)
|
using (softwareRegKey)
|
||||||
{
|
{
|
||||||
var appRegKey = softwareRegKey.OpenSubKey(AppName, true);
|
var appRegKey = softwareRegKey.OpenSubKey(APP_NAME, true);
|
||||||
if (appRegKey != null)
|
if (appRegKey != null)
|
||||||
{
|
{
|
||||||
using (appRegKey)
|
using (appRegKey)
|
||||||
{
|
{
|
||||||
var profilesRegKey = appRegKey.OpenSubKey(ProfilesRegkey, true);
|
var profilesRegKey = appRegKey.OpenSubKey(PROFILES_REGKEY, true);
|
||||||
if (profilesRegKey != null)
|
if (profilesRegKey != null)
|
||||||
{
|
{
|
||||||
using (profilesRegKey)
|
using (profilesRegKey)
|
||||||
{
|
{
|
||||||
var tempKey = profilesRegKey.OpenSubKey(profileName);
|
using (RegistryKey tempKey = profilesRegKey.OpenSubKey(profileName))
|
||||||
if (tempKey != null)
|
|
||||||
{
|
{
|
||||||
using (tempKey)
|
profile = new MtConnectionProfile(profileName);
|
||||||
{
|
|
||||||
profile = new MtConnectionProfile(profileName)
|
|
||||||
{
|
|
||||||
Host = tempKey.GetValue(HostRegvalueName).ToString(),
|
|
||||||
Port = (int) tempKey.GetValue(PortRegvalueName)
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
profile.Host = tempKey.GetValue(HOST_REGVALUE_NAME).ToString();
|
||||||
|
profile.Port = (int)tempKey.GetValue(PORT_REGVALUE_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +254,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
private static void SaveConnectionProfileToRegistry(MtConnectionProfile profile)
|
private static void SaveConnectionProfileToRegistry(MtConnectionProfile profile)
|
||||||
{
|
{
|
||||||
var softwareRgKey = Registry.CurrentUser.OpenSubKey(Software, true);
|
RegistryKey softwareRgKey = Registry.CurrentUser.OpenSubKey(SOFTWARE, true);
|
||||||
|
|
||||||
if (softwareRgKey == null)
|
if (softwareRgKey == null)
|
||||||
return;
|
return;
|
||||||
@@ -267,30 +262,29 @@ namespace MTApiService
|
|||||||
using (softwareRgKey)
|
using (softwareRgKey)
|
||||||
{
|
{
|
||||||
//app name
|
//app name
|
||||||
var appRegKey = softwareRgKey.OpenSubKey(AppName, true) ?? softwareRgKey.CreateSubKey(AppName);
|
var appRegKey = softwareRgKey.OpenSubKey(APP_NAME, true);
|
||||||
|
if (appRegKey == null)
|
||||||
if (appRegKey != null)
|
|
||||||
{
|
{
|
||||||
using (appRegKey)
|
appRegKey = softwareRgKey.CreateSubKey(APP_NAME);
|
||||||
{
|
}
|
||||||
//ConnectionProfiles key
|
|
||||||
var profilesRegKey = appRegKey.OpenSubKey(ProfilesRegkey, true) ??
|
|
||||||
appRegKey.CreateSubKey(ProfilesRegkey);
|
|
||||||
|
|
||||||
if (profilesRegKey != null)
|
using (appRegKey)
|
||||||
|
{
|
||||||
|
//ConnectionProfiles key
|
||||||
|
var profilesRegKey = appRegKey.OpenSubKey(PROFILES_REGKEY, true);
|
||||||
|
if (profilesRegKey == null)
|
||||||
|
{
|
||||||
|
profilesRegKey = appRegKey.CreateSubKey(PROFILES_REGKEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (profilesRegKey)
|
||||||
|
{
|
||||||
|
var profileKey = profilesRegKey.CreateSubKey(profile.Name);
|
||||||
|
|
||||||
|
using (profileKey)
|
||||||
{
|
{
|
||||||
using (profilesRegKey)
|
profileKey.SetValue(HOST_REGVALUE_NAME, profile.Host);
|
||||||
{
|
profileKey.SetValue(PORT_REGVALUE_NAME, profile.Port);
|
||||||
var profileKey = profilesRegKey.CreateSubKey(profile.Name);
|
|
||||||
if (profileKey != null)
|
|
||||||
{
|
|
||||||
using (profileKey)
|
|
||||||
{
|
|
||||||
profileKey.SetValue(HostRegvalueName, profile.Host);
|
|
||||||
profileKey.SetValue(PortRegvalueName, profile.Port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,19 +293,19 @@ namespace MTApiService
|
|||||||
|
|
||||||
private static void DeleteConnectionProfileFromRegistry(string profileName)
|
private static void DeleteConnectionProfileFromRegistry(string profileName)
|
||||||
{
|
{
|
||||||
var softwareRegKey = Registry.CurrentUser.OpenSubKey(Software, true);
|
var softwareRegKey = Registry.CurrentUser.OpenSubKey(SOFTWARE, true);
|
||||||
if (softwareRegKey == null)
|
if (softwareRegKey == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using (softwareRegKey)
|
using (softwareRegKey)
|
||||||
{
|
{
|
||||||
var appRegKey = softwareRegKey.OpenSubKey(AppName, true);
|
var appRegKey = softwareRegKey.OpenSubKey(APP_NAME, true);
|
||||||
if (appRegKey == null)
|
if (appRegKey == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using (appRegKey)
|
using (appRegKey)
|
||||||
{
|
{
|
||||||
var profilesRegKey = appRegKey.OpenSubKey(ProfilesRegkey, true);
|
var profilesRegKey = appRegKey.OpenSubKey(PROFILES_REGKEY, true);
|
||||||
if (profilesRegKey == null)
|
if (profilesRegKey == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
@@ -20,8 +21,6 @@ namespace MTApiService
|
|||||||
typeof(MtResponseArrayList), typeof(MtResponseMqlRatesArray),
|
typeof(MtResponseArrayList), typeof(MtResponseMqlRatesArray),
|
||||||
typeof(MtResponseMqlBookInfoArray)};
|
typeof(MtResponseMqlBookInfoArray)};
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract object GetValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -34,13 +33,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int Value { get; private set; }
|
public int Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -53,13 +45,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public long Value { get; private set; }
|
public long Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -72,13 +57,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public ulong Value { get; private set; }
|
public ulong Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -91,13 +69,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public double Value { get; private set; }
|
public double Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString(CultureInfo.CurrentCulture);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -110,13 +81,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Value { get; private set; }
|
public string Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -129,13 +93,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public bool Value { get; private set; }
|
public bool Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -148,13 +105,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public double[] Value { get; private set; }
|
public double[] Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -167,13 +117,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int[] Value { get; private set; }
|
public int[] Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -186,13 +129,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public long[] Value { get; private set; }
|
public long[] Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -205,13 +141,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public ArrayList Value { get; private set; }
|
public ArrayList Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -224,13 +153,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public MtMqlRates[] Value { get; private set; }
|
public MtMqlRates[] Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -243,13 +165,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public MtMqlTick Value { get; private set; }
|
public MtMqlTick Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -262,13 +177,6 @@ namespace MTApiService
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public MtMqlBookInfo[] Value { get; private set; }
|
public MtMqlBookInfo[] Value { get; private set; }
|
||||||
|
|
||||||
public override object GetValue() { return Value; }
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+104
-194
@@ -3,26 +3,17 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.ServiceModel.Channels;
|
using System.ServiceModel.Channels;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
internal class MtServer : IDisposable, IMtApiServer
|
internal class MtServer : IDisposable, IMtApiServer
|
||||||
{
|
{
|
||||||
#region Constants
|
#region Constants
|
||||||
private const int WaitResponseTime = 40000; // 40 sec
|
private const int WAIT_RESPONSE_TIME = 40000; // 40 sec
|
||||||
private const int StopExpertInterval = 1000; // 1 sec
|
private const int STOP_EXPERT_INTERVAL = 1000; // 1 sec
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Fields
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtServer));
|
|
||||||
|
|
||||||
private readonly MtService _service;
|
|
||||||
private readonly List<ServiceHost> _hosts = new List<ServiceHost>();
|
|
||||||
private readonly MtCommandExecutorManager _executorManager = new MtCommandExecutorManager();
|
|
||||||
private readonly List<MtExpert> _experts = new List<MtExpert>();
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ctor
|
#region ctor
|
||||||
@@ -34,126 +25,99 @@ namespace MTApiService
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public int Port { get; }
|
public int Port { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Log.Debug("Start: begin");
|
|
||||||
|
|
||||||
var hostsInitialized = InitHosts(Port);
|
var hostsInitialized = InitHosts(Port);
|
||||||
|
if (hostsInitialized == false)
|
||||||
Log.DebugFormat("Start: end. hostsInitialized = {0}", hostsInitialized);
|
{
|
||||||
|
Debug.WriteLine("Start: InitHosts failed. ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool InitHosts(int port)
|
private bool InitHosts(int port)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("InitHosts: begin. port = {0}", port);
|
|
||||||
|
|
||||||
int count;
|
|
||||||
|
|
||||||
lock (_hosts)
|
lock (_hosts)
|
||||||
{
|
{
|
||||||
if (_hosts.Count > 0)
|
if (_hosts.Count > 0)
|
||||||
{
|
|
||||||
Log.Info("InitHosts: end. Host's has been initialized");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
//init local pipe host
|
//init local pipe host
|
||||||
var localUrl = CreateConnectionAddress(null, port, true);
|
string localUrl = CreateConnectionAddress(null, port, true);
|
||||||
var localServiceHost = CreateServiceHost(localUrl, true);
|
ServiceHost localServiceHost = CreateServiceHost(localUrl, true);
|
||||||
if (localServiceHost != null)
|
if (localServiceHost != null)
|
||||||
{
|
{
|
||||||
_hosts.Add(localServiceHost);
|
_hosts.Add(localServiceHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
//init network hosts
|
//init network hosts
|
||||||
var dnsHostName = Dns.GetHostName();
|
IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());
|
||||||
var ips = Dns.GetHostEntry(dnsHostName);
|
if (ips != null)
|
||||||
if (ips == null)
|
|
||||||
{
|
{
|
||||||
Log.WarnFormat("InitHosts: end. Dns.GetHostEntry has returned null for DNS Host Name {0}", dnsHostName);
|
foreach (IPAddress ipAddress in ips.AddressList)
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var ipAddress in ips.AddressList)
|
|
||||||
{
|
|
||||||
if (ipAddress?.AddressFamily == AddressFamily.InterNetwork)
|
|
||||||
{
|
{
|
||||||
var ip = ipAddress.ToString();
|
if (ipAddress != null)
|
||||||
var networkUrl = CreateConnectionAddress(ip, port, false);
|
|
||||||
var serviceHost = CreateServiceHost(networkUrl, false);
|
|
||||||
if (serviceHost != null)
|
|
||||||
{
|
{
|
||||||
_hosts.Add(serviceHost);
|
if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
|
||||||
|
{
|
||||||
|
string ip = ipAddress.ToString();
|
||||||
|
string networkUrl = CreateConnectionAddress(ip, port, false);
|
||||||
|
ServiceHost serviceHost = CreateServiceHost(networkUrl, false);
|
||||||
|
if (serviceHost != null)
|
||||||
|
{
|
||||||
|
_hosts.Add(serviceHost);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count = _hosts.Count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.DebugFormat("InitHosts: end. Host's count = {0}", count);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceHost CreateServiceHost(string serverUrlAdress, bool local)
|
private ServiceHost CreateServiceHost(string serverUrlAdress, bool local)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("CreateServiceHost: begin. serverUrlAdress = {0}; local = {1}", serverUrlAdress, local);
|
ServiceHost serviceHost = null;
|
||||||
|
if (serverUrlAdress != null)
|
||||||
if (serverUrlAdress == null)
|
|
||||||
{
|
{
|
||||||
Log.Warn("CreateServiceHost: end. serverUrlAdress is not defined");
|
try
|
||||||
return null;
|
{
|
||||||
}
|
serviceHost = new ServiceHost(_service);
|
||||||
|
var binding = CreateConnectionBinding(local);
|
||||||
|
|
||||||
ServiceHost serviceHost;
|
serviceHost.AddServiceEndpoint(typeof(IMtApi), binding, serverUrlAdress);
|
||||||
try
|
serviceHost.Open();
|
||||||
{
|
}
|
||||||
serviceHost = new ServiceHost(_service);
|
catch(Exception e)
|
||||||
var binding = CreateConnectionBinding(local);
|
{
|
||||||
|
Debug.WriteLine("CreateServiceHost: Create ServiceHost failed. " + e.Message);
|
||||||
serviceHost.AddServiceEndpoint(typeof(IMtApi), binding, serverUrlAdress);
|
}
|
||||||
serviceHost.Open();
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
Log.ErrorFormat("CreateServiceHost: Error! {0}", e.Message);
|
|
||||||
serviceHost = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("CreateServiceHost: end.");
|
|
||||||
|
|
||||||
return serviceHost;
|
return serviceHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddExpert(MtExpert expert)
|
public void AddExpert(MtExpert expert)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("AddExpert: begin. expert {0}", expert);
|
if (expert != null)
|
||||||
|
|
||||||
if (expert == null)
|
|
||||||
{
|
{
|
||||||
Log.Warn("AddExpert: end. expert is not defined");
|
expert.Deinited += expert_Deinited;
|
||||||
return;
|
expert.QuoteChanged += expert_QuoteChanged;
|
||||||
|
expert.OnMtEvent += Expert_OnMtEvent;
|
||||||
|
|
||||||
|
lock (_experts)
|
||||||
|
{
|
||||||
|
_experts.Add(expert);
|
||||||
|
}
|
||||||
|
|
||||||
|
_executorManager.AddCommandExecutor(expert);
|
||||||
|
|
||||||
|
_service.OnQuoteAdded(expert.Quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
expert.Deinited += expert_Deinited;
|
|
||||||
expert.QuoteChanged += expert_QuoteChanged;
|
|
||||||
expert.OnMtEvent += Expert_OnMtEvent;
|
|
||||||
|
|
||||||
lock (_experts)
|
|
||||||
{
|
|
||||||
_experts.Add(expert);
|
|
||||||
}
|
|
||||||
|
|
||||||
_executorManager.AddCommandExecutor(expert);
|
|
||||||
|
|
||||||
_service.OnQuoteAdded(expert.Quote);
|
|
||||||
|
|
||||||
Log.Debug("AddExpert: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -162,30 +126,25 @@ namespace MTApiService
|
|||||||
|
|
||||||
public MtResponse SendCommand(MtCommand command)
|
public MtResponse SendCommand(MtCommand command)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendCommand: begin. command {0}", command);
|
MtResponse response = null;
|
||||||
|
|
||||||
if (command == null)
|
if (command != null)
|
||||||
{
|
{
|
||||||
Log.Warn("SendCommand: end. command is not defined");
|
var task = new MtCommandTask(command);
|
||||||
return null;
|
_executorManager.EnqueueCommandTask(task);
|
||||||
|
|
||||||
|
//wait for execute command in MetaTrader
|
||||||
|
response = task.WaitResult(WAIT_RESPONSE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
var task = new MtCommandTask(command);
|
|
||||||
_executorManager.EnqueueCommandTask(task);
|
|
||||||
|
|
||||||
//wait for execute command in MetaTrader
|
|
||||||
var response = task.WaitResult(WaitResponseTime);
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MtQuote> GetQuotes()
|
public IEnumerable<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
Log.Debug("GetQuotes: called");
|
|
||||||
|
|
||||||
lock (_experts)
|
lock (_experts)
|
||||||
{
|
{
|
||||||
return _experts.Select(s => s.Quote).ToList();
|
return (from s in _experts select s.Quote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,131 +153,99 @@ namespace MTApiService
|
|||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void stopTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
private void stopTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("stopTimer_Elapsed: begin");
|
var expertsCount = 0;
|
||||||
|
|
||||||
int expertsCount;
|
|
||||||
|
|
||||||
lock (_experts)
|
lock (_experts)
|
||||||
{
|
{
|
||||||
expertsCount = _experts.Count;
|
expertsCount = _experts.Count();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expertsCount == 0)
|
if (expertsCount == 0)
|
||||||
{
|
{
|
||||||
_service.OnStopServer();
|
_service.OnStopServer();
|
||||||
|
|
||||||
Log.DebugFormat("stopTimer_Elapsed: experts count is 0. Call Stop().");
|
|
||||||
|
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
var stopTimer = sender as System.Timers.Timer;
|
var stopTimer = sender as System.Timers.Timer;
|
||||||
if (stopTimer == null) return;
|
if (stopTimer != null)
|
||||||
|
{
|
||||||
stopTimer.Stop();
|
stopTimer.Stop();
|
||||||
stopTimer.Elapsed -= stopTimer_Elapsed;
|
stopTimer.Elapsed -= stopTimer_Elapsed;
|
||||||
|
}
|
||||||
Log.DebugFormat("stopTimer_Elapsed: end");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CreateConnectionAddress(string host, int port, bool local)
|
private string CreateConnectionAddress(string host, int port, bool local)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("CreateConnectionAddress: begin. host = {0}, port = {1}, local = {2}", host, port, local);
|
|
||||||
|
|
||||||
string connectionAddress = null;
|
string connectionAddress = null;
|
||||||
|
|
||||||
if (local)
|
if (local == true)
|
||||||
{
|
{
|
||||||
//by Pipe
|
//by Pipe
|
||||||
connectionAddress = "net.pipe://localhost/MtApiService_" + port;
|
connectionAddress = "net.pipe://localhost/MtApiService_" + port.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//by Socket
|
//by Socket
|
||||||
if (host != null)
|
if (host != null)
|
||||||
{
|
{
|
||||||
connectionAddress = "net.tcp://" + host + ":" + port + "/MtApiService";
|
connectionAddress = "net.tcp://" + host.ToString() + ":" + port.ToString() + "/MtApiService";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.DebugFormat("CreateConnectionAddress: end. connectionAddress = {0}", connectionAddress);
|
|
||||||
|
|
||||||
return connectionAddress;
|
return connectionAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Binding CreateConnectionBinding(bool local)
|
private static Binding CreateConnectionBinding(bool local)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("CreateConnectionBinding: begin. local = {0}", local);
|
Binding connectionBinding = null;
|
||||||
|
|
||||||
Binding connectionBinding;
|
if (local == true)
|
||||||
|
|
||||||
if (local)
|
|
||||||
{
|
{
|
||||||
//by Pipe
|
//by Pipe
|
||||||
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
|
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
|
||||||
{
|
bind.MaxReceivedMessageSize = 2147483647;
|
||||||
MaxReceivedMessageSize = 2147483647,
|
bind.MaxBufferSize = 2147483647;
|
||||||
MaxBufferSize = 2147483647,
|
|
||||||
MaxBufferPoolSize = 2147483647,
|
|
||||||
SendTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReceiveTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReaderQuotas =
|
|
||||||
{
|
|
||||||
MaxArrayLength = 2147483647,
|
|
||||||
MaxBytesPerRead = 2147483647,
|
|
||||||
MaxDepth = 2147483647,
|
|
||||||
MaxStringContentLength = 2147483647,
|
|
||||||
MaxNameTableCharCount = 2147483647
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Commented next statement since it is not required
|
// Commented next statement since it is not required
|
||||||
|
bind.MaxBufferPoolSize = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxArrayLength = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxBytesPerRead = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxDepth = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxStringContentLength = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxNameTableCharCount = 2147483647;
|
||||||
|
|
||||||
connectionBinding = bind;
|
connectionBinding = bind;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//by Socket
|
//by Socket
|
||||||
var bind = new NetTcpBinding(SecurityMode.None)
|
var bind = new NetTcpBinding(SecurityMode.None);
|
||||||
{
|
bind.MaxReceivedMessageSize = 2147483647;
|
||||||
MaxReceivedMessageSize = 2147483647,
|
bind.MaxBufferSize = 2147483647;
|
||||||
MaxBufferSize = 2147483647,
|
|
||||||
MaxBufferPoolSize = 2147483647,
|
|
||||||
SendTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReceiveTimeout = new TimeSpan(12, 0, 0),
|
|
||||||
ReaderQuotas =
|
|
||||||
{
|
|
||||||
MaxArrayLength = 2147483647,
|
|
||||||
MaxBytesPerRead = 2147483647,
|
|
||||||
MaxDepth = 2147483647,
|
|
||||||
MaxStringContentLength = 2147483647,
|
|
||||||
MaxNameTableCharCount = 2147483647
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Commented next statement since it is not required
|
// Commented next statement since it is not required
|
||||||
|
bind.MaxBufferPoolSize = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxArrayLength = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxBytesPerRead = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxDepth = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxStringContentLength = 2147483647;
|
||||||
|
bind.ReaderQuotas.MaxNameTableCharCount = 2147483647;
|
||||||
|
|
||||||
connectionBinding = bind;
|
connectionBinding = bind;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("CreateConnectionBinding: end.");
|
|
||||||
|
|
||||||
return connectionBinding;
|
return connectionBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Stop()
|
private void Stop()
|
||||||
{
|
{
|
||||||
Log.Debug("Stop: begin.");
|
|
||||||
|
|
||||||
_executorManager.Stop();
|
_executorManager.Stop();
|
||||||
|
|
||||||
lock (_hosts)
|
lock (_hosts)
|
||||||
{
|
{
|
||||||
if (_hosts.Count == 0)
|
if (_hosts.Count == 0)
|
||||||
{
|
|
||||||
Log.Debug("Stop: end. Host count is 0.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -327,18 +254,15 @@ namespace MTApiService
|
|||||||
host.Close();
|
host.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (TimeoutException ex)
|
catch (TimeoutException)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Stop: TimeoutException - {0}", ex.Message);
|
|
||||||
|
|
||||||
foreach (var host in _hosts)
|
foreach (var host in _hosts)
|
||||||
{
|
{
|
||||||
host.Abort();
|
host.Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Stop: Exception - {0}", ex.Message);
|
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -348,27 +272,20 @@ namespace MTApiService
|
|||||||
}
|
}
|
||||||
|
|
||||||
FireOnStopped();
|
FireOnStopped();
|
||||||
|
|
||||||
Log.Debug("Stop: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expert_Deinited(object sender, EventArgs e)
|
private void expert_Deinited(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Log.Debug("expert_Deinited: begin.");
|
if (sender == null)
|
||||||
|
|
||||||
var expert = sender as MtExpert;
|
|
||||||
if (expert == null)
|
|
||||||
{
|
|
||||||
Log.Warn("expert_Deinited: end. Expert is not defined.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
int expertsCount;
|
var expert = (MtExpert)sender;
|
||||||
|
var expertsCount = 0;
|
||||||
|
|
||||||
lock (_experts)
|
lock (_experts)
|
||||||
{
|
{
|
||||||
_experts.Remove(expert);
|
_experts.Remove(expert);
|
||||||
expertsCount = _experts.Count;
|
expertsCount = _experts.Count();
|
||||||
}
|
}
|
||||||
|
|
||||||
_executorManager.RemoveCommandExecutor(expert);
|
_executorManager.RemoveCommandExecutor(expert);
|
||||||
@@ -382,29 +299,19 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
var stopTimer = new System.Timers.Timer();
|
var stopTimer = new System.Timers.Timer();
|
||||||
stopTimer.Elapsed += stopTimer_Elapsed;
|
stopTimer.Elapsed += stopTimer_Elapsed;
|
||||||
stopTimer.Interval = StopExpertInterval;
|
stopTimer.Interval = STOP_EXPERT_INTERVAL;
|
||||||
stopTimer.Start();
|
stopTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("expert_Deinited: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expert_QuoteChanged(MtExpert expert, MtQuote quote)
|
private void expert_QuoteChanged(MtExpert expert, MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("expert_QuoteChanged: begin. expert = {0}, quote = {1}", expert, quote);
|
|
||||||
|
|
||||||
_service.QuoteUpdate(quote);
|
_service.QuoteUpdate(quote);
|
||||||
|
|
||||||
Log.Debug("expert_QuoteChanged: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Expert_OnMtEvent(object sender, MtEventArgs e)
|
private void Expert_OnMtEvent(object sender, MtEventArgs e)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Expert_OnMtEvent: begin. event = {0}", e.Event);
|
|
||||||
|
|
||||||
_service.OnMtEvent(e.Event);
|
_service.OnMtEvent(e.Event);
|
||||||
|
|
||||||
Log.Debug("Expert_OnMtEvent: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FireOnStopped()
|
private void FireOnStopped()
|
||||||
@@ -421,13 +328,16 @@ namespace MTApiService
|
|||||||
#region IDispose
|
#region IDispose
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Log.Debug("Dispose: begin");
|
|
||||||
|
|
||||||
Stop();
|
Stop();
|
||||||
|
|
||||||
Log.Debug("Dispose: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Fields
|
||||||
|
private readonly MtService _service;
|
||||||
|
private readonly List<ServiceHost> _hosts = new List<ServiceHost>();
|
||||||
|
private readonly MtCommandExecutorManager _executorManager = new MtCommandExecutorManager();
|
||||||
|
private readonly List<MtExpert> _experts = new List<MtExpert>();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using log4net;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.ServiceModel;
|
||||||
|
using System.Net;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
public class MtServerInstance
|
public class MtServerInstance
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Init_Instance
|
||||||
private const string LogProfileName = "MtApiService";
|
|
||||||
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtServerInstance));
|
static readonly MtServerInstance mInstance = new MtServerInstance();
|
||||||
private static readonly MtServerInstance Instance = new MtServerInstance();
|
|
||||||
|
|
||||||
private readonly Dictionary<int, MtServer> _servers = new Dictionary<int, MtServer>();
|
|
||||||
private readonly Dictionary<int, MtExpert> _experts = new Dictionary<int, MtExpert>();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Init Instance
|
|
||||||
|
|
||||||
private MtServerInstance()
|
private MtServerInstance()
|
||||||
{
|
{
|
||||||
LogConfigurator.Setup(LogProfileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static MtServerInstance()
|
static MtServerInstance()
|
||||||
@@ -29,7 +24,7 @@ namespace MTApiService
|
|||||||
|
|
||||||
public static MtServerInstance GetInstance()
|
public static MtServerInstance GetInstance()
|
||||||
{
|
{
|
||||||
return Instance;
|
return mInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -38,23 +33,20 @@ namespace MTApiService
|
|||||||
#region Public Methods
|
#region Public Methods
|
||||||
public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
|
public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
|
||||||
{
|
{
|
||||||
if (mtHandler == null)
|
Debug.WriteLine("MtApiServerInstance::InitExpert: symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);
|
||||||
throw new ArgumentNullException(nameof(mtHandler));
|
|
||||||
|
|
||||||
Log.InfoFormat("InitExpert: begin. symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);
|
MtServer server = null;
|
||||||
|
lock (mServersDictionary)
|
||||||
MtServer server;
|
|
||||||
lock (_servers)
|
|
||||||
{
|
{
|
||||||
if (_servers.ContainsKey(port))
|
if (mServersDictionary.ContainsKey(port))
|
||||||
{
|
{
|
||||||
server = _servers[port];
|
server = mServersDictionary[port];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
server = new MtServer(port);
|
server = new MtServer(port);
|
||||||
server.Stopped += server_Stopped;
|
server.Stopped += new EventHandler(server_Stopped);
|
||||||
_servers[port] = server;
|
mServersDictionary[port] = server;
|
||||||
|
|
||||||
server.Start();
|
server.Start();
|
||||||
}
|
}
|
||||||
@@ -62,28 +54,26 @@ namespace MTApiService
|
|||||||
|
|
||||||
var expert = new MtExpert(expertHandle, new MtQuote(symbol, bid, ask), mtHandler);
|
var expert = new MtExpert(expertHandle, new MtQuote(symbol, bid, ask), mtHandler);
|
||||||
|
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
_experts[expert.Handle] = expert;
|
mExpertsDictionary[expert.Handle] = expert;
|
||||||
}
|
}
|
||||||
|
|
||||||
server.AddExpert(expert);
|
server.AddExpert(expert);
|
||||||
|
|
||||||
Log.Info("InitExpert: end");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeinitExpert(int expertHandle)
|
public void DeinitExpert(int expertHandle)
|
||||||
{
|
{
|
||||||
Log.InfoFormat("DeinitExpert: begin. expertHandle = {0}", expertHandle);
|
Debug.WriteLine("MtApiServerInstance::DeinitExpert: expertHandle = {0}", expertHandle);
|
||||||
|
|
||||||
MtExpert expert = null;
|
MtExpert expert = null;
|
||||||
|
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
if (_experts.ContainsKey(expertHandle))
|
if (mExpertsDictionary.ContainsKey(expertHandle) == true)
|
||||||
{
|
{
|
||||||
expert = _experts[expertHandle];
|
expert = mExpertsDictionary[expertHandle];
|
||||||
_experts.Remove(expertHandle);
|
mExpertsDictionary.Remove(expertHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,143 +81,110 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
expert.Deinit();
|
expert.Deinit();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.WarnFormat("DeinitExpert: expert with id {0} has not been found.", expertHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Info("DeinitExpert: end");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendQuote(int expertHandle, string symbol, double bid, double ask)
|
public void SendQuote(int expertHandle, string symbol, double bid, double ask)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendQuote: begin. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);
|
Debug.WriteLine("MtApiServerInstance::SendQuote: enter. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);
|
||||||
|
|
||||||
MtExpert expert;
|
MtExpert expert = null;
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
expert = _experts[expertHandle];
|
expert = mExpertsDictionary[expertHandle];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expert != null)
|
if (expert != null)
|
||||||
{
|
{
|
||||||
expert.Quote = new MtQuote(symbol, bid, ask);
|
expert.Quote = new MtQuote(symbol, bid, ask);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.WarnFormat("SendQuote: expert with id {0} has not been found.", expertHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("SendQuote: end");
|
Debug.WriteLine("MtApiServerInstance::SendQuote: finish.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendEvent(int expertHandle, int eventType, string payload)
|
public void SendEvent(int expertHandle, int eventType, string payload)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendEvent: begin. eventType = {0}, payload = {1}", eventType, payload);
|
Debug.WriteLine("MtApiServerInstance::SendEvent called. eventType = {0}, payload = {1}", eventType, payload);
|
||||||
|
|
||||||
MtExpert expert;
|
MtExpert expert = null;
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
expert = _experts[expertHandle];
|
expert = mExpertsDictionary[expertHandle];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expert != null)
|
if (expert != null)
|
||||||
{
|
{
|
||||||
expert.SendEvent(new MtEvent(eventType, payload));
|
expert.SendEvent(new MtEvent(eventType, payload));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.WarnFormat("SendEvent: expert with id {0} has not been found.", expertHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("SendEvent: end");
|
Debug.WriteLine("MtApiServerInstance::SendEvent: finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendResponse(int expertHandle, MtResponse response)
|
public void SendResponse(int expertHandle, MtResponse response)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendResponse: begin. id = {0}, response = {1}", expertHandle, response);
|
Debug.WriteLine("MtApiServerInstance::SendResponse: id = {0}, response = {1}", expertHandle, response);
|
||||||
|
|
||||||
MtExpert expert;
|
MtExpert expert = null;
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
expert = _experts[expertHandle];
|
expert = mExpertsDictionary[expertHandle];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expert != null)
|
if (expert != null)
|
||||||
{
|
{
|
||||||
expert.SendResponse(response);
|
expert.SendResponse(response);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.WarnFormat("SendResponse: expert with id {0} has not been found.", expertHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("SendResponse: end");
|
Debug.WriteLine("MtApiServerInstance::SendResponse: finish");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetCommandType(int expertHandle)
|
public int GetCommandType(int expertHandle)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("GetCommandType: begin. expertHandle = {0}", expertHandle);
|
Debug.WriteLine("MtApiServerInstance::GetCommandType: expertHandle = {0}", expertHandle);
|
||||||
|
|
||||||
MtExpert expert;
|
MtExpert expert = null;
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
expert = _experts[expertHandle];
|
expert = mExpertsDictionary[expertHandle];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expert == null)
|
return (expert != null) ? expert.GetCommandType() : 0;
|
||||||
{
|
|
||||||
Log.WarnFormat("GetCommandType: expert with id {0} has not been found.", expertHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
var retval = expert?.GetCommandType() ?? 0;
|
|
||||||
|
|
||||||
Log.DebugFormat("GetCommandType: end. retval = {0}", retval);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetCommandParameter(int expertHandle, int index)
|
public object GetCommandParameter(int expertHandle, int index)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("GetCommandParameter: begin. expertHandle = {0}, index = {1}", expertHandle, index);
|
Debug.WriteLine("MtApiServerInstance::GetCommandParameter: expertHandle = {0}, index = {1}", expertHandle, index);
|
||||||
|
|
||||||
MtExpert expert;
|
MtExpert expert = null;
|
||||||
lock (_experts)
|
lock (mExpertsDictionary)
|
||||||
{
|
{
|
||||||
expert = _experts[expertHandle];
|
expert = mExpertsDictionary[expertHandle];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expert == null)
|
return (expert != null) ? expert.GetCommandParameter(index) : null;
|
||||||
{
|
|
||||||
Log.WarnFormat("GetCommandParameter: expert with id {0} has not been found.", expertHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
var retval = expert?.GetCommandParameter(index);
|
|
||||||
|
|
||||||
Log.DebugFormat("GetCommandParameter: end. retval = {0}", retval);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void server_Stopped(object sender, EventArgs e)
|
private void server_Stopped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var server = (MtServer)sender;
|
MtServer server = (MtServer)sender;
|
||||||
server.Stopped -= server_Stopped;
|
server.Stopped -= server_Stopped;
|
||||||
|
|
||||||
var port = server.Port;
|
var port = server.Port;
|
||||||
|
lock (mServersDictionary)
|
||||||
Log.InfoFormat("server_Stopped: port = {0}", port);
|
|
||||||
|
|
||||||
lock (_servers)
|
|
||||||
{
|
{
|
||||||
if (_servers.ContainsKey(port))
|
if (mServersDictionary.ContainsKey(port))
|
||||||
{
|
{
|
||||||
_servers.Remove(port);
|
mServersDictionary.Remove(port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Fields
|
||||||
|
private readonly MtRegistryManager mConnectionManager = new MtRegistryManager();
|
||||||
|
private readonly Dictionary<int, MtServer> mServersDictionary = new Dictionary<int, MtServer>();
|
||||||
|
private readonly Dictionary<int, MtExpert> mExpertsDictionary = new Dictionary<int, MtExpert>();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-99
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
@@ -19,7 +18,7 @@ namespace MTApiService
|
|||||||
MtResponse SendCommand(MtCommand command);
|
MtResponse SendCommand(MtCommand command);
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
List<MtQuote> GetQuotes();
|
IEnumerable<MtQuote> GetQuotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ServiceContract]
|
[ServiceContract]
|
||||||
@@ -47,149 +46,107 @@ namespace MTApiService
|
|||||||
InstanceContextMode = InstanceContextMode.Single)]
|
InstanceContextMode = InstanceContextMode.Single)]
|
||||||
public sealed class MtService : IMtApi
|
public sealed class MtService : IMtApi
|
||||||
{
|
{
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtService));
|
|
||||||
|
|
||||||
public MtService(IMtApiServer serverCallback)
|
public MtService(IMtApiServer serverCallback)
|
||||||
{
|
{
|
||||||
if (serverCallback == null)
|
if (serverCallback == null)
|
||||||
throw new ArgumentNullException(nameof(serverCallback));
|
throw new ArgumentNullException("serverCallback");
|
||||||
|
|
||||||
_server = serverCallback;
|
mServer = serverCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IMtApi
|
#region IMtApi
|
||||||
public bool Connect()
|
public bool Connect()
|
||||||
{
|
{
|
||||||
Log.Debug("Connect: begin");
|
bool connected = false;
|
||||||
|
|
||||||
var callback = OperationContext.Current.GetCallbackChannel<IMtApiCallback>();
|
IMtApiCallback callback = OperationContext.Current.GetCallbackChannel<IMtApiCallback>();
|
||||||
|
|
||||||
if (callback == null)
|
if (callback != null)
|
||||||
{
|
{
|
||||||
Log.Warn("Connect: end. Callback is not definded.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var connected = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_clientsLocker.AcquireWriterLock(10000);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_clientCallbacks.Contains(callback) == false)
|
mClientsLocker.AcquireWriterLock(10000);
|
||||||
_clientCallbacks.Add(callback);
|
|
||||||
|
|
||||||
connected = true;
|
try
|
||||||
|
{
|
||||||
|
if (mClientCallbacks.Contains(callback) == false)
|
||||||
|
mClientCallbacks.Add(callback);
|
||||||
|
|
||||||
|
connected = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mClientsLocker.ReleaseWriterLock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
catch (ApplicationException)
|
||||||
{
|
{
|
||||||
_clientsLocker.ReleaseWriterLock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ApplicationException ex)
|
|
||||||
{
|
|
||||||
Log.ErrorFormat("Connect: ApplicationException - {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.DebugFormat("Connect: end. connected = {0}", connected);
|
|
||||||
|
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
Log.Debug("Disconnect: begin");
|
IMtApiCallback callback = OperationContext.Current.GetCallbackChannel<IMtApiCallback>();
|
||||||
|
|
||||||
var callback = OperationContext.Current.GetCallbackChannel<IMtApiCallback>();
|
if (callback != null)
|
||||||
|
|
||||||
if (callback == null)
|
|
||||||
{
|
{
|
||||||
Log.Warn("Disconnect: end. Callback is not definded.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_clientsLocker.AcquireWriterLock(10000);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_clientCallbacks.Remove(callback);
|
mClientsLocker.AcquireWriterLock(10000);
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_clientsLocker.ReleaseWriterLock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ApplicationException ex)
|
|
||||||
{
|
|
||||||
Log.ErrorFormat("Disconnect: ApplicationException - {0}", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("Disconnect: end.");
|
try
|
||||||
|
{
|
||||||
|
mClientCallbacks.Remove(callback);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mClientsLocker.ReleaseWriterLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ApplicationException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtResponse SendCommand(MtCommand command)
|
public MtResponse SendCommand(MtCommand command)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("SendCommand: called. command = {0}", command);
|
return mServer.SendCommand(command);
|
||||||
|
|
||||||
return _server.SendCommand(command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MtQuote> GetQuotes()
|
public IEnumerable<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
Log.Debug("GetQuotes: called.");
|
return mServer.GetQuotes();
|
||||||
|
|
||||||
return _server.GetQuotes();
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
public void OnStopServer()
|
public void OnStopServer()
|
||||||
{
|
{
|
||||||
Log.Debug("OnStopServer: begin.");
|
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnServerStopped());
|
ExecuteCallbackAction(a => a.OnServerStopped());
|
||||||
|
|
||||||
Log.Debug("OnStopServer: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QuoteUpdate(MtQuote quote)
|
public void QuoteUpdate(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.Debug("QuoteUpdate: begin.");
|
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnQuoteUpdate(quote));
|
ExecuteCallbackAction(a => a.OnQuoteUpdate(quote));
|
||||||
|
|
||||||
Log.Debug("QuoteUpdate: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnQuoteAdded(MtQuote quote)
|
public void OnQuoteAdded(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.Debug("OnQuoteAdded: begin.");
|
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnQuoteAdded(quote));
|
ExecuteCallbackAction(a => a.OnQuoteAdded(quote));
|
||||||
|
|
||||||
Log.Debug("OnQuoteAdded: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnQuoteRemoved(MtQuote quote)
|
public void OnQuoteRemoved(MtQuote quote)
|
||||||
{
|
{
|
||||||
Log.Debug("OnQuoteRemoved: begin.");
|
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnQuoteRemoved(quote));
|
ExecuteCallbackAction(a => a.OnQuoteRemoved(quote));
|
||||||
|
|
||||||
Log.Debug("OnQuoteRemoved: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMtEvent(MtEvent mtEvent)
|
public void OnMtEvent(MtEvent mtEvent)
|
||||||
{
|
{
|
||||||
Log.Debug("OnMtEvent: begin.");
|
|
||||||
|
|
||||||
ExecuteCallbackAction(a => a.OnMtEvent(mtEvent));
|
ExecuteCallbackAction(a => a.OnMtEvent(mtEvent));
|
||||||
|
|
||||||
Log.Debug("OnMtEvent: end.");
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -197,26 +154,22 @@ namespace MTApiService
|
|||||||
|
|
||||||
private void ExecuteCallbackAction(Action<IMtApiCallback> action)
|
private void ExecuteCallbackAction(Action<IMtApiCallback> action)
|
||||||
{
|
{
|
||||||
Log.Debug("ExecuteCallbackAction: begin.");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_clientsLocker.AcquireReaderLock(2000);
|
mClientsLocker.AcquireReaderLock(2000);
|
||||||
|
|
||||||
List<IMtApiCallback> crashedClientCallbacks = null;
|
List<IMtApiCallback> crashedClientCallbacks = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var callback in _clientCallbacks)
|
foreach (var callback in mClientCallbacks)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
action(callback);
|
action(callback);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("ExecuteCallbackAction: Exception - {0}", ex.Message);
|
|
||||||
|
|
||||||
if (crashedClientCallbacks == null)
|
if (crashedClientCallbacks == null)
|
||||||
crashedClientCallbacks = new List<IMtApiCallback>();
|
crashedClientCallbacks = new List<IMtApiCallback>();
|
||||||
|
|
||||||
@@ -226,33 +179,29 @@ namespace MTApiService
|
|||||||
|
|
||||||
if (crashedClientCallbacks != null)
|
if (crashedClientCallbacks != null)
|
||||||
{
|
{
|
||||||
Log.WarnFormat("ExecuteCallbackAction: crashed callback count = {0}", crashedClientCallbacks.Count);
|
|
||||||
|
|
||||||
foreach (var crashedCallback in crashedClientCallbacks)
|
foreach (var crashedCallback in crashedClientCallbacks)
|
||||||
{
|
{
|
||||||
_clientCallbacks.Remove(crashedCallback);
|
mClientCallbacks.Remove(crashedCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_clientsLocker.ReleaseReaderLock();
|
mClientsLocker.ReleaseReaderLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ApplicationException ex)
|
catch (ApplicationException)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("ExecuteCallbackAction: ApplicationException - {0}", ex.Message);
|
//TODO: add logging
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("ExecuteCallbackAction: end.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Fields
|
#region Fields
|
||||||
private readonly IMtApiServer _server;
|
private readonly IMtApiServer mServer;
|
||||||
private readonly List<IMtApiCallback> _clientCallbacks = new List<IMtApiCallback>();
|
private readonly List<IMtApiCallback> mClientCallbacks = new List<IMtApiCallback>();
|
||||||
private readonly ReaderWriterLock _clientsLocker = new ReaderWriterLock();
|
private readonly ReaderWriterLock mClientsLocker = new ReaderWriterLock();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.22.0")]
|
[assembly: AssemblyVersion("1.0.21.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.22.0")]
|
[assembly: AssemblyFileVersion("1.0.21.0")]
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="ILMerge" version="2.13.0307" targetFramework="net40" />
|
|
||||||
<package id="log4net" version="2.0.5" targetFramework="net40" />
|
|
||||||
<package id="MSBuild.ILMerge.Task" version="1.0.5" targetFramework="net40" />
|
|
||||||
</packages>
|
|
||||||
@@ -72,6 +72,7 @@
|
|||||||
<Compile Include="MtOrder.cs" />
|
<Compile Include="MtOrder.cs" />
|
||||||
<Compile Include="MtQuote.cs" />
|
<Compile Include="MtQuote.cs" />
|
||||||
<Compile Include="MtQuoteEventArgs.cs" />
|
<Compile Include="MtQuoteEventArgs.cs" />
|
||||||
|
<Compile Include="MtSession.cs" />
|
||||||
<Compile Include="MtTimeBar.cs" />
|
<Compile Include="MtTimeBar.cs" />
|
||||||
<Compile Include="MtTypes.cs" />
|
<Compile Include="MtTypes.cs" />
|
||||||
<Compile Include="Monitors\TradeMonitor.cs" />
|
<Compile Include="Monitors\TradeMonitor.cs" />
|
||||||
@@ -90,6 +91,7 @@
|
|||||||
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
||||||
<Compile Include="Requests\OrderModifyRequest.cs" />
|
<Compile Include="Requests\OrderModifyRequest.cs" />
|
||||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||||
|
<Compile Include="Requests\SessionRequest.cs" />
|
||||||
<Compile Include="Requests\RequestBase.cs" />
|
<Compile Include="Requests\RequestBase.cs" />
|
||||||
<Compile Include="Requests\RequestType.cs" />
|
<Compile Include="Requests\RequestType.cs" />
|
||||||
<Compile Include="Responses\CopyRatesResponse.cs" />
|
<Compile Include="Responses\CopyRatesResponse.cs" />
|
||||||
@@ -97,6 +99,7 @@
|
|||||||
<Compile Include="Responses\GetOrdersResponse.cs" />
|
<Compile Include="Responses\GetOrdersResponse.cs" />
|
||||||
<Compile Include="Responses\ICustomResponse.cs" />
|
<Compile Include="Responses\ICustomResponse.cs" />
|
||||||
<Compile Include="Responses\OrderSendResponse.cs" />
|
<Compile Include="Responses\OrderSendResponse.cs" />
|
||||||
|
<Compile Include="Responses\SessionResponce.cs" />
|
||||||
<Compile Include="Responses\ResponseBase.cs" />
|
<Compile Include="Responses\ResponseBase.cs" />
|
||||||
<Compile Include="SeriesIdentifier.cs" />
|
<Compile Include="SeriesIdentifier.cs" />
|
||||||
<Compile Include="TimeBarArgs.cs" />
|
<Compile Include="TimeBarArgs.cs" />
|
||||||
|
|||||||
+182
-173
@@ -15,34 +15,25 @@ namespace MtApi
|
|||||||
|
|
||||||
public sealed class MtApiClient
|
public sealed class MtApiClient
|
||||||
{
|
{
|
||||||
private volatile bool _isBacktestingMode;
|
private const int DoubleArrayLimit = 64800;
|
||||||
|
private volatile bool IsBacktestingMode = false;
|
||||||
|
|
||||||
#region MetaTrader Constants
|
#region MetaTrader Constants
|
||||||
|
|
||||||
//Special constant
|
//Special constant
|
||||||
public const int NULL = 0;
|
public const int NULL = 0;
|
||||||
public const int EMPTY = -1;
|
public const int EMPTY = -1;
|
||||||
|
|
||||||
private const string LogProfileName = "MtApiClient";
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Fields
|
|
||||||
private readonly MtClient _client = new MtClient();
|
|
||||||
private readonly object _locker = new object();
|
|
||||||
private MtConnectionState _connectionState = MtConnectionState.Disconnected;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ctor
|
#region ctor
|
||||||
|
|
||||||
public MtApiClient()
|
public MtApiClient()
|
||||||
{
|
{
|
||||||
LogConfigurator.Setup(LogProfileName);
|
_client.QuoteAdded += mClient_QuoteAdded;
|
||||||
|
_client.QuoteRemoved += mClient_QuoteRemoved;
|
||||||
_client.QuoteAdded += _client_QuoteAdded;
|
_client.QuoteUpdated += mClient_QuoteUpdated;
|
||||||
_client.QuoteRemoved += _client_QuoteRemoved;
|
_client.ServerDisconnected += mClient_ServerDisconnected;
|
||||||
_client.QuoteUpdated += _client_QuoteUpdated;
|
_client.ServerFailed += mClient_ServerFailed;
|
||||||
_client.ServerDisconnected += _client_ServerDisconnected;
|
|
||||||
_client.ServerFailed += _client_ServerFailed;
|
|
||||||
_client.MtEventReceived += _client_MtEventReceived;
|
_client.MtEventReceived += _client_MtEventReceived;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -55,8 +46,15 @@ namespace MtApi
|
|||||||
///<param name="port">Port of host connection (default 8222) </param>
|
///<param name="port">Port of host connection (default 8222) </param>
|
||||||
public void BeginConnect(string host, int port)
|
public void BeginConnect(string host, int port)
|
||||||
{
|
{
|
||||||
|
//if (string.IsNullOrEmpty(host) == false && (host.Equals("localhost") || host.Equals("127.0.0.1")))
|
||||||
|
//{
|
||||||
|
// this.BeginConnect(port);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
Action<string, int> connectAction = Connect;
|
Action<string, int> connectAction = Connect;
|
||||||
connectAction.BeginInvoke(host, port, null, null);
|
connectAction.BeginInvoke(host, port, null, null);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -83,12 +81,8 @@ namespace MtApi
|
|||||||
///</summary>
|
///</summary>
|
||||||
public IEnumerable<MtQuote> GetQuotes()
|
public IEnumerable<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
IEnumerable<MTApiService.MtQuote> quotes;
|
var quotes = _client.GetQuotes();
|
||||||
lock (_client)
|
return quotes != null ? (from q in quotes select q.Convert()) : null;
|
||||||
{
|
|
||||||
quotes = _client.GetQuotes();
|
|
||||||
}
|
|
||||||
return quotes?.Select(q => q.Convert());
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -180,7 +174,7 @@ namespace MtApi
|
|||||||
public double OrderOpenPrice(int ticket)
|
public double OrderOpenPrice(int ticket)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { ticket };
|
var commandParameters = new ArrayList { ticket };
|
||||||
var retVal = SendCommand<double>(MtCommandType.OrderOpenPriceByTicket, commandParameters);
|
double retVal = SendCommand<double>(MtCommandType.OrderOpenPriceByTicket, commandParameters);
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
@@ -225,7 +219,7 @@ namespace MtApi
|
|||||||
[Obsolete("OrderType is deprecated, please use GetOrder instead.")]
|
[Obsolete("OrderType is deprecated, please use GetOrder instead.")]
|
||||||
public TradeOperation OrderType()
|
public TradeOperation OrderType()
|
||||||
{
|
{
|
||||||
var retVal = SendCommand<int>(MtCommandType.OrderType, null);
|
int retVal = SendCommand<int>(MtCommandType.OrderType, null);
|
||||||
|
|
||||||
return (TradeOperation)retVal;
|
return (TradeOperation)retVal;
|
||||||
}
|
}
|
||||||
@@ -256,7 +250,7 @@ namespace MtApi
|
|||||||
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration),
|
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration),
|
||||||
ArrowColor = MtApiColorConverter.ConvertToMtColor(arrowColor)
|
ArrowColor = MtApiColorConverter.ConvertToMtColor(arrowColor)
|
||||||
});
|
});
|
||||||
return response?.Ticket ?? -1;
|
return response != null ? response.Ticket : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
||||||
@@ -284,7 +278,7 @@ namespace MtApi
|
|||||||
|
|
||||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit)
|
public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit)
|
||||||
{
|
{
|
||||||
double dPrice;
|
double dPrice = 0;
|
||||||
return double.TryParse(price, out dPrice) ?
|
return double.TryParse(price, out dPrice) ?
|
||||||
OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit, null, 0, DateTime.MinValue, Color.Empty) : 0;
|
OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit, null, 0, DateTime.MinValue, Color.Empty) : 0;
|
||||||
}
|
}
|
||||||
@@ -322,7 +316,7 @@ namespace MtApi
|
|||||||
Comment = comment,
|
Comment = comment,
|
||||||
Magic = magic,
|
Magic = magic,
|
||||||
});
|
});
|
||||||
return response?.Ticket ?? -1;
|
return response != null ? response.Ticket : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -338,7 +332,7 @@ namespace MtApi
|
|||||||
Comment = comment,
|
Comment = comment,
|
||||||
Magic = magic,
|
Magic = magic,
|
||||||
});
|
});
|
||||||
return response?.Ticket ?? -1;
|
return response != null ? response.Ticket : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OrderClose(int ticket, double lots, double price, int slippage, Color color)
|
public bool OrderClose(int ticket, double lots, double price, int slippage, Color color)
|
||||||
@@ -427,7 +421,7 @@ namespace MtApi
|
|||||||
return response != null;
|
return response != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrowColor)
|
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrow_color)
|
||||||
{
|
{
|
||||||
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
||||||
{
|
{
|
||||||
@@ -436,7 +430,7 @@ namespace MtApi
|
|||||||
Stoploss = stoploss,
|
Stoploss = stoploss,
|
||||||
Takeprofit = takeprofit,
|
Takeprofit = takeprofit,
|
||||||
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration),
|
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration),
|
||||||
ArrowColor = MtApiColorConverter.ConvertToMtColor(arrowColor)
|
ArrowColor = MtApiColorConverter.ConvertToMtColor(arrow_color)
|
||||||
});
|
});
|
||||||
return response != null;
|
return response != null;
|
||||||
}
|
}
|
||||||
@@ -488,7 +482,7 @@ namespace MtApi
|
|||||||
public MtOrder GetOrder(int index, OrderSelectMode select, OrderSelectSource pool)
|
public MtOrder GetOrder(int index, OrderSelectMode select, OrderSelectSource pool)
|
||||||
{
|
{
|
||||||
var response = SendRequest<GetOrderResponse>(new GetOrderRequest { Index = index, Select = (int) select, Pool = (int) pool});
|
var response = SendRequest<GetOrderResponse>(new GetOrderRequest { Index = index, Select = (int) select, Pool = (int) pool});
|
||||||
return response?.Order;
|
return response != null ? response.Order : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MtOrder> GetOrders(OrderSelectSource pool)
|
public List<MtOrder> GetOrders(OrderSelectSource pool)
|
||||||
@@ -718,15 +712,15 @@ namespace MtApi
|
|||||||
return SendCommand<bool>(MtCommandType.SendFTP, commandParameters);
|
return SendCommand<bool>(MtCommandType.SendFTP, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SendFTP(string filename, string ftpPath)
|
public bool SendFTP(string filename, string ftp_path)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { filename, ftpPath };
|
var commandParameters = new ArrayList { filename, ftp_path };
|
||||||
return SendCommand<bool>(MtCommandType.SendFTPA, commandParameters);
|
return SendCommand<bool>(MtCommandType.SendFTPA, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendMail(string subject, string someText)
|
public void SendMail(string subject, string some_text)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { subject, someText };
|
var commandParameters = new ArrayList { subject, some_text };
|
||||||
SendCommand<object>(MtCommandType.SendMail, commandParameters);
|
SendCommand<object>(MtCommandType.SendMail, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -894,15 +888,15 @@ namespace MtApi
|
|||||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GlobalVariableSetOnCondition(string name, double value, double checkValue)
|
public bool GlobalVariableSetOnCondition(string name, double value, double check_value)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { name, value, checkValue };
|
var commandParameters = new ArrayList { name, value, check_value };
|
||||||
return SendCommand<bool>(MtCommandType.GlobalVariableSetOnCondition, commandParameters);
|
return SendCommand<bool>(MtCommandType.GlobalVariableSetOnCondition, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GlobalVariablesDeleteAll(string prefixName)
|
public int GlobalVariablesDeleteAll(string prefix_name)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { prefixName };
|
var commandParameters = new ArrayList { prefix_name };
|
||||||
return SendCommand<int>(MtCommandType.GlobalVariableSetOnCondition, commandParameters);
|
return SendCommand<int>(MtCommandType.GlobalVariableSetOnCondition, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,15 +920,15 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iAD, commandParameters);
|
return SendCommand<double>(MtCommandType.iAD, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
public double iAlligator(string symbol, int timeframe, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int ma_method, int applied_price, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, jawPeriod, jawShift, teethPeriod, teethShift, lipsPeriod, lipsShift, maMethod, appliedPrice, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, jaw_period, jaw_shift, teeth_period, teeth_shift, lips_period, lips_shift, ma_method, applied_price, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iAlligator, commandParameters);
|
return SendCommand<double>(MtCommandType.iAlligator, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iADX(string symbol, int timeframe, int period, int appliedPrice, int mode, int shift)
|
public double iADX(string symbol, int timeframe, int period, int applied_price, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, applied_price, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iADX, commandParameters);
|
return SendCommand<double>(MtCommandType.iADX, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -950,50 +944,50 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iAO, commandParameters);
|
return SendCommand<double>(MtCommandType.iAO, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iBearsPower(string symbol, int timeframe, int period, int appliedPrice, int shift)
|
public double iBearsPower(string symbol, int timeframe, int period, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iBearsPower, commandParameters);
|
return SendCommand<double>(MtCommandType.iBearsPower, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iBands(string symbol, int timeframe, int period, int deviation, int bandsShift, int appliedPrice, int mode, int shift)
|
public double iBands(string symbol, int timeframe, int period, int deviation, int bands_shift, int applied_price, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, deviation, bandsShift, appliedPrice, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, deviation, bands_shift, applied_price, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iBands, commandParameters);
|
return SendCommand<double>(MtCommandType.iBands, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iBandsOnArray(double[] array, int total, int period, int deviation, int bandsShift, int mode, int shift)
|
public double iBandsOnArray(double[] array, int total, int period, int deviation, int bands_shift, int mode, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] {});
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(period);
|
commandParameters.Add(period);
|
||||||
commandParameters.Add(deviation);
|
commandParameters.Add(deviation);
|
||||||
commandParameters.Add(bandsShift);
|
commandParameters.Add(bands_shift);
|
||||||
commandParameters.Add(mode);
|
commandParameters.Add(mode);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
|
|
||||||
return SendCommand<double>(MtCommandType.iBandsOnArray, commandParameters);
|
return SendCommand<double>(MtCommandType.iBandsOnArray, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iBullsPower(string symbol, int timeframe, int period, int appliedPrice, int shift)
|
public double iBullsPower(string symbol, int timeframe, int period, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iBullsPower, commandParameters);
|
return SendCommand<double>(MtCommandType.iBullsPower, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iCCI(string symbol, int timeframe, int period, int appliedPrice, int shift)
|
public double iCCI(string symbol, int timeframe, int period, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iCCI, commandParameters);
|
return SendCommand<double>(MtCommandType.iCCI, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iCCIOnArray(double[] array, int total, int period, int shift)
|
public double iCCIOnArray(double[] array, int total, int period, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] { });
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(period);
|
commandParameters.Add(period);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
@@ -1013,7 +1007,7 @@ namespace MtApi
|
|||||||
Params = new ArrayList(parameters),
|
Params = new ArrayList(parameters),
|
||||||
ParamsType = ICustomRequest.ParametersType.Int
|
ParamsType = ICustomRequest.ParametersType.Int
|
||||||
});
|
});
|
||||||
return response?.Value ?? double.NaN;
|
return response != null ? response.Value : double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iCustom(string symbol, int timeframe, string name, double[] parameters, int mode, int shift)
|
public double iCustom(string symbol, int timeframe, string name, double[] parameters, int mode, int shift)
|
||||||
@@ -1028,7 +1022,7 @@ namespace MtApi
|
|||||||
Params = new ArrayList(parameters),
|
Params = new ArrayList(parameters),
|
||||||
ParamsType = ICustomRequest.ParametersType.Double
|
ParamsType = ICustomRequest.ParametersType.Double
|
||||||
});
|
});
|
||||||
return response?.Value ?? double.NaN;
|
return response != null ? response.Value : double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iCustom(string symbol, int timeframe, string name, int mode, int shift)
|
public double iCustom(string symbol, int timeframe, string name, int mode, int shift)
|
||||||
@@ -1041,7 +1035,7 @@ namespace MtApi
|
|||||||
Mode = mode,
|
Mode = mode,
|
||||||
Shift = shift
|
Shift = shift
|
||||||
});
|
});
|
||||||
return response?.Value ?? double.NaN;
|
return response != null ? response.Value : double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iDeMarker(string symbol, int timeframe, int period, int shift)
|
public double iDeMarker(string symbol, int timeframe, int period, int shift)
|
||||||
@@ -1050,21 +1044,21 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iDeMarker, commandParameters);
|
return SendCommand<double>(MtCommandType.iDeMarker, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iEnvelopes(string symbol, int timeframe, int maPeriod, int maMethod, int maShift, int appliedPrice, double deviation, int mode, int shift)
|
public double iEnvelopes(string symbol, int timeframe, int ma_period, int ma_method, int ma_shift, int applied_price, double deviation, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, maPeriod, maMethod, maShift, appliedPrice, deviation, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, ma_period, ma_method, ma_shift, applied_price, deviation, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iEnvelopes, commandParameters);
|
return SendCommand<double>(MtCommandType.iEnvelopes, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iEnvelopesOnArray(double[] array, int total, int maPeriod, int maMethod, int maShift, double deviation, int mode, int shift)
|
public double iEnvelopesOnArray(double[] array, int total, int ma_period, int ma_method, int ma_shift, double deviation, int mode, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] {});
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(maPeriod);
|
commandParameters.Add(ma_period);
|
||||||
commandParameters.Add(maMethod);
|
commandParameters.Add(ma_method);
|
||||||
commandParameters.Add(maShift);
|
commandParameters.Add(ma_shift);
|
||||||
commandParameters.Add(deviation);
|
commandParameters.Add(deviation);
|
||||||
commandParameters.Add(mode);
|
commandParameters.Add(mode);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
@@ -1072,9 +1066,9 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iEnvelopesOnArray, commandParameters);
|
return SendCommand<double>(MtCommandType.iEnvelopesOnArray, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iForce(string symbol, int timeframe, int period, int maMethod, int appliedPrice, int shift)
|
public double iForce(string symbol, int timeframe, int period, int ma_method, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, maMethod, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, ma_method, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iForce, commandParameters);
|
return SendCommand<double>(MtCommandType.iForce, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1084,15 +1078,15 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iFractals, commandParameters);
|
return SendCommand<double>(MtCommandType.iFractals, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
public double iGator(string symbol, int timeframe, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int ma_method, int applied_price, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, jawPeriod, jawShift, teethPeriod, teethShift, lipsPeriod, lipsShift, maMethod, appliedPrice, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, jaw_period, jaw_shift, teeth_period, teeth_shift, lips_period, lips_shift, ma_method, applied_price, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iGator, commandParameters);
|
return SendCommand<double>(MtCommandType.iGator, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iIchimoku(string symbol, int timeframe, int tenkanSen, int kijunSen, int senkouSpanB, int mode, int shift)
|
public double iIchimoku(string symbol, int timeframe, int tenkan_sen, int kijun_sen, int senkou_span_b, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, tenkanSen, kijunSen, senkouSpanB, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, tenkan_sen, kijun_sen, senkou_span_b, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iIchimoku, commandParameters);
|
return SendCommand<double>(MtCommandType.iIchimoku, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1102,17 +1096,17 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iBWMFI, commandParameters);
|
return SendCommand<double>(MtCommandType.iBWMFI, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iMomentum(string symbol, int timeframe, int period, int appliedPrice, int shift)
|
public double iMomentum(string symbol, int timeframe, int period, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iMomentum, commandParameters);
|
return SendCommand<double>(MtCommandType.iMomentum, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iMomentumOnArray(double[] array, int total, int period, int shift)
|
public double iMomentumOnArray(double[] array, int total, int period, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] {});
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(period);
|
commandParameters.Add(period);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
@@ -1126,41 +1120,41 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iMFI, commandParameters);
|
return SendCommand<double>(MtCommandType.iMFI, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iMA(string symbol, int timeframe, int period, int maShift, int maMethod, int appliedPrice, int shift)
|
public double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, maShift, maMethod, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, ma_shift, ma_method, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iMA, commandParameters);
|
return SendCommand<double>(MtCommandType.iMA, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iMAOnArray(double[] array, int total, int period, int maShift, int maMethod, int shift)
|
double iMAOnArray(double[] array, int total, int period, int ma_shift, int ma_method, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] {});
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(period);
|
commandParameters.Add(period);
|
||||||
commandParameters.Add(maShift);
|
commandParameters.Add(ma_shift);
|
||||||
commandParameters.Add(maMethod);
|
commandParameters.Add(ma_method);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
|
|
||||||
return SendCommand<double>(MtCommandType.iMAOnArray, commandParameters);
|
return SendCommand<double>(MtCommandType.iMAOnArray, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iOsMA(string symbol, int timeframe, int fastEmaPeriod, int slowEmaPeriod, int signalPeriod, int appliedPrice, int shift)
|
public double iOsMA(string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, fastEmaPeriod, slowEmaPeriod, signalPeriod, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, fast_ema_period, slow_ema_period, signal_period, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iOsMA, commandParameters);
|
return SendCommand<double>(MtCommandType.iOsMA, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iMACD(string symbol, int timeframe, int fastEmaPeriod, int slowEmaPeriod, int signalPeriod, int appliedPrice, int mode, int shift)
|
public double iMACD(string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, fastEmaPeriod, slowEmaPeriod, signalPeriod, appliedPrice, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, fast_ema_period, slow_ema_period, signal_period, applied_price, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iMACD, commandParameters);
|
return SendCommand<double>(MtCommandType.iMACD, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iOBV(string symbol, int timeframe, int appliedPrice, int shift)
|
public double iOBV(string symbol, int timeframe, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iOBV, commandParameters);
|
return SendCommand<double>(MtCommandType.iOBV, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1170,17 +1164,17 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iSAR, commandParameters);
|
return SendCommand<double>(MtCommandType.iSAR, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iRSI( string symbol, int timeframe, int period, int appliedPrice, int shift)
|
public double iRSI( string symbol, int timeframe, int period, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, period, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, period, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iRSI, commandParameters);
|
return SendCommand<double>(MtCommandType.iRSI, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iRSIOnArray(double[] array, int total, int period, int shift)
|
public double iRSIOnArray(double[] array, int total, int period, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] {});
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(period);
|
commandParameters.Add(period);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
@@ -1194,29 +1188,29 @@ namespace MtApi
|
|||||||
return SendCommand<double>(MtCommandType.iRVI, commandParameters);
|
return SendCommand<double>(MtCommandType.iRVI, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iStdDev(string symbol, int timeframe, int maPeriod, int maShift, int maMethod, int appliedPrice, int shift)
|
public double iStdDev(string symbol, int timeframe, int ma_period, int ma_shift, int ma_method, int applied_price, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, maPeriod, maShift, maMethod, appliedPrice, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, ma_period, ma_shift, ma_method, applied_price, shift };
|
||||||
return SendCommand<double>(MtCommandType.iStdDev, commandParameters);
|
return SendCommand<double>(MtCommandType.iStdDev, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iStdDevOnArray(double[] array, int total, int maPeriod, int maShift, int maMethod, int shift)
|
public double iStdDevOnArray(double[] array, int total, int ma_period, int ma_shift, int ma_method, int shift)
|
||||||
{
|
{
|
||||||
var arraySize = array?.Length ?? 0;
|
int arraySize = array != null ? array.Length : 0;
|
||||||
var commandParameters = new ArrayList { arraySize };
|
var commandParameters = new ArrayList { arraySize };
|
||||||
commandParameters.AddRange(array ?? new double[] {});
|
commandParameters.AddRange(array);
|
||||||
commandParameters.Add(total);
|
commandParameters.Add(total);
|
||||||
commandParameters.Add(maPeriod);
|
commandParameters.Add(ma_period);
|
||||||
commandParameters.Add(maShift);
|
commandParameters.Add(ma_shift);
|
||||||
commandParameters.Add(maMethod);
|
commandParameters.Add(ma_method);
|
||||||
commandParameters.Add(shift);
|
commandParameters.Add(shift);
|
||||||
|
|
||||||
return SendCommand<double>(MtCommandType.iStdDevOnArray, commandParameters);
|
return SendCommand<double>(MtCommandType.iStdDevOnArray, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double iStochastic(string symbol, int timeframe, int pKperiod, int pDperiod, int slowing, int method, int priceField, int mode, int shift)
|
public double iStochastic(string symbol, int timeframe, int pKperiod, int pDperiod, int slowing, int method, int price_field, int mode, int shift)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, timeframe, pKperiod, pDperiod, slowing, method, priceField, mode, shift };
|
var commandParameters = new ArrayList { symbol, timeframe, pKperiod, pDperiod, slowing, method, price_field, mode, shift };
|
||||||
return SendCommand<double>(MtCommandType.iStochastic, commandParameters);
|
return SendCommand<double>(MtCommandType.iStochastic, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1359,7 +1353,7 @@ namespace MtApi
|
|||||||
{
|
{
|
||||||
result = new DateTime[response.Length];
|
result = new DateTime[response.Length];
|
||||||
|
|
||||||
for(var i = 0; i < response.Length; i++)
|
for(int i = 0; i < response.Length; i++)
|
||||||
{
|
{
|
||||||
result[i] = MtApiTimeConverter.ConvertFromMtTime(response[i]);
|
result[i] = MtApiTimeConverter.ConvertFromMtTime(response[i]);
|
||||||
}
|
}
|
||||||
@@ -1373,115 +1367,117 @@ namespace MtApi
|
|||||||
return SendCommand<bool>(MtCommandType.RefreshRates, null);
|
return SendCommand<bool>(MtCommandType.RefreshRates, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MqlRates> CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count)
|
public List<MqlRates> CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count)
|
||||||
{
|
{
|
||||||
var response = SendRequest<CopyRatesResponse>(new CopyRates1Request
|
var response = SendRequest<CopyRatesResponse>(new CopyRates1Request
|
||||||
{
|
{
|
||||||
SymbolName = symbolName,
|
SymbolName = symbol_name,
|
||||||
Timeframe = timeframe,
|
Timeframe = timeframe,
|
||||||
StartPos = startPos,
|
StartPos = start_pos,
|
||||||
Count = count
|
Count = count
|
||||||
});
|
});
|
||||||
return response?.Rates;
|
return response != null ? response.Rates : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MqlRates> CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count)
|
public List<MqlRates> CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count)
|
||||||
{
|
{
|
||||||
var response = SendRequest<CopyRatesResponse>(new CopyRates2Request
|
var response = SendRequest<CopyRatesResponse>(new CopyRates2Request
|
||||||
{
|
{
|
||||||
SymbolName = symbolName,
|
SymbolName = symbol_name,
|
||||||
Timeframe = timeframe,
|
Timeframe = timeframe,
|
||||||
StartTime = MtApiTimeConverter.ConvertToMtTime(startTime),
|
StartTime = MtApiTimeConverter.ConvertToMtTime(start_time),
|
||||||
Count = count
|
Count = count
|
||||||
});
|
});
|
||||||
return response?.Rates;
|
return response != null ? response.Rates : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MqlRates> CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime)
|
public List<MqlRates> CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time)
|
||||||
{
|
{
|
||||||
var response = SendRequest<CopyRatesResponse>(new CopyRates3Request
|
var response = SendRequest<CopyRatesResponse>(new CopyRates3Request
|
||||||
{
|
{
|
||||||
SymbolName = symbolName,
|
SymbolName = symbol_name,
|
||||||
Timeframe = timeframe,
|
Timeframe = timeframe,
|
||||||
StartTime = MtApiTimeConverter.ConvertToMtTime(startTime),
|
StartTime = MtApiTimeConverter.ConvertToMtTime(start_time),
|
||||||
StopTime = MtApiTimeConverter.ConvertToMtTime(stopTime)
|
StopTime = MtApiTimeConverter.ConvertToMtTime(stop_time)
|
||||||
});
|
});
|
||||||
return response?.Rates;
|
return response != null ? response.Rates : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BaBacktestingReady()
|
||||||
|
{
|
||||||
|
SendCommand<object>(MtCommandType.BacktestingReady, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Checkup
|
#region Checkup
|
||||||
public string TerminalInfoString(ENUM_TERMINAL_INFO_STRING propertyId)
|
public string TerminalInfoString(ENUM_TERMINAL_INFO_STRING property_id)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { (int)propertyId };
|
var commandParameters = new ArrayList { (int)property_id };
|
||||||
return SendCommand<string>(MtCommandType.TerminalInfoString, commandParameters);
|
return SendCommand<string>(MtCommandType.TerminalInfoString, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING propId)
|
public string SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING prop_id)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { name, (int)propId };
|
var commandParameters = new ArrayList { name, (int)prop_id };
|
||||||
return SendCommand<string>(MtCommandType.SymbolInfoString, commandParameters); ;
|
return SendCommand<string>(MtCommandType.SymbolInfoString, commandParameters); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MtSession SymbolInfoSession(string symbol, DayOfWeek dayOfWeek, uint index, SessionType type)
|
||||||
|
{
|
||||||
|
var responce = SendRequest<SessionResponce>(new SessionRequest { Symbol = symbol, DayOfWeek = dayOfWeek, SessionIndex = (int)index, SessionType = type });
|
||||||
|
return responce != null ? responce.Session : null;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void Connect(string host, int port)
|
private void Connect(string host, int port)
|
||||||
{
|
{
|
||||||
UpdateConnectionState(MtConnectionState.Connecting, $"Connecting to {host}:{port}");
|
UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to {0}:{1}", host, port));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (_client)
|
_client.Open(host, port);
|
||||||
{
|
_client.Connect();
|
||||||
_client.Open(host, port);
|
|
||||||
_client.Connect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
UpdateConnectionState(MtConnectionState.Failed, $"Failed connection to {host}:{port}. {e.Message}");
|
UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to {0}:{1}. {2}", host, port, e.Message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UpdateConnectionState(MtConnectionState.Connected, $"Connected to {host}:{port}");
|
UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to {0}:{1}", host, port));
|
||||||
OnConnected();
|
OnConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Connect(int port)
|
private void Connect(int port)
|
||||||
{
|
{
|
||||||
UpdateConnectionState(MtConnectionState.Connecting, $"Connecting to 'localhost':{port}");
|
UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to 'localhost':{0}", port));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (_client)
|
_client.Open(port);
|
||||||
{
|
_client.Connect();
|
||||||
_client.Open(port);
|
|
||||||
_client.Connect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
UpdateConnectionState(MtConnectionState.Failed, $"Failed connection to 'localhost':{port}. {e.Message}");
|
UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to 'localhost':{0}. {1}", port, e.Message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UpdateConnectionState(MtConnectionState.Connected, $"Connected to 'localhost':{port}");
|
UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to 'localhost':{0}", port));
|
||||||
OnConnected();
|
OnConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnConnected()
|
private void OnConnected()
|
||||||
{
|
{
|
||||||
_isBacktestingMode = IsTesting();
|
IsBacktestingMode = IsTesting();
|
||||||
if (_isBacktestingMode)
|
if (IsBacktestingMode)
|
||||||
{
|
{
|
||||||
BacktestingReady();
|
BaBacktestingReady();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Disconnect()
|
private void Disconnect()
|
||||||
{
|
{
|
||||||
lock (_client)
|
_client.Disconnect();
|
||||||
{
|
_client.Close();
|
||||||
_client.Disconnect();
|
|
||||||
_client.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateConnectionState(MtConnectionState.Disconnected, "Disconnected");
|
UpdateConnectionState(MtConnectionState.Disconnected, "Disconnected");
|
||||||
}
|
}
|
||||||
@@ -1509,18 +1505,37 @@ namespace MtApi
|
|||||||
MtResponse response;
|
MtResponse response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (_client)
|
response = _client.SendCommand((int)commandType, commandParameters);
|
||||||
{
|
|
||||||
response = _client.SendCommand((int)commandType, commandParameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (CommunicationException ex)
|
catch (CommunicationException ex)
|
||||||
{
|
{
|
||||||
throw new MtConnectionException(ex.Message, ex);
|
throw new MtConnectionException(ex.Message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseValue = response.GetValue();
|
T result = default(T);
|
||||||
return responseValue != null ? (T)responseValue : default(T);
|
|
||||||
|
if (response is MtResponseDouble)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseDouble)response).Value, typeof(T));
|
||||||
|
|
||||||
|
if (response is MtResponseInt)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseInt)response).Value, typeof(T));
|
||||||
|
|
||||||
|
if (response is MtResponseBool)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseBool)response).Value, typeof(T));
|
||||||
|
|
||||||
|
if (response is MtResponseString)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseString)response).Value, typeof(T));
|
||||||
|
|
||||||
|
if (response is MtResponseDoubleArray)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseDoubleArray)response).Value, typeof(T));
|
||||||
|
|
||||||
|
if (response is MtResponseIntArray)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseIntArray)response).Value, typeof(T));
|
||||||
|
|
||||||
|
if (response is MtResponseArrayList)
|
||||||
|
result = (T)Convert.ChangeType(((MtResponseArrayList)response).Value, typeof(T));
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private T SendRequest<T>(RequestBase request) where T : ResponseBase, new()
|
private T SendRequest<T>(RequestBase request) where T : ResponseBase, new()
|
||||||
@@ -1528,7 +1543,7 @@ namespace MtApi
|
|||||||
if (request == null)
|
if (request == null)
|
||||||
return default(T);
|
return default(T);
|
||||||
|
|
||||||
var serializer = JsonConvert.SerializeObject(request, Formatting.None,
|
var serializer = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.None,
|
||||||
new JsonSerializerSettings
|
new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
@@ -1538,10 +1553,7 @@ namespace MtApi
|
|||||||
MtResponseString res;
|
MtResponseString res;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (_client)
|
res = (MtResponseString)_client.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
||||||
{
|
|
||||||
res = (MtResponseString)_client.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (CommunicationException ex)
|
catch (CommunicationException ex)
|
||||||
{
|
{
|
||||||
@@ -1562,11 +1574,11 @@ namespace MtApi
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_QuoteUpdated(MTApiService.MtQuote quote)
|
private void mClient_QuoteUpdated(MTApiService.MtQuote quote)
|
||||||
{
|
{
|
||||||
if (quote != null)
|
if (quote != null)
|
||||||
{
|
{
|
||||||
if (_isBacktestingMode)
|
if (IsBacktestingMode)
|
||||||
{
|
{
|
||||||
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||||
}
|
}
|
||||||
@@ -1577,29 +1589,29 @@ namespace MtApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_ServerDisconnected(object sender, EventArgs e)
|
private void mClient_ServerDisconnected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdateConnectionState(MtConnectionState.Disconnected, "MtApi is disconnected");
|
UpdateConnectionState(MtConnectionState.Disconnected, "MtApi is disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_ServerFailed(object sender, EventArgs e)
|
private void mClient_ServerFailed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdateConnectionState(MtConnectionState.Failed, "Failed connection with MtApi");
|
UpdateConnectionState(MtConnectionState.Failed, "Failed connection with MtApi");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_QuoteRemoved(MTApiService.MtQuote quote)
|
private void mClient_QuoteRemoved(MTApiService.MtQuote quote)
|
||||||
{
|
{
|
||||||
QuoteRemoved.FireEventAsync(this, new MtQuoteEventArgs(quote.Convert()));
|
QuoteRemoved.FireEventAsync(this, new MtQuoteEventArgs(quote.Convert()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_QuoteAdded(MTApiService.MtQuote quote)
|
private void mClient_QuoteAdded(MTApiService.MtQuote quote)
|
||||||
{
|
{
|
||||||
QuoteAdded.FireEventAsync(this, new MtQuoteEventArgs(quote.Convert()));
|
QuoteAdded.FireEventAsync(this, new MtQuoteEventArgs(quote.Convert()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_MtEventReceived(object sender, MtEventArgs e)
|
private void _client_MtEventReceived(object sender, MtEventArgs e)
|
||||||
{
|
{
|
||||||
var eventType = (MtEventTypes) e.Event.EventType;
|
MtEventTypes eventType = (MtEventTypes) e.Event.EventType;
|
||||||
|
|
||||||
switch(eventType)
|
switch(eventType)
|
||||||
{
|
{
|
||||||
@@ -1608,8 +1620,6 @@ namespace MtApi
|
|||||||
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Event.Payload));
|
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Event.Payload));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1618,21 +1628,20 @@ namespace MtApi
|
|||||||
OnLastTimeBar.FireEventAsync(this, new TimeBarArgs(timeBar));
|
OnLastTimeBar.FireEventAsync(this, new TimeBarArgs(timeBar));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BacktestingReady()
|
|
||||||
{
|
|
||||||
SendCommand<object>(MtCommandType.BacktestingReady, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
public event MtApiQuoteHandler QuoteUpdated;
|
public event MtApiQuoteHandler QuoteUpdated;
|
||||||
public event EventHandler<MtQuoteEventArgs> QuoteAdded;
|
public event EventHandler<MtQuoteEventArgs> QuoteAdded;
|
||||||
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
|
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
|
||||||
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
|
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
|
||||||
public event EventHandler<TimeBarArgs> OnLastTimeBar;
|
public event EventHandler<TimeBarArgs> OnLastTimeBar;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Fields
|
||||||
|
private readonly MtClient _client = new MtClient();
|
||||||
|
private readonly object _locker = new object();
|
||||||
|
private MtConnectionState _connectionState = MtConnectionState.Disconnected;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public class MtSession
|
||||||
|
{
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public DayOfWeek DayOfWeek { get; set; }
|
||||||
|
public uint Index { get; set; }
|
||||||
|
public int MtFromTime { get; set; }
|
||||||
|
public DateTime From
|
||||||
|
{
|
||||||
|
get { return MtApiTimeConverter.ConvertFromMtTime(MtFromTime); }
|
||||||
|
}
|
||||||
|
public int MtToTime { get; set; }
|
||||||
|
public DateTime To
|
||||||
|
{
|
||||||
|
get { return MtApiTimeConverter.ConvertFromMtTime(MtToTime); }
|
||||||
|
}
|
||||||
|
public bool HasData { get; set; }
|
||||||
|
public SessionType Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SessionType { Quote, Trade }
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
OrderDelete = 6,
|
OrderDelete = 6,
|
||||||
OrderModify = 7,
|
OrderModify = 7,
|
||||||
iCustom = 8,
|
iCustom = 8,
|
||||||
CopyRates = 9
|
CopyRates = 9,
|
||||||
|
Session = 10,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MtApi.Requests
|
||||||
|
{
|
||||||
|
public 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
|
||||||
|
{
|
||||||
|
get { return RequestType.Session; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace MtApi.Responses
|
||||||
|
{
|
||||||
|
public class SessionResponce : ResponseBase
|
||||||
|
{
|
||||||
|
public MtSession Session { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,28 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
internal static class ExtensionMethods
|
static class ExtensionMethods
|
||||||
{
|
{
|
||||||
#region Event Methods
|
#region Event Methods
|
||||||
public static void FireEvent(this EventHandler eventHandler, object sender)
|
public static void FireEvent(this EventHandler eventHandler, object sender)
|
||||||
{
|
{
|
||||||
eventHandler?.Invoke(sender, EventArgs.Empty);
|
if (eventHandler != null)
|
||||||
|
{
|
||||||
|
eventHandler(sender, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FireEvent<T>(this EventHandler<T> eventHandler, object sender, T e)
|
public static void FireEvent<T>(this EventHandler<T> eventHandler, object sender, T e)
|
||||||
where T : EventArgs
|
where T : EventArgs
|
||||||
{
|
{
|
||||||
eventHandler?.Invoke(sender, e);
|
if (eventHandler != null)
|
||||||
|
{
|
||||||
|
eventHandler(sender, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
+11
-12
@@ -1,4 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
@@ -16,17 +19,13 @@ namespace MtApi5
|
|||||||
this.real_volume = real_volume;
|
this.real_volume = real_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MqlRates()
|
public DateTime time { get; private set; } // Period start time
|
||||||
{
|
public double open { get; private set; } // Open price
|
||||||
}
|
public double high { get; private set; } // The highest price of the period
|
||||||
|
public double low { get; private set; } // The lowest price of the period
|
||||||
public DateTime time { get; set; } // Period start time
|
public double close { get; private set; } // Close price
|
||||||
public double open { get; set; } // Open price
|
public long tick_volume { get; private set; } // Tick volume
|
||||||
public double high { get; set; } // The highest price of the period
|
public int spread { get; private set; } // Spread
|
||||||
public double low { get; set; } // The lowest price of the period
|
public long real_volume { get; private set; } // Trade volume
|
||||||
public double close { get; set; } // Close price
|
|
||||||
public long tick_volume { get; set; } // Tick volume
|
|
||||||
public int spread { get; set; } // Spread
|
|
||||||
public long real_volume { get; set; } // Trade volume
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
@@ -6,7 +8,7 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type
|
public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type
|
||||||
public uint Magic { get; set; } // Expert Advisor ID (magic number)
|
public uint Magic { get; set; } // Expert Advisor ID (magic number)
|
||||||
public ulong Order { get; set; } // Order ticket
|
public uint 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 Volume { get; set; } // Requested volume for a deal in lots
|
||||||
public double Price { get; set; } // Price
|
public double Price { get; set; } // Price
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.ServiceModel" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
@@ -56,7 +55,7 @@
|
|||||||
<Compile Include="MqlTradeResult.cs" />
|
<Compile Include="MqlTradeResult.cs" />
|
||||||
<Compile Include="Mt5QuoteEventArgs.cs" />
|
<Compile Include="Mt5QuoteEventArgs.cs" />
|
||||||
<Compile Include="MtApi5Client.cs" />
|
<Compile Include="MtApi5Client.cs" />
|
||||||
<Compile Include="Mt5CommandType.cs" />
|
<Compile Include="MtCommandType.cs" />
|
||||||
<Compile Include="MtConverters.cs" />
|
<Compile Include="MtConverters.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Mt5Quote.cs" />
|
<Compile Include="Mt5Quote.cs" />
|
||||||
|
|||||||
+493
-533
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
internal enum Mt5CommandType
|
enum Mt5CommandType
|
||||||
{
|
{
|
||||||
//NoCommand = 0
|
//NoCommand = 0
|
||||||
|
|
||||||
@@ -101,15 +101,6 @@ namespace MtApi5
|
|||||||
MarketBookRelease = 61,
|
MarketBookRelease = 61,
|
||||||
MarketBookGet = 62,
|
MarketBookGet = 62,
|
||||||
OrderCloseAll = 63,
|
OrderCloseAll = 63,
|
||||||
|
PositionClose = 64
|
||||||
//CTrade
|
|
||||||
PositionClose = 64,
|
|
||||||
PositionOpen = 65,
|
|
||||||
|
|
||||||
//Backtesting
|
|
||||||
BacktestingReady = 66,
|
|
||||||
IsTesting = 67,
|
|
||||||
|
|
||||||
Print = 68
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+33
-30
@@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using MTApiService;
|
using MTApiService;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
internal static class MtConverters
|
static class MtConverters
|
||||||
{
|
{
|
||||||
#region Values Converters
|
#region Values Converters
|
||||||
public static Mt5Quote Parse(this MtQuote quote)
|
public static Mt5Quote Parse(this MtQuote quote)
|
||||||
@@ -14,29 +17,29 @@ namespace MtApi5
|
|||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
||||||
{
|
{
|
||||||
var retVal = false;
|
bool retVal = false;
|
||||||
result = null;
|
result = null;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
if (string.IsNullOrEmpty(inputString) == false)
|
||||||
{
|
{
|
||||||
var values = inputString.Split(separator);
|
string[] values = inputString.Split(separator);
|
||||||
if (values.Length == 10)
|
if (values.Length == 10)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
retVal = int.Parse(values[0]) != 0;
|
retVal = int.Parse(values[0]) != 0;
|
||||||
|
|
||||||
var retcode = uint.Parse(values[1]);
|
uint retcode = uint.Parse(values[1]);
|
||||||
var deal = ulong.Parse(values[2]);
|
ulong deal = ulong.Parse(values[2]);
|
||||||
var order = ulong.Parse(values[3]);
|
ulong order = ulong.Parse(values[3]);
|
||||||
var volume = double.Parse(values[4]);
|
double volume = double.Parse(values[4]);
|
||||||
var price = double.Parse(values[5]);
|
double price = double.Parse(values[5]);
|
||||||
var bid = double.Parse(values[6]);
|
double bid = double.Parse(values[6]);
|
||||||
var ask = double.Parse(values[7]);
|
double ask = double.Parse(values[7]);
|
||||||
var comment = values[8];
|
string comment = values[8];
|
||||||
var requestId = uint.Parse(values[9]);
|
uint request_id = uint.Parse(values[9]);
|
||||||
|
|
||||||
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, request_id);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -49,28 +52,28 @@ namespace MtApi5
|
|||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
||||||
{
|
{
|
||||||
var retVal = false;
|
bool retVal = false;
|
||||||
result = null;
|
result = null;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
if (string.IsNullOrEmpty(inputString) == false)
|
||||||
{
|
{
|
||||||
var values = inputString.Split(separator);
|
string[] values = inputString.Split(separator);
|
||||||
if (values.Length == 10)
|
if (values.Length == 10)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
retVal = int.Parse(values[0]) != 0;
|
retVal = int.Parse(values[0]) != 0;
|
||||||
|
|
||||||
var retcode = uint.Parse(values[1]);
|
uint retcode = uint.Parse(values[1]);
|
||||||
var balance = double.Parse(values[2]);
|
double balance = double.Parse(values[2]);
|
||||||
var equity = double.Parse(values[3]);
|
double equity = double.Parse(values[3]);
|
||||||
var profit = double.Parse(values[4]);
|
double profit = double.Parse(values[4]);
|
||||||
var margin = double.Parse(values[5]);
|
double margin = double.Parse(values[5]);
|
||||||
var marginFree = double.Parse(values[6]);
|
double margin_free = double.Parse(values[6]);
|
||||||
var marginLevel = double.Parse(values[7]);
|
double margin_level = double.Parse(values[7]);
|
||||||
var comment = values[8];
|
string comment = values[8];
|
||||||
|
|
||||||
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, margin_free, margin_level, comment);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -84,7 +87,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out double result)
|
public static bool ParseResult(this string inputString, char separator, out double result)
|
||||||
{
|
{
|
||||||
var retVal = false;
|
bool retVal = false;
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
if (string.IsNullOrEmpty(inputString) == false)
|
||||||
@@ -110,24 +113,24 @@ namespace MtApi5
|
|||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
||||||
{
|
{
|
||||||
var retVal = false;
|
bool retVal = false;
|
||||||
|
|
||||||
from = new DateTime();
|
from = new DateTime();
|
||||||
to = new DateTime();
|
to = new DateTime();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
if (string.IsNullOrEmpty(inputString) == false)
|
||||||
{
|
{
|
||||||
var values = inputString.Split(separator);
|
string[] values = inputString.Split(separator);
|
||||||
if (values.Length == 3)
|
if (values.Length == 3)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
retVal = int.Parse(values[0]) != 0;
|
retVal = int.Parse(values[0]) != 0;
|
||||||
|
|
||||||
var iFrom = int.Parse(values[1]);
|
int iFrom = int.Parse(values[1]);
|
||||||
from = Mt5TimeConverter.ConvertFromMtTime(iFrom);
|
from = Mt5TimeConverter.ConvertFromMtTime(iFrom);
|
||||||
|
|
||||||
var iTo= int.Parse(values[2]);
|
int iTo= int.Parse(values[2]);
|
||||||
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -145,7 +148,7 @@ namespace MtApi5
|
|||||||
if (request == null)
|
if (request == null)
|
||||||
throw new ArgumentNullException();
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
var exp = Mt5TimeConverter.ConvertToMtTime(request.Expiration);
|
int exp = Mt5TimeConverter.ConvertToMtTime(request.Expiration);
|
||||||
|
|
||||||
return new ArrayList { (int)request.Action, request.Magic, request.Order, request.Symbol, request.Volume
|
return new ArrayList { (int)request.Action, request.Magic, request.Order, request.Symbol, request.Volume
|
||||||
, request.Price, request.Stoplimit, request.Sl, request.Tp, request.Deviation, (int)request.Type
|
, request.Price, request.Stoplimit, request.Sl, request.Tp, request.Deviation, (int)request.Type
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ MTApiService library should be placed in Windows GAC (Global Assembly Cache). In
|
|||||||
|
|
||||||
# How to build solution
|
# How to build solution
|
||||||
The project is supported by Visual Studio 2015.
|
The project is supported by Visual Studio 2015.
|
||||||
It also requires WIX Tools (http://wixtoolset.org/).
|
To build solution you need to update sign key file in MtApiService project:
|
||||||
|
- open properties of MTApiService project;
|
||||||
|
- go to tab Signing and select item MtApiKey.pfx;
|
||||||
|
- input password "MtApiService".
|
||||||
To make api for MetaTrader4 use MtApiInstaller and for MetaTrader5 use MtApi5Installer.
|
To make api for MetaTrader4 use MtApiInstaller and for MetaTrader5 use MtApi5Installer.
|
||||||
All installers will be placed in folder "[root]\build\installers\" and all *.dll files will be placed in "[root]\build\products\".
|
All installers will be placed in folder "[root]\build\installers\" and all *.dll files will be placed in "[root]\build\products\".
|
||||||
MQL files have been build to ex4 and stored into folders "mq4" for MetaTrader and "mq5" for MetaTrader5. They are ready to using in terminals.
|
MQL files have been build to ex4 and stored into folders "mq4" for MetaTrader and "mq5" for MetaTrader5. They are ready to using in terminals.
|
||||||
|
|||||||
@@ -1,115 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
|
|
||||||
namespace MtApi5TestClient
|
|
||||||
{
|
|
||||||
internal class ListBoxBehavior
|
|
||||||
{
|
|
||||||
static readonly Dictionary<ListBox, Capture> Associations =
|
|
||||||
new Dictionary<ListBox, Capture>();
|
|
||||||
|
|
||||||
public static bool GetScrollOnNewItem(DependencyObject obj)
|
|
||||||
{
|
|
||||||
return (bool)obj.GetValue(ScrollOnNewItemProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetScrollOnNewItem(DependencyObject obj, bool value)
|
|
||||||
{
|
|
||||||
obj.SetValue(ScrollOnNewItemProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly DependencyProperty ScrollOnNewItemProperty =
|
|
||||||
DependencyProperty.RegisterAttached(
|
|
||||||
"ScrollOnNewItem",
|
|
||||||
typeof(bool),
|
|
||||||
typeof(ListBoxBehavior),
|
|
||||||
new UIPropertyMetadata(false, OnScrollOnNewItemChanged));
|
|
||||||
|
|
||||||
public static void OnScrollOnNewItemChanged(
|
|
||||||
DependencyObject d,
|
|
||||||
DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
var listBox = d as ListBox;
|
|
||||||
if (listBox == null) return;
|
|
||||||
bool oldValue = (bool)e.OldValue, newValue = (bool)e.NewValue;
|
|
||||||
if (newValue == oldValue) return;
|
|
||||||
if (newValue)
|
|
||||||
{
|
|
||||||
listBox.Loaded += ListBox_Loaded;
|
|
||||||
listBox.Unloaded += ListBox_Unloaded;
|
|
||||||
var itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];
|
|
||||||
itemsSourcePropertyDescriptor.AddValueChanged(listBox, ListBox_ItemsSourceChanged);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
listBox.Loaded -= ListBox_Loaded;
|
|
||||||
listBox.Unloaded -= ListBox_Unloaded;
|
|
||||||
if (Associations.ContainsKey(listBox))
|
|
||||||
Associations[listBox].Dispose();
|
|
||||||
var itemsSourcePropertyDescriptor = TypeDescriptor.GetProperties(listBox)["ItemsSource"];
|
|
||||||
itemsSourcePropertyDescriptor.RemoveValueChanged(listBox, ListBox_ItemsSourceChanged);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ListBox_ItemsSourceChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var listBox = (ListBox)sender;
|
|
||||||
if (Associations.ContainsKey(listBox))
|
|
||||||
Associations[listBox].Dispose();
|
|
||||||
Associations[listBox] = new Capture(listBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ListBox_Unloaded(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
var listBox = (ListBox)sender;
|
|
||||||
if (Associations.ContainsKey(listBox))
|
|
||||||
Associations[listBox].Dispose();
|
|
||||||
listBox.Unloaded -= ListBox_Unloaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ListBox_Loaded(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
var listBox = (ListBox)sender;
|
|
||||||
var incc = listBox.Items as INotifyCollectionChanged;
|
|
||||||
if (incc == null) return;
|
|
||||||
listBox.Loaded -= ListBox_Loaded;
|
|
||||||
Associations[listBox] = new Capture(listBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
class Capture : IDisposable
|
|
||||||
{
|
|
||||||
private readonly ListBox listBox;
|
|
||||||
private readonly INotifyCollectionChanged incc;
|
|
||||||
|
|
||||||
public Capture(ListBox listBox)
|
|
||||||
{
|
|
||||||
this.listBox = listBox;
|
|
||||||
incc = listBox.ItemsSource as INotifyCollectionChanged;
|
|
||||||
if (incc != null)
|
|
||||||
{
|
|
||||||
incc.CollectionChanged += incc_CollectionChanged;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void incc_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Action == NotifyCollectionChangedAction.Add)
|
|
||||||
{
|
|
||||||
listBox.ScrollIntoView(e.NewItems[0]);
|
|
||||||
listBox.SelectedItem = e.NewItems[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (incc != null)
|
|
||||||
incc.CollectionChanged -= incc_CollectionChanged;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Executable → Regular
+15
-38
@@ -3,7 +3,6 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
||||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||||
xmlns:mtApi5TestClient="clr-namespace:MtApi5TestClient"
|
|
||||||
Title="MainWindow" Height="700" Width="650"
|
Title="MainWindow" Height="700" Width="650"
|
||||||
Closing="Window_Closing">
|
Closing="Window_Closing">
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
@@ -263,52 +262,36 @@
|
|||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Account Information">
|
<TabItem Header="Account Information">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="0.4*"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid Grid.Row="0" Margin="10">
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="0.4*"/>
|
|
||||||
<ColumnDefinition Width="*"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<ComboBox Grid.Column="0" Grid.Row="0"
|
<ComboBox Grid.Column="0" Grid.Row="0"
|
||||||
SelectedItem="{Binding AccountInfoDoublePropertyId}"
|
SelectedItem="{Binding AccountInfoDoublePropertyId}"
|
||||||
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_DOUBLE_Key}}"/>
|
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_DOUBLE_Key}}"/>
|
||||||
<Button Grid.Column="1" Grid.Row="0" Margin="10,0,0,0"
|
<Button Grid.Column="1" Grid.Row="0" Margin="10,0,0,0"
|
||||||
Command="{Binding AccountInfoDoubleCommand}"
|
Command="{Binding AccountInfoDoubleCommand}"
|
||||||
Content="AccountInfoDouble" HorizontalAlignment="Left" />
|
Content="AccountInfoDouble" HorizontalAlignment="Left" />
|
||||||
|
|
||||||
<ComboBox Grid.Column="0" Grid.Row="1"
|
<ComboBox Grid.Column="0" Grid.Row="1"
|
||||||
SelectedItem="{Binding AccountInfoIntegerPropertyId}"
|
SelectedItem="{Binding AccountInfoIntegerPropertyId}"
|
||||||
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_INTEGER_Key}}"/>
|
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_INTEGER_Key}}"/>
|
||||||
<Button Grid.Column="1" Grid.Row="1" Margin="10,0,0,0"
|
<Button Grid.Column="1" Grid.Row="1" Margin="10,0,0,0"
|
||||||
Command="{Binding AccountInfoIntegerCommand}"
|
Command="{Binding AccountInfoIntegerCommand}"
|
||||||
Content="AccountInfoInteger" HorizontalAlignment="Left" />
|
Content="AccountInfoInteger" HorizontalAlignment="Left" />
|
||||||
|
|
||||||
<ComboBox Grid.Column="0" Grid.Row="2"
|
<ComboBox Grid.Column="0" Grid.Row="2"
|
||||||
SelectedItem="{Binding AccountInfoStringPropertyId}"
|
SelectedItem="{Binding AccountInfoStringPropertyId}"
|
||||||
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_STRING_Key}}"/>
|
ItemsSource="{Binding Source={StaticResource ENUM_ACCOUNT_INFO_STRING_Key}}"/>
|
||||||
<Button Grid.Column="1" Grid.Row="2" Margin="10,0,0,0"
|
<Button Grid.Column="1" Grid.Row="2" Margin="10,0,0,0"
|
||||||
Command="{Binding AccountInfoStringCommand}"
|
Command="{Binding AccountInfoStringCommand}"
|
||||||
Content="AccountInfoString" HorizontalAlignment="Left" />
|
Content="AccountInfoString" HorizontalAlignment="Left" />
|
||||||
</Grid>
|
|
||||||
<Grid Margin="10" Grid.Row="1">
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="*"/>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
|
|
||||||
<TextBox Grid.Column="0" Text="{Binding MessageText}" Margin="5"/>
|
|
||||||
<Button Grid.Column="1" Content="Print" Command="{Binding PrintCommand}" Margin="5"/>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
@@ -333,9 +316,9 @@
|
|||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<TextBox Grid.Row="0" Text="symbolName"/>
|
<TextBox Grid.Row="0" Text="symbol_name"/>
|
||||||
<TextBox Grid.Row="1" Text="timeframe"/>
|
<TextBox Grid.Row="1" Text="timeframe"/>
|
||||||
<TextBox Grid.Row="2" Text="startPos"/>
|
<TextBox Grid.Row="2" Text="start_pos"/>
|
||||||
<TextBox Grid.Row="3" Text="count"/>
|
<TextBox Grid.Row="3" Text="count"/>
|
||||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}"/>
|
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}"/>
|
||||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
<ComboBox Grid.Row="1" Grid.Column="1"
|
||||||
@@ -372,7 +355,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="Market Info">
|
<TabItem Header=" Market Info">
|
||||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
<Button Command="{Binding SymbolsTotalCommand}" Content="SymbolsTotal" Margin="2"/>
|
<Button Command="{Binding SymbolsTotalCommand}" Content="SymbolsTotal" Margin="2"/>
|
||||||
<Button Command="{Binding SymbolNameCommand}" Content="SymbolName" Margin="2"/>
|
<Button Command="{Binding SymbolNameCommand}" Content="SymbolName" Margin="2"/>
|
||||||
@@ -389,16 +372,10 @@
|
|||||||
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
|
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="CTrade">
|
|
||||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
|
||||||
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
|
||||||
</WrapPanel>
|
|
||||||
</TabItem>
|
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|
||||||
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
||||||
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="200" ItemsSource="{Binding History}"/>
|
<ListBox Height="200" ItemsSource="{Binding History}"/>
|
||||||
</Expander>
|
</Expander>
|
||||||
|
|
||||||
<StatusBar Grid.Row="3">
|
<StatusBar Grid.Row="3">
|
||||||
|
|||||||
Executable → Regular
Executable → Regular
+1
-1
@@ -39,7 +39,7 @@ namespace MtApi5TestClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ulong Order
|
public uint Order
|
||||||
{
|
{
|
||||||
get { return TradeRequest.Order; }
|
get { return TradeRequest.Order; }
|
||||||
set
|
set
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
@@ -10,9 +10,8 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>MtApi5TestClient</RootNamespace>
|
<RootNamespace>MtApi5TestClient</RootNamespace>
|
||||||
<AssemblyName>MtApi5TestClient</AssemblyName>
|
<AssemblyName>MtApi5TestClient</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<TargetFrameworkProfile>
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
</TargetFrameworkProfile>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
@@ -26,7 +25,6 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
@@ -36,7 +34,6 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -53,7 +50,6 @@
|
|||||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
@@ -71,7 +67,6 @@
|
|||||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||||
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
|
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
@@ -102,7 +97,6 @@
|
|||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="DelegateCommand.cs" />
|
<Compile Include="DelegateCommand.cs" />
|
||||||
<Compile Include="ListBoxBehavior.cs" />
|
|
||||||
<Compile Include="MainWindow.xaml.cs">
|
<Compile Include="MainWindow.xaml.cs">
|
||||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
@@ -130,7 +124,6 @@
|
|||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Include="app.config" />
|
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|||||||
+19
-11
@@ -1,15 +1,15 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.42000
|
// Runtime Version:4.0.30319.18034
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace MtApi5TestClient.Properties {
|
namespace MtApi5TestClient.Properties
|
||||||
using System;
|
{
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -22,23 +22,28 @@ namespace MtApi5TestClient.Properties {
|
|||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
internal class Resources
|
||||||
|
{
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
internal Resources() {
|
internal Resources()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
internal static global::System.Resources.ResourceManager ResourceManager
|
||||||
get {
|
{
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
get
|
||||||
|
{
|
||||||
|
if ((resourceMan == null))
|
||||||
|
{
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MtApi5TestClient.Properties.Resources", typeof(Resources).Assembly);
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MtApi5TestClient.Properties.Resources", typeof(Resources).Assembly);
|
||||||
resourceMan = temp;
|
resourceMan = temp;
|
||||||
}
|
}
|
||||||
@@ -51,11 +56,14 @@ namespace MtApi5TestClient.Properties {
|
|||||||
/// resource lookups using this strongly typed resource class.
|
/// resource lookups using this strongly typed resource class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
internal static global::System.Globalization.CultureInfo Culture {
|
internal static global::System.Globalization.CultureInfo Culture
|
||||||
get {
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
return resourceCulture;
|
return resourceCulture;
|
||||||
}
|
}
|
||||||
set {
|
set
|
||||||
|
{
|
||||||
resourceCulture = value;
|
resourceCulture = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-6
@@ -1,24 +1,28 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.42000
|
// Runtime Version:4.0.30319.18034
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace MtApi5TestClient.Properties {
|
namespace MtApi5TestClient.Properties
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||||
|
{
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|
||||||
public static Settings Default {
|
public static Settings Default
|
||||||
get {
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+351
-510
File diff suppressed because it is too large
Load Diff
@@ -1,3 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
|
|
||||||
@@ -837,7 +837,7 @@ namespace TestApiClientUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
//OrderSend
|
//OrderSend
|
||||||
private async void button1_Click(object sender, EventArgs e)
|
private void button1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var symbol = textBoxOrderSymbol.Text;
|
var symbol = textBoxOrderSymbol.Text;
|
||||||
|
|
||||||
@@ -878,7 +878,7 @@ namespace TestApiClientUI
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ticket = await Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));
|
var ticket = Execute(() => _apiClient.OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));
|
||||||
|
|
||||||
AddToLog(string.Format("Sended order result: ticket = {0}", ticket));
|
AddToLog(string.Format("Sended order result: ticket = {0}", ticket));
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
-111
@@ -43,8 +43,6 @@ int ExpertHandle;
|
|||||||
string message;
|
string message;
|
||||||
bool isCrashed = false;
|
bool isCrashed = false;
|
||||||
|
|
||||||
bool IsRemoteReadyForTesting = false;
|
|
||||||
|
|
||||||
string symbolValue;
|
string symbolValue;
|
||||||
string commentValue;
|
string commentValue;
|
||||||
|
|
||||||
@@ -56,12 +54,6 @@ int OnInit()
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
double OnTester()
|
|
||||||
{
|
|
||||||
Print("OnTester");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnDeinit(const int reason)
|
void OnDeinit(const int reason)
|
||||||
{
|
{
|
||||||
deinit();
|
deinit();
|
||||||
@@ -89,12 +81,6 @@ bool IsDemo()
|
|||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsTesting()
|
|
||||||
{
|
|
||||||
bool isTesting = MQLInfoInteger(MQL_TESTER);
|
|
||||||
return isTesting;
|
|
||||||
}
|
|
||||||
|
|
||||||
int init()
|
int init()
|
||||||
{
|
{
|
||||||
preinit();
|
preinit();
|
||||||
@@ -140,30 +126,6 @@ int init()
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintFormat("Expert Handle = %d", ExpertHandle);
|
|
||||||
|
|
||||||
//--- Backtesting mode
|
|
||||||
if (false)
|
|
||||||
{
|
|
||||||
if (IsTesting())
|
|
||||||
{
|
|
||||||
Print("Waiting on remote client...");
|
|
||||||
//wait for command (BacktestingReady) from remote side to be ready for work
|
|
||||||
while(!IsRemoteReadyForTesting)
|
|
||||||
{
|
|
||||||
executeCommand();
|
|
||||||
|
|
||||||
//This section uses a while loop to simulate Sleep() during Backtest.
|
|
||||||
unsigned int viSleepUntilTick = GetTickCount() + 100; //100 milliseconds
|
|
||||||
while(GetTickCount() < viSleepUntilTick)
|
|
||||||
{
|
|
||||||
//Do absolutely nothing. Just loop until the desired tick is reached.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//---
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +139,6 @@ int deinit()
|
|||||||
isCrashed = true;
|
isCrashed = true;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
Print("Expert was deinitialized.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@@ -217,15 +178,9 @@ int executeCommand()
|
|||||||
|
|
||||||
if (!getCommandType(ExpertHandle, commandType))
|
if (!getCommandType(ExpertHandle, commandType))
|
||||||
{
|
{
|
||||||
Print("[ERROR] getCommandType");
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandType > 0)
|
|
||||||
{
|
|
||||||
Print("executeCommand: commnad type = ", commandType);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (commandType)
|
switch (commandType)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -254,7 +209,6 @@ int executeCommand()
|
|||||||
sendBooleanResponse(ExpertHandle, retVal);
|
sendBooleanResponse(ExpertHandle, retVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 64: //PositionClose
|
case 64: //PositionClose
|
||||||
{
|
{
|
||||||
int ticket;
|
int ticket;
|
||||||
@@ -1640,71 +1594,6 @@ int executeCommand()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 65: //PositionOpen
|
|
||||||
{
|
|
||||||
string symbol;
|
|
||||||
StringInit(symbol, 50, 0);
|
|
||||||
ENUM_ORDER_TYPE order_type;
|
|
||||||
double volume;
|
|
||||||
double price;
|
|
||||||
double sl;
|
|
||||||
double tp;
|
|
||||||
string comment;
|
|
||||||
StringInit(comment, 1000, 0);
|
|
||||||
|
|
||||||
getStringValue(ExpertHandle, 0, symbol);
|
|
||||||
int order_type_int = 0;
|
|
||||||
getIntValue(ExpertHandle, 1, order_type_int);
|
|
||||||
order_type = (ENUM_ORDER_TYPE) order_type_int;
|
|
||||||
getDoubleValue(ExpertHandle, 2, volume);
|
|
||||||
getDoubleValue(ExpertHandle, 3, price);
|
|
||||||
getDoubleValue(ExpertHandle, 4, sl);
|
|
||||||
getDoubleValue(ExpertHandle, 5, tp);
|
|
||||||
getStringValue(ExpertHandle, 6, comment);
|
|
||||||
|
|
||||||
PrintFormat("command PositionOpen: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
|
||||||
symbol, order_type, volume, price, sl, tp, comment);
|
|
||||||
|
|
||||||
CTrade trade;
|
|
||||||
bool result = trade.PositionOpen(symbol, order_type, volume, price, sl, tp, comment);
|
|
||||||
sendBooleanResponse(ExpertHandle, result);
|
|
||||||
Print("command PositionOpen: result = ", result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 66: //BacktestingReady
|
|
||||||
{
|
|
||||||
if (IsTesting())
|
|
||||||
{
|
|
||||||
Print("Remote client is ready for backteting");
|
|
||||||
IsRemoteReadyForTesting = true;
|
|
||||||
sendBooleanResponse(ExpertHandle, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sendBooleanResponse(ExpertHandle, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 67: //IsTesting
|
|
||||||
{
|
|
||||||
sendBooleanResponse(ExpertHandle, IsTesting());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 68: //Print
|
|
||||||
{
|
|
||||||
string printMsg;
|
|
||||||
StringInit(printMsg, 1000, 0);
|
|
||||||
|
|
||||||
getStringValue(ExpertHandle, 0, printMsg);
|
|
||||||
|
|
||||||
Print(printMsg);
|
|
||||||
sendBooleanResponse(ExpertHandle, true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Print("Unknown command type = ", commandType);
|
Print("Unknown command type = ", commandType);
|
||||||
sendVoidResponse(ExpertHandle);
|
sendVoidResponse(ExpertHandle);
|
||||||
|
|||||||
Reference in New Issue
Block a user