Issue #226: Implemented two modes of lock ticks: LOCK_EVERY_TICK and LOCK_EVERY_CANDLE. Added event OnLockTicks

This commit is contained in:
Viacheslav Demydiuk
2020-11-29 19:30:21 +02:00
parent acd8514c38
commit 3a05fc3353
11 changed files with 57 additions and 11 deletions
+1
View File
@@ -1,4 +1,5 @@
using System;
using MtApi.Events;
namespace MtApi
{
@@ -1,4 +1,4 @@
namespace MtApi
namespace MtApi.Events
{
internal class MtChartEvent
{
+9
View File
@@ -0,0 +1,9 @@
namespace MtApi.Events
{
public enum MtEventTypes
{
LastTimeBar = 1,
ChartEvent = 2,
OnLockTicks = 3
}
}
+7
View File
@@ -0,0 +1,7 @@
namespace MtApi.Events
{
internal class OnLockTicksEvent
{
public string Instrument { get; set; }
}
}
+4 -2
View File
@@ -74,6 +74,7 @@
<Compile Include="EnumSymbolInfoInteger.cs" />
<Compile Include="EnumTerminalInfoDouble.cs" />
<Compile Include="EnumTerminalInfoInteger.cs" />
<Compile Include="Events\OnLockTicksEvent.cs" />
<Compile Include="FlagFontStyle.cs" />
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
<Compile Include="Monitors\OrderModification\ModifiedOrdersEventArgs.cs" />
@@ -86,14 +87,15 @@
<Compile Include="Monitors\Triggers\TimeElapsedTrigger.cs" />
<Compile Include="MqlRates.cs" />
<Compile Include="MqlTick.cs" />
<Compile Include="MtChartEvent.cs" />
<Compile Include="Events\MtChartEvent.cs" />
<Compile Include="MtConnectionEventArgs.cs" />
<Compile Include="MtConnectionException.cs" />
<Compile Include="MtConnectionState.cs" />
<Compile Include="MtCommandType.cs" />
<Compile Include="MtErrorCode.cs" />
<Compile Include="MtEventTypes.cs" />
<Compile Include="Events\MtEventTypes.cs" />
<Compile Include="MtExecutionException.cs" />
<Compile Include="MtLockTicksEventArgs.cs" />
<Compile Include="MtOrder.cs" />
<Compile Include="MtQuote.cs" />
<Compile Include="MtQuoteEventArgs.cs" />
+10
View File
@@ -9,6 +9,7 @@ using MtApi.Requests;
using MtApi.Responses;
using Newtonsoft.Json;
using System.Threading.Tasks;
using MtApi.Events;
namespace MtApi
{
@@ -3140,6 +3141,9 @@ namespace MtApi
case MtEventTypes.ChartEvent:
FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject<MtChartEvent>(e.Payload));
break;
case MtEventTypes.OnLockTicks:
FireOnLockTicks(e.ExpertHandle, JsonConvert.DeserializeObject<OnLockTicksEvent>(e.Payload));
break;
default:
throw new ArgumentOutOfRangeException();
}
@@ -3155,6 +3159,11 @@ namespace MtApi
OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent));
}
private void FireOnLockTicks(int expertHandler, OnLockTicksEvent lockTicksEvent)
{
OnLockTicks?.Invoke(this, new MtLockTicksEventArgs(expertHandler, lockTicksEvent.Instrument));
}
private void BacktestingReady()
{
SendCommand<object>(MtCommandType.BacktestingReady, null);
@@ -3171,6 +3180,7 @@ namespace MtApi
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
public event EventHandler<TimeBarArgs> OnLastTimeBar;
public event EventHandler<ChartEventArgs> OnChartEvent;
public event EventHandler<MtLockTicksEventArgs> OnLockTicks;
#endregion
}
-8
View File
@@ -1,8 +0,0 @@
namespace MtApi
{
public enum MtEventTypes
{
LastTimeBar = 1,
ChartEvent = 2
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
namespace MtApi
{
public class MtLockTicksEventArgs : EventArgs
{
internal MtLockTicksEventArgs(int expertHandle, string symbol)
{
ExpertHandle = expertHandle;
Symbol = symbol;
}
public int ExpertHandle { get; }
public string Symbol { get; }
}
}
+9
View File
@@ -44,6 +44,7 @@ namespace TestApiClientUI
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
_apiClient.OnChartEvent += _apiClient_OnChartEvent;
_apiClient.OnLockTicks += _apiClient_OnLockTicks;
InitOrderCommandsGroup();
@@ -149,6 +150,14 @@ namespace TestApiClientUI
PrintLog(msg);
}
private void _apiClient_OnLockTicks(object sender, MtLockTicksEventArgs e)
{
var msg =
$"OnLockTicks: ExpertHandle = {e.ExpertHandle}, Symbol = {e.Symbol}";
Console.WriteLine(msg);
PrintLog(msg);
}
private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
{
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask);
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.