Skip to content

Commit 3a05fc3

Browse files
committed
Issue vdemydiuk#226: Implemented two modes of lock ticks: LOCK_EVERY_TICK and LOCK_EVERY_CANDLE. Added event OnLockTicks
1 parent acd8514 commit 3a05fc3

File tree

11 files changed

+57
-11
lines changed

11 files changed

+57
-11
lines changed

MtApi/ChartEventArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using MtApi.Events;
23

34
namespace MtApi
45
{

MtApi/MtChartEvent.cs renamed to MtApi/Events/MtChartEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MtApi
1+
namespace MtApi.Events
22
{
33
internal class MtChartEvent
44
{

MtApi/Events/MtEventTypes.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MtApi.Events
2+
{
3+
public enum MtEventTypes
4+
{
5+
LastTimeBar = 1,
6+
ChartEvent = 2,
7+
OnLockTicks = 3
8+
}
9+
}

MtApi/Events/OnLockTicksEvent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MtApi.Events
2+
{
3+
internal class OnLockTicksEvent
4+
{
5+
public string Instrument { get; set; }
6+
}
7+
}

MtApi/MtApi.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="EnumSymbolInfoInteger.cs" />
7575
<Compile Include="EnumTerminalInfoDouble.cs" />
7676
<Compile Include="EnumTerminalInfoInteger.cs" />
77+
<Compile Include="Events\OnLockTicksEvent.cs" />
7778
<Compile Include="FlagFontStyle.cs" />
7879
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
7980
<Compile Include="Monitors\OrderModification\ModifiedOrdersEventArgs.cs" />
@@ -86,14 +87,15 @@
8687
<Compile Include="Monitors\Triggers\TimeElapsedTrigger.cs" />
8788
<Compile Include="MqlRates.cs" />
8889
<Compile Include="MqlTick.cs" />
89-
<Compile Include="MtChartEvent.cs" />
90+
<Compile Include="Events\MtChartEvent.cs" />
9091
<Compile Include="MtConnectionEventArgs.cs" />
9192
<Compile Include="MtConnectionException.cs" />
9293
<Compile Include="MtConnectionState.cs" />
9394
<Compile Include="MtCommandType.cs" />
9495
<Compile Include="MtErrorCode.cs" />
95-
<Compile Include="MtEventTypes.cs" />
96+
<Compile Include="Events\MtEventTypes.cs" />
9697
<Compile Include="MtExecutionException.cs" />
98+
<Compile Include="MtLockTicksEventArgs.cs" />
9799
<Compile Include="MtOrder.cs" />
98100
<Compile Include="MtQuote.cs" />
99101
<Compile Include="MtQuoteEventArgs.cs" />

MtApi/MtApiClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using MtApi.Responses;
1010
using Newtonsoft.Json;
1111
using System.Threading.Tasks;
12+
using MtApi.Events;
1213

1314
namespace MtApi
1415
{
@@ -3140,6 +3141,9 @@ private void _client_MtEventReceived(MtEvent e)
31403141
case MtEventTypes.ChartEvent:
31413142
FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject<MtChartEvent>(e.Payload));
31423143
break;
3144+
case MtEventTypes.OnLockTicks:
3145+
FireOnLockTicks(e.ExpertHandle, JsonConvert.DeserializeObject<OnLockTicksEvent>(e.Payload));
3146+
break;
31433147
default:
31443148
throw new ArgumentOutOfRangeException();
31453149
}
@@ -3155,6 +3159,11 @@ private void FireOnChartEvent(int expertHandler, MtChartEvent chartEvent)
31553159
OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent));
31563160
}
31573161

3162+
private void FireOnLockTicks(int expertHandler, OnLockTicksEvent lockTicksEvent)
3163+
{
3164+
OnLockTicks?.Invoke(this, new MtLockTicksEventArgs(expertHandler, lockTicksEvent.Instrument));
3165+
}
3166+
31583167
private void BacktestingReady()
31593168
{
31603169
SendCommand<object>(MtCommandType.BacktestingReady, null);
@@ -3171,6 +3180,7 @@ private void BacktestingReady()
31713180
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
31723181
public event EventHandler<TimeBarArgs> OnLastTimeBar;
31733182
public event EventHandler<ChartEventArgs> OnChartEvent;
3183+
public event EventHandler<MtLockTicksEventArgs> OnLockTicks;
31743184

31753185
#endregion
31763186
}

MtApi/MtEventTypes.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

MtApi/MtLockTicksEventArgs.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace MtApi
4+
{
5+
public class MtLockTicksEventArgs : EventArgs
6+
{
7+
internal MtLockTicksEventArgs(int expertHandle, string symbol)
8+
{
9+
ExpertHandle = expertHandle;
10+
Symbol = symbol;
11+
}
12+
13+
public int ExpertHandle { get; }
14+
public string Symbol { get; }
15+
}
16+
}

TestClients/TestApiClientUI/Form1.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public Form1()
4444
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
4545
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
4646
_apiClient.OnChartEvent += _apiClient_OnChartEvent;
47+
_apiClient.OnLockTicks += _apiClient_OnLockTicks;
4748

4849
InitOrderCommandsGroup();
4950

@@ -149,6 +150,14 @@ private void _apiClient_OnChartEvent(object sender, ChartEventArgs e)
149150
PrintLog(msg);
150151
}
151152

153+
private void _apiClient_OnLockTicks(object sender, MtLockTicksEventArgs e)
154+
{
155+
var msg =
156+
$"OnLockTicks: ExpertHandle = {e.ExpertHandle}, Symbol = {e.Symbol}";
157+
Console.WriteLine(msg);
158+
PrintLog(msg);
159+
}
160+
152161
private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
153162
{
154163
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask);

mq4/MtApi.ex4

3.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)