mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-13 18:58:09 +00:00
Issue #59: Added event OnChartEvent into MtApi (MT4)
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public class ChartEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
internal ChartEventArgs(int expertHandle, MtChartEvent chartEvent)
|
||||||
|
{
|
||||||
|
ExpertHandle = expertHandle;
|
||||||
|
ChartId = chartEvent.ChartId;
|
||||||
|
EventId = chartEvent.EventId;
|
||||||
|
Lparam = chartEvent.Lparam;
|
||||||
|
Dparam = chartEvent.Dparam;
|
||||||
|
Sparam = chartEvent.Sparam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExpertHandle { get; }
|
||||||
|
public long ChartId { get; }
|
||||||
|
public int EventId { get; }
|
||||||
|
public long Lparam { get; }
|
||||||
|
public double Dparam { get; }
|
||||||
|
public string Sparam { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumChartEvent
|
||||||
|
{
|
||||||
|
CHARTEVENT_KEYDOWN = 0,
|
||||||
|
CHARTEVENT_MOUSE_MOVE = 10,
|
||||||
|
CHARTEVENT_OBJECT_CREATE = 7,
|
||||||
|
CHARTEVENT_OBJECT_CHANGE = 8,
|
||||||
|
CHARTEVENT_OBJECT_DELETE = 6,
|
||||||
|
CHARTEVENT_CLICK = 4,
|
||||||
|
CHARTEVENT_OBJECT_CLICK = 1,
|
||||||
|
CHARTEVENT_OBJECT_DRAG = 2,
|
||||||
|
CHARTEVENT_OBJECT_ENDEDIT = 3,
|
||||||
|
CHARTEVENT_CHART_CHANGE = 9,
|
||||||
|
CHARTEVENT_CUSTOM = 1000,
|
||||||
|
CHARTEVENT_CUSTOM_LAST = 66534
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ChartEventArgs.cs" />
|
||||||
<Compile Include="ChartPeriod.cs" />
|
<Compile Include="ChartPeriod.cs" />
|
||||||
<Compile Include="EnumAlignMode.cs" />
|
<Compile Include="EnumAlignMode.cs" />
|
||||||
<Compile Include="EnumChartPropertyDouble.cs" />
|
<Compile Include="EnumChartPropertyDouble.cs" />
|
||||||
@@ -77,6 +78,7 @@
|
|||||||
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
||||||
<Compile Include="MqlRates.cs" />
|
<Compile Include="MqlRates.cs" />
|
||||||
<Compile Include="MqlTick.cs" />
|
<Compile Include="MqlTick.cs" />
|
||||||
|
<Compile Include="MtChartEvent.cs" />
|
||||||
<Compile Include="MtConnectionEventArgs.cs" />
|
<Compile Include="MtConnectionEventArgs.cs" />
|
||||||
<Compile Include="MtConnectionException.cs" />
|
<Compile Include="MtConnectionException.cs" />
|
||||||
<Compile Include="MtConnectionState.cs" />
|
<Compile Include="MtConnectionState.cs" />
|
||||||
|
|||||||
+12
-5
@@ -3068,18 +3068,24 @@ namespace MtApi
|
|||||||
switch(eventType)
|
switch(eventType)
|
||||||
{
|
{
|
||||||
case MtEventTypes.LastTimeBar:
|
case MtEventTypes.LastTimeBar:
|
||||||
{
|
FireOnLastTimeBar(e.ExpertHandle, JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
||||||
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
break;
|
||||||
}
|
case MtEventTypes.ChartEvent:
|
||||||
|
FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject<MtChartEvent>(e.Payload));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FireOnLastTimeBar(MtTimeBar timeBar)
|
private void FireOnLastTimeBar(int expertHandler, MtTimeBar timeBar)
|
||||||
{
|
{
|
||||||
OnLastTimeBar?.Invoke(this, new TimeBarArgs(timeBar));
|
OnLastTimeBar?.Invoke(this, new TimeBarArgs(expertHandler, timeBar));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireOnChartEvent(int expertHandler, MtChartEvent chartEvent)
|
||||||
|
{
|
||||||
|
OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BacktestingReady()
|
private void BacktestingReady()
|
||||||
@@ -3097,6 +3103,7 @@ namespace MtApi
|
|||||||
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;
|
||||||
|
public event EventHandler<ChartEventArgs> OnChartEvent;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
internal class MtChartEvent
|
||||||
|
{
|
||||||
|
public long ChartId { get; set; }
|
||||||
|
public int EventId { get; set; }
|
||||||
|
public long Lparam { get; set; }
|
||||||
|
public double Dparam { get; set; }
|
||||||
|
public string Sparam { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
public enum MtEventTypes
|
public enum MtEventTypes
|
||||||
{
|
{
|
||||||
LastTimeBar = 1
|
LastTimeBar = 1,
|
||||||
|
ChartEvent = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -11,16 +11,7 @@ namespace MtApi
|
|||||||
public double Close { get; set; }
|
public double Close { get; set; }
|
||||||
public double High { get; set; }
|
public double High { get; set; }
|
||||||
public double Low { get; set; }
|
public double Low { get; set; }
|
||||||
|
public DateTime OpenTime => MtApiTimeConverter.ConvertFromMtTime(MtOpenTime);
|
||||||
public DateTime OpenTime
|
public DateTime CloseTime => MtApiTimeConverter.ConvertFromMtTime(MtCloseTime);
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtOpenTime); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public DateTime CloseTime
|
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.37.0")]
|
[assembly: AssemblyVersion("1.0.38.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.37.0")]
|
[assembly: AssemblyFileVersion("1.0.38.0")]
|
||||||
@@ -4,11 +4,18 @@ namespace MtApi
|
|||||||
{
|
{
|
||||||
public class TimeBarArgs: EventArgs
|
public class TimeBarArgs: EventArgs
|
||||||
{
|
{
|
||||||
|
internal TimeBarArgs(int expertHandle, MtTimeBar timeBar)
|
||||||
|
: this(timeBar)
|
||||||
|
{
|
||||||
|
ExpertHandle = expertHandle;
|
||||||
|
}
|
||||||
|
|
||||||
public TimeBarArgs(MtTimeBar timeBar)
|
public TimeBarArgs(MtTimeBar timeBar)
|
||||||
{
|
{
|
||||||
TimeBar = timeBar;
|
TimeBar = timeBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtTimeBar TimeBar { get; private set; }
|
public int ExpertHandle { get; }
|
||||||
|
public MtTimeBar TimeBar { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ namespace TestApiClientUI
|
|||||||
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
|
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
|
||||||
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
|
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
|
||||||
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
||||||
|
_apiClient.OnChartEvent += _apiClient_OnChartEvent;
|
||||||
|
|
||||||
InitOrderCommandsGroup();
|
InitOrderCommandsGroup();
|
||||||
|
|
||||||
@@ -134,7 +135,15 @@ namespace TestApiClientUI
|
|||||||
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
||||||
{
|
{
|
||||||
var msg =
|
var msg =
|
||||||
$"TimeBar: Symbol = {e.TimeBar.Symbol}, OpenTime = {e.TimeBar.OpenTime}, CloseTime = {e.TimeBar.CloseTime}, Open = {e.TimeBar.Open}, Close = {e.TimeBar.Close}, High = {e.TimeBar.High}, Low = {e.TimeBar.Low}";
|
$"TimeBar: ExpertHandle = {e.ExpertHandle}, Symbol = {e.TimeBar.Symbol}, OpenTime = {e.TimeBar.OpenTime}, CloseTime = {e.TimeBar.CloseTime}, Open = {e.TimeBar.Open}, Close = {e.TimeBar.Close}, High = {e.TimeBar.High}, Low = {e.TimeBar.Low}";
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
PrintLog(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _apiClient_OnChartEvent(object sender, ChartEventArgs e)
|
||||||
|
{
|
||||||
|
var msg =
|
||||||
|
$"OnChartEvent: ExpertHandle = {e.ExpertHandle}, ChartId = {e.ChartId}, EventId = {e.EventId}, Lparam = {e.Lparam}, Dparam = {e.Dparam}, Sparam = {e.Sparam}";
|
||||||
Console.WriteLine(msg);
|
Console.WriteLine(msg);
|
||||||
PrintLog(msg);
|
PrintLog(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user